Recommended VPS Complete list of best VPS hosting providers.

How To Install New WordPress Blogging Script On A Nginx-based Ubuntu Server

This tutorial is a very basic guide to teach you how to install WordPress blogging script on your server running Nginx as the web server. Hence you can build your own self-hosted WordPress blog in a powerful, fast and responsive server even without having to install WHM/cPanel at first. It means you can also have a fast WordPress blog hosted in standalone server with your own dedicated IP (good for SEO) and won’t be interrupted by any other users like what you usually been faced in shared hosting environment.

p.s: When I say “server” it refers to both VPS or Dedicated one.

Prerequisite

  1. A server running either Ubuntu or Debian. In this example I use Ubuntu 12.04.
  2. You’ll need either Putty in Windows or Terminal in Mac and Linux to access your server via SSH connection.
  3. In this example I will use Putty. If you do so, make sure you know where to download it and how to use it. Read: Using Putty To SSH To Your Server From Windows.
  4. You have to also know all basic commands useful to SSH-ing your server. Read: Most common Unix command to manage unmanaged server.
  5. Make sure you have installed: Nginx, PHP, MySQL, and Postfix.
  6. Setup new virtual hosts file in Nginx as necessary step to add new website on your server.
  7. You may also setup Bind9 DNS software first or may be later after you add your website into your server.

How To Install WordPress

Step 1 – As usual, login to your server via SSH connection. If you didn’t change it yet, it should be in port 22 otherwise use your defined port. If you did follow my previous guide about all essential basic configuration for Ubuntu server, then you should login using your username instead of root. Once logged in, type su, hit Enter on your keyboard then type in your root password.

login ssh

Step 2 – Go to the directory where you will place all website’s files there. Usually it should be named as “htdocs” or “public_html”. In my case I use “htdocs” which is located at /var/www/domain.com/htdocs/. Use this command:

cd /var/www/domain.com/htdocs/

Remember:
– Replace “domain.com” with your own domain name;
– Replace “htdocs” with “public_htm” if you do prefer to use public_html.

go to htdocs

As in my previous tutorial I also created index.html test file, so we may also need to remove it first using “rm index.html” command as shown in screenshot pic above.

Step 3 – Next, downloading WordPress main script package. The command is simple:

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

wget wordpress

Step 4 – Alright, so you now have the WordPress package file. But first, you have to also extract it first. Use this command:

tar --strip-components=1 -xvf latest.tar.gz

Then remove that “latest.tar.gz” file you’ve already extracted, not quite necessary but it will save some space in your server:

rm latest.tar.gz

Once done, you can also test to see what files are inside your root public_html or htdocs folder by using “ls” command:

wordpress files

Step 5 – Next, as WordPress needs MySQL database, then you should create one along with new MySQL user having all privileges granted to that database. Read: Top most common MySQL basic commands. Or shortly, here I re-mention the necessary command as below:

Login to main MySQL screen at first. In this case I use root:

mysql -u root -p

Type in the password.

mysql screen

Once you are in MySQL screen, here you can create new database for your blog. Use this command:

CREATE DATABASE databasename;

**change databasename with your own database name. You better not use space in the name. In this example I use “myblog”:

create database

If you wish to use space you can use underscore e.g: wp_456.

So you have created new database. Next, you have to create new MySQL username and grant full access to that new database. This is considered safer than using your root login. Use this command:

GRANT ALL ON databasename.* TO sqluser@localhost IDENTIFIED BY 'password';

**change databasename, sqluser and password with your own. For example:

GRANT ALL ON myblog.* TO sawiyatidb@localhost IDENTIFIED BY 'pass1234';

In that example I create “sawiyatidb” as my user for database named “myblog” while pass1234 is the password for user sawiyatidb.

create new mysql user

That’s it. You must remember: database name, database username and its password. Once done, exit MySQL screen by typing “\q“.

Step 6 – Edit Nginx virtual hosts file. I explained how to do that in my previous tutorial here. You can use this standard Nginx-config file with no setting for any caching plugin but this one is already compatible with WordPress pretty / SEO-friendly permalink:

server {
        server_name domain.com www.domain.com;

	access_log   /var/log/nginx/domain.com.access.log;
	error_log    /var/log/nginx/domain.com.error.log;

        root /var/www/domain.com/htdocs;
        index index.php;

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

        location ~ \.php$ {
                include fastcgi_params;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
        }
}

Remember to change “domain.com” with your own and also replace “htdocs” with “public_html” if you really prefer to use it. You can use this command below to edit virtual hosts file for your domain then add above entries to the file:

nano /etc/nginx/sites-available/domain.com

Here’s the example;

edit virtual hosts file wp

Also run this command only if you didn’t do it yet / or never did it yet:

ln -s /etc/nginx/sites-available/domain.com /etc/nginx/sites-enabled/

Step 7 – Next, run these two commands to test Nginx config file then restart Nginx service on your server:

nginx -t

test nginx config

service nginx restart

nginx restart

Step 8 – Finally, lets proceed the WordPress installation wizard. Open your favorite web browser (I use Firefox) then visit your blog’s url / domain name. You should now see default WordPress installation wizard. First thing, you’ll be asked to create configuration file or wp-config.php

install wp 1

Next,.. just click the “Let’s Go” button.

install wordpress

So next,.. here it is the part where you have to provide Database Name, MySQL Username, its password, while you can leave Database Host and Table prefix as it is.

install wordpress

Click on the Submit button. You’ll then see an error saying that the wizard can’t write the wp-config.php file. Don’t worry that’s not a big problem.

copy file

Now go back to your server and create one by typing this command but make sure you are in “htdocs” or “public_html” folder already:

nano wp-config.php

Then copy paste the code supplied in the wizard to the wp-config.php file you are editing in Nano editor.

edit wp-config

copy the config script

then paste it to Nano editor. In putty all you have to do is just a right-click.

edit wp-config

Once done, hit Control+O to save then Control+X to exit. Then go back to your web browser to continue the installation..

click the button

Finally hit the “Run the Install” button. In the next section you have to define admin username and its password to login to your blog. I’m sure you are already understand exactly what is it.

install wordpress

Finally,.. hit the “Install WordPress” button.

install wordpress

That’s it. Now you can login to your new blog and congratulation..

install wordpress final

Have a question? Have you done it successfully? Come on share your experience with me..

One Comment

Add a Comment

Your email address will not be published. Required fields are marked *

Get more stuff like this
in your inbox

Subscribe and get interesting stuff plus faster updates to your email.