• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

How to Install WordPress with Nginx on Ubuntu 18.04

Written by Admin, Updated On August 24, 2019
cms, mariadb, mysql, nginx, ubuntu, wordpress
How to Install WordPress with Nginx on Ubuntu 18.04

WordPress is the most popular and widely used blogging and content management system in the world. PHP processing and MySQL database are used as a backend in WordPress. It is simplest way to create a Blog, Portfolio Website, webshop etc. In this tutorial, we will show you how to install WordPress with Nginx on Ubuntu 18.04 machine.

Prerequisites#

We are going to use LEMP (Linux, Nginx, MySQL, and PHP) stack with Nginx as web server. So ensure that you met the following prerequisites before start installation process:

  • Ubuntu server with a non-root user with sudo privileges.
  • Nginx must installed and configured, as shown in this tutorial.
  • Your domain name should pointing to your server IP address.
  • An SSL certificate installed for your domain. You can install a free Let’s Encrypt SSL certificate as shown in this tutorial.

Create MySQL database and Grant Permissions#

As we discussed previously WordPress is using MySQL database to store the data. So first of all we need to create a MySQL database, MySQL user and grant permission. If you system don’t have installed MySQL you can follow How to Install MySQL on Ubuntu 18.04 and if you want to install MariaDB then follow, How to Install MariaDB on Ubuntu 18.04 tutorials.

At first, log in to MySQL shell using below command:

mysql -u root -p

It will prompt you to enter password for the root user. You will be logged in on entering correct password.

Type the below command to create a new MySQL database for your WordPress:

CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;

Now you have to create a new MySQL user by issuing below command:

GRANT ALL ON wordpress.* TO 'wordpressuser'@'localhost' IDENTIFIED BY 'enter-strong-password';

Need to flush the database so changes can reflact in MySQL, type:

FLUSH PRIVILEGES;

Finally, exist from MySQL shell by typing:

EXIT;

Install PHP on Ubuntu#

PHP 7.2 is the latest stable and default PHP version in Ubuntu 18.04 system. You can also check the latest version for installation on PHP official website.

First of all you need to update the apt package manager index and upgrade the packages:

sudo apt update && sudo apt upgrade

Next, to install PHP and all the required modules run below command in the terminal:

sudo apt install php7.2-fpm php7.2-json php7.2-mysql php7.2-opcache  php7.2-mbstring php7.2-xml php7.2-cli php7.2-fpm php7.2-gd php7.2-curl

You can verify the installation by typing below command:

php -v

You should restart the Nginx service to take effect by issuing below command:

sudo systemctl restart nginx

Downloading and Setup WordPress#

First, navigate to /tmp directory using below command:

cd /tmp

Now download the latest WordPress setup from the WordPress download page using using below wget command:

wget https://wordpress.org/latest.tar.gz

Once the download is completed, extract the downloaded files using below command:

tar xzvf latest.tar.gz

After that, create the configuration file for WordPress using below command:

cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php

Then copy all the files to example.com directory using below command:

sudo cp -a /tmp/wordpress/. /var/www/example.com

You need to set the correct permissions so web server can the site’s files and directories. To change the ownership of example.com directory use following chown command:

sudo chown -R www-data:www-data /var/www/example.com

Configure Nginx#

You should have installed Nginx with SSL certificate installed on your Ubuntu machine. We will follow the Nginx recipe from the official Nginx site to create a new server block for our WordPress instance.

Open your text editor and create the following file:

# Redirect HTTP -> HTTPS
server {
    listen 80;
    server_name www.example.com example.com;

    include snippets/letsencrypt.conf;
    return 301 https://example.com$request_uri;
}

# Redirect WWW -> NON WWW
server {
    listen 443 ssl http2;
    server_name www.example.com;

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem;
    include snippets/ssl.conf;

    return 301 https://example.com$request_uri;
}

server {
    listen 443 ssl http2;
    server_name example.com;

    root /var/www/html/example.com;
    index index.php;

    # SSL parameters
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem;
    include snippets/ssl.conf;
    include snippets/letsencrypt.conf;

    # log files
    access_log /var/log/nginx/example.com.access.log;
    error_log /var/log/nginx/example.com.error.log;

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

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

    location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
        expires max;
        log_not_found off;
    }

}

Note : You should replace your real domain name with example.com and set correct SSL certificates path.

Next, you should Enable the server block by creating a symbolic link to the sites-enabled directory:

sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/

It’s recommended to check nginx syntax errors by typing:

sudo nginx -t

If there are no errors the output should look like this:

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

After that restart the nginx server :

sudo systemctl restart nginx

Complete the WordPress Installation#

Now WordPress is configuration is complete and we can finish remaining installation through web interface.

To do it open your browser and type your domain name and it should show page as following:

wordpress-language-selector

Select language which you would like to set and click on continue button to go ahead.

After that it will show below page you just have to click on Let’s Go! button to continue.

wordpress-install-information

On next page it will ask you to enter database connection details. Enter MySQL database and user details which you created previously.

wordpress-database-information

Next hit on the Run the installation button to start installation process.

wordpress-run-installation

On next screen, You should enter name of WordPress site and set username and password for your site. Also, enter your email address and select whether you want to discourage search engines from indexing the site (It’s not recommended).

wordpress-install-welcome

Finally, click on the Install WordPress button and once the installation is finished you will see the below screen:

wordress-install-completed

Hit on Login button you will be redirected to WordPress login page. Now use the username and password which you set in previous step.

wordpress-login

After successful login you will be redirected to the WordPress administration dashboard as following:

wordpress-dashboard

That’s it. You did and now you can customize your WordPress installation by installing new themes and plugins.

Conclusion#

You have successfully installed WordPress with Nginx on your Ubuntu 18.04 server.

If you have questions feel free to leave a comment below.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article How to Install and Use Nano Text Editor in Linux
Next Article   How to Install WordPress with Apache on Debian 10

Related Posts

  • How to Install WordPress with Nginx on Debian 11

    How to Install WordPress with Nginx on Debian 11

    March 22, 2023
  • How to Install Apache, MySQL, PHP (LAMP) on Ubuntu 22.04

    How to Install LAMP on Ubuntu 22.04

    March 20, 2023
  • How to Install LEMP Stack on Ubuntu 22.04

    How to Install LEMP Stack on Ubuntu 22.04

    March 18, 2023

Leave a Reply Cancel reply

DigitalOcean Referral Badge

Popular Posts

  • How to Install Microsoft Edge Browser on Ubuntu 22.04
    How to Install Microsoft Edge Browser on Ubuntu 22.04 March 14, 2023
  • How to Install Ruby on Ubuntu 22.04 LTS
    How to Install Ruby on Ubuntu 22.04 LTS February 27, 2023
  • How to Install LEMP Stack on Ubuntu 22.04
    How to Install LEMP Stack on Ubuntu 22.04 March 18, 2023
  • How to Install Set Up Apache Virtual Hosts on Ubuntu 22.04
    How to Set Up Apache Virtual Hosts on Ubuntu 22.04 March 2, 2023
  • How to Install MariaDB on Debian 11 Bullseye
    How to Install MariaDB on Debian 11 Bullseye March 8, 2023
© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook