Check this Out!Visit our social network pages for recent updates!

Lesson 35: Installing WordPress with Nginx Support on Ubuntu

Students lesson 35 assignment: How do you install WordPress with Nginx webserver support?

By now you probably already know WordPress is the most popular Content Management System (CMS) in used today. It’s more popular because of its vast plugins, themes and support base

The community support behind WordPress is stronger than any other CMS out there. Anyone can get a blog or website powered by WordPress running easily because WordPress was designed to be very easy to install and use.

When you combine WordPress and Nginx webserver, you’d get a more efficient and powerful website. Nginx webserver is known for its performance capabilities as compared to other webservers.

This brief tutorial shows you how to run a WordPress blog or website powered by Nginx webserver.

Step 1: Prerequisites

Before you can run a website powered by WordPress, you must first prepare your Linux or Windows environment. You need to install components and programs necessary for WordPress to function.

Since WordPress is primarily hosted on a Linux servers, we’re going to be using Ubuntu server here.

The first thing you’ll want to do is to install the LEMP Stack. The post below shows you how.

Lesson 36: Installing the LEMP Stack on Ubuntu

After installing the LEMP, continue below to complete WordPress installation.

Step 2: Create MySQL database and User for WordPress

When you’re done with LEMP, go and create WordPress database and user. To do that, logon to MySQL server by running the commands below.

mysql -u root -p

When prompted for a password, enter the password created in our previous post on installing LEMP.

Next, run MySQL command below to create a new WordPress database called wpdb

CREATE DATABASE wpdb;

The above commands creates a database for WordPress to use. The next step is to create a user to manage the database. This user will be given full rights to manage data from the database.

Run the commands below to create a database user named wpuser and a password. (replace password with a new password)

CREATE USER wpuser@localhost IDENTIFIED BY 'password';

After creating the database and user, your next step is to grant the user full access the to database. To do that, run the commands below.

GRANT ALL PRIVILEGES ON wpdb.* TO wpuser@localhost;

Everything should be done. Finally, flush the changes to disk so that the server apples the changes we made.

FLUSH PRIVILEGES;

Exit MySQL

exit

Step 3: Download and configure WordPress files

Now that the database is setup, your next task will be to download WordPress files onto your server. To do that, run the commands below.

cd /tmp/ && wget http://wordpress.org/latest.tar.gz

Then, run the commands below to extract the downloaded files

tar -xvzf latest.tar.gz

After extracting the files, your next step will be to copy or move the downloaded files to Nginx’s root directory. Before you copy the files there, remove Nginx existing test html file from the root directory.

sudo rm /var/www/html/index.*html

Now, move WordPress content to Nginx root directory.

sudo mv wordpress/* /var/www/html/

After that, create WordPress configuration file named wp-config.php by making a copy of wp-config-sample.php file.

sudo cp /var/www/html/wp-config-sample.php /var/www/html/wp-config.php

After that, open WordPress configuration page and enter the database connection info. To do that, run the commands below.

sudo nano /var/www/html/wp-config.php

Make the necessary database connection changes and save the file.

. . .
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wpdb');

/** MySQL database username */
define('DB_USER', 'wpuser');

/** MySQL database password_here */
define('DB_PASSWORD', 'password');
. . .

Save the file and close out.

Next, change WordPress file permissions so that it functions properly.

sudo chown -R www-data:www-data /var/www/html/
sudo chmod -R 755 /var/www/html/

Step 4: Configure Nginx configuration

Now that WordPress is configured, go and configure Nginx. What we need to do is copy Nginx default site configuration file to create a new one for WordPress.

sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/wordpress

Open the file by running the commands below

sudo nano /etc/nginx/sites-available/wordpress

Then make the following changes highlighted below

 

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /var/www/html;
        index index.php index.html index.htm;

        server_name _;

        location / {
                # try_files $uri $uri/ =404;
                try_files $uri $uri/ /index.php?q=$uri&$args;
        }

        error_page 404 /404.html;

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
                root /usr/share/nginx/html;
        }

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
        }
}

Next, run the command below to enable the newly created site.

sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/

Now that the site is enabled, go and delete the original (default) site, since we don’t want two sites with the same configurations.

sudo rm /etc/nginx/sites-enabled/default

Restart Nginx by running the commands below

sudo systemctl restart nginx

Now your server is configured. All you need to do is browse to the server name or IP address to complete WordPress configuration.

http://localhost  or http://your_domain

You should see WordPress default setup page.

WordPress default setup page

Enter your WordPress site info and click Install.

wordpress welcome page

Enjoy!

You may also like this post:

How To Install WordPress On Ubuntu Servers