DEV Community

Partha Biswas
Partha Biswas

Posted on • Edited 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 php-xml
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;

    ssl_certificate  /etc/ssl/domain1.com.pem;
    ssl_certificate_key  /etc/ssl/domain1.com.key;

    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

Image of AssemblyAI

Automatic Speech Recognition with AssemblyAI

Experience near-human accuracy, low-latency performance, and advanced Speech AI capabilities with AssemblyAI's Speech-to-Text API. Sign up today and get $50 in API credit. No credit card required.

Try the API

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay