Web server adalah komputer yang terhubung ke internet dan memiliki beberapa jenis perangkat lunak khusus untuk server web yang diinstal di dalamnya.
Jenis perangkat lunak web server yang paling umum adalah yang dapat melayani halaman web statis dan dinamis ke browser di seluruh dunia. Misalnya, Apache dan Nginx keduanya adalah server HTTP yang dapat melayani halaman web.
Prerequisites
A server running Debian 12.
A non-root user with sudo privileges.
A fully qualified domain name (FQDN) like example.com pointing to the server.
The Uncomplicated Firewall(UFW) is enabled and running.
Everything is updated.
Few packages that your system needs.
Some of these packages may already be installed on your system.
Step 1 - Configure Firewall
The first step before installing any packages is to configure the firewall to allow HTTP and HTTPS connections.
Check the status of the firewall.
You should see something like the following.
Allow HTTP and HTTPs ports.
Check the status again to confirm.
Output:
Step 2 - Install Web Engine
Install Nginx
Debian 12 ships with an older version of Nginx. To install the latest version, you need to download the official Nginx repository.
Import Nginx’s signing key.
Add the repository for Nginx’s stable version.
Update the system repositories.
Install Nginx.
Verify the installation. On Debian systems, the following command will only work with sudo.
Output:
Start Nginx.
Check the service status.
Output:
Install Apache
Check the service status.
Output
Step 3 - Install PHP
Debian 12/ Ubuntu 22.04 ships with PHP 8.3 by default. You can install it by running the following command.
Install Multi PHP
Install PHP 7.4
Install PHP 7.4 Extension
Install PHP 8.3
Install PHP 8.3 Extension
Change PHP version to php7.4
Change PHP version to php8.3
Check the version of PHP installed
check php version
Output:
Step 4 - Install MariaDB
Debian 12 does not ship with MySQL by default and they haven’t released an official package for it yet. Therefore, we will be using MariaDB for it. MariaDB doesn’t have an official package for Debian 12 as well but Debian ships with it. Therefore, install it using the following command.
Check the version of MySQL.
Run the MariaDB secure install script.
You will be asked for the root password. Press Enter because we haven’t set any password for it.
You can enter the MariaDB shell by typing sudo mysql or sudo mariadb on the command line.
Step 5 - Configure MariaDB
Log in to the MariaDB shell.
Create a sample database.
show database
Create a test table.
Insert test data.
Repeat the above command multiple times to add more entries. Run the following command to check the contents of the table.
You will receive the following output.
Exit the MySQL shell.
ADD USER MariaDB
Open your Terminal and type:
input your root password (press ENTER if you not configure it)
Then
Change 'user1' on 'user1'@localhost with your user name
Change 'password1' with your secure password
Change 'user1' on 'user1'@localhost with your user name
Change 'password1' with your secure password
Step 6 - Configure PHP-FPM
Open php.ini for editing.
To set file upload sizes, change the values of the upload_max_filesize and post_max_size variables.
Configure PHP’s memory limit depending on your server resources and requirements.
Save the file by pressing Ctrl + X and entering Y when prompted.
Opcache is PHP’s caching system. It works by saving precompiled script bytecode in the memory, so every time a user visits a page, it loads faster. Opcache is installed by default. To verify, check the PHP version.
This tells us that Opcache is installed and available. In case, it doesn’t show up here, you can install it manually by running the following command.
To change Opcache settings, open the file /etc/php/8.2/fpm/conf.d/10-opcache.ini for editing.
The following settings should get you started with using Opcache and are generally recommended for good performance. You can enable it by adding the following lines at the bottom.
Save the file by pressing Ctrl + X and entering Y when prompted.
Restart PHP-FPM.
Step 10 - Install Certbot for SSL
We need to install Certbot to generate free SSL certificates offered by Let’s Encrypt.
You can either install Certbot using Debian’s repository or grab the latest version using the Snapd tool. We will be using the Snapd version.
Debian 12 comes doesn’t come with Snapd installed. Install Snapd package.
Run the following commands to ensure that your version of Snapd is up to date.
Install Certbot.
Use the following command to ensure that the Certbot command can be run by creating a symbolic link to the /usr/bin directory.
Verify if Certbot is functioning properly.
Output:
Step 11 - Test a demo site
Create the site
Create and open a test page for editing.
Paste the following code in it.
Save the file by pressing Ctrl + X and entering Y when prompted.
Create an SSL Certificate
Run the following command to generate an SSL Certificate.
The above command will download a certificate to the /etc/letsencrypt/live/example.com directory on your server.
Generate a Diffie-Hellman group certificate.
Check the Certbot renewal scheduler service.
You will find snap.certbot.renew.service as one of the services scheduled to run.
Do a dry run of the process to check whether the SSL renewal is working fine.
If you see no errors, you are all set. Your certificate will renew automatically.
Configure Nginx
Create and open the file /etc/nginx/conf.d/example.conf for editing.
enforce HTTPS
Save the file by pressing Ctrl + X and entering Y when prompted.
Open the file /etc/nginx/nginx.conf for editing.
Add the following line before the line include /etc/nginx/conf.d/*.conf;.
Save the file by pressing Ctrl + X and entering Y when prompted.
Verify your Nginx configuration.
If you see no errors, it means you are good to go. Start the Nginx server.
Load your website by visiting https://example.com in your browser and you will see the following page.