Skip to main content

Web Server Configuration

Choose your web server from the tabs mentioned below:

Configuration Nginx

To configure Nginx to work with PHP-FPM, create a new Nginx configuration file for your domain using the following command:

sudo nano /etc/nginx/sites-available/your_domain.conf

After that, paste the following code to the file:

server {
listen 80;
server_name your_domain.tld www.yourdomain.tld;
root /var/www/your_domain/html;

index index.php index.html index.htm;

location / {
try_files $uri $uri/ =404;
}

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
}

location ~ /\.ht {
deny all;
}
}
tip

If you haven’t created the root directory for your domain, make sure to create and own it using the following commands:

mkdir /var/www/your_domain/html
chown -R www-data:www-data /var/www/your_domain

Now, let's enable your website configuration

sudo ln -s /etc/nginx/sites-available/your_domain.conf /etc/nginx/sites-enabled/

Then, let's verify the settings using the command:

sudo nginx -t

Now it's time to test & verify our Configuration file. If everything went on the track, the output will be something like:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Once the configuration is completed, don't forget to restart Nginx

sudo systemctl restart nginx