DEV Community

Partha Biswas
Partha Biswas

Posted on

Installing Wordpress with Nginx in Ubuntu

To install WordPress with Nginx on Ubuntu, follow these steps:
1. Update your system

sudo apt update
Enter fullscreen mode Exit fullscreen mode

2. Install required module

sudo apt install php-fpm php-mysql mysql-server nginx unzip
Enter fullscreen mode Exit fullscreen mode

3. Setup mySql (Optional)
You can skip this if already done

4. Configuring Nginx to work with PHP

Goto nginx directory

cd /etc/nginx/sites-available
Enter fullscreen mode Exit fullscreen mode

Delete default (Optional)

sudo rm default
Enter fullscreen mode Exit fullscreen mode

Create Server Blocks for this Domain

sudo nano /etc/nginx/sites-available/domain1.com
Enter fullscreen mode Exit fullscreen mode

Identify php sock version by following command

ls /var/run/php
Enter fullscreen mode Exit fullscreen mode

Add the following content (adjust paths and domain names as needed and php sock version from above):

server {
    listen 80;
    server_name domain1.com www.domain1.com;

    root /var/www/html/domain1.com;
    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/php7.4-fpm.sock;  # Adjust PHP version if necessary
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }
}
Enter fullscreen mode Exit fullscreen mode

Create symbolic links in the site-enabled directory

sudo ln -s /etc/nginx/sites-available/domain1.com /etc/nginx/sites-enabled/
Enter fullscreen mode Exit fullscreen mode

Test Nginx Configuration. Make sure the Nginx configuration is correct:

sudo nginx -t
Enter fullscreen mode Exit fullscreen mode

Restart Nginx

sudo systemctl restart nginx
Enter fullscreen mode Exit fullscreen mode

5. Configuring Wordpress
Downloading Wordpress to the Ubuntu server

cd /var/www/html/domain1.com
sudo wget https://wordpress.org/latest.zip
Enter fullscreen mode Exit fullscreen mode

Extract the file to domain1.com

sudo unzip latest.zip
sudo mv wordpress/* .
Enter fullscreen mode Exit fullscreen mode

Remove unwanted files and folders

sudo rm latest.zip
sudo rm -R wordpress
Enter fullscreen mode Exit fullscreen mode

Changing the owner of the Wordpress files

sudo chown -R www-data:www-data *
Enter fullscreen mode Exit fullscreen mode

6. Databse details configure
Open domain1.com and fill all the details.
From next page copy it's contains and create new file with this in /var/www/html/domain1.com folder

sudo nano wp-config.php
Enter fullscreen mode Exit fullscreen mode

Now complete remaining setup vi domain1.com url

Top comments (0)