How To Install New WordPress On A Nginx-based CentOS Server

Sunday, July 17th 2016. | how to

#howto ,#tutorial #VPS – How To Install New WordPress On A Nginx-based CentOS Server – This tutorial explains step by step guide (with pics) about How To Install New WordPress On A Nginx-based CentOS Server

Being an easy-to-use blogging platform, WordPress has been used by lot of bloggers in the world. It is supported by numerous amount of themes and plugins so users can have a blog with not just good-looking theme but also various advanced functionality via plugins. Google loves speed while WordPress is the perfect platform to deliver lightweight websites by using fast-loading theme (there are plenty of it) and caching plugins like WP Super Cache and W3 Total Cache. Yet, in many cases that was not enough to serve thousands online users in the same time. Good caching plugin and very lightweight theme have been used and various tweaks like minifying scripts have been implemented but the server still goes down? The answer is simple, ditch Apache and start using Nginx.

In this page I’ll show you how to install WordPress on Nginx server (CentOS). The setup here is very basic which means only WordPress with no plugin that alters Apache’s .htaccess. I will in the next time write about WordPress + WP Super Cache / W3 Total Cache.

Prerequisite

  1. A server running CentOS. In this example I use CentOS 6.3 x32 (see my playground server).
  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 need to edit DNS record of your domain name so it can resolve to your server. This is optional because you can also do this later.

Step 1 – Login to your server and follow my previous guide about Basic setup for CentOS before you build a live web server. You may and may not follow that tutorial but if you followed, it will give you some basic security tweak to your server.

Before you proceed to the next steps, it is better to explain that all commands in this tutorial are written without the “sudo” prefix. However if you disabled root login and you logged in using another username with root privilege, you can add the “sudo” prefix all by your self. Alternatively you can simply type su, hit Enter and type in your password twice to switch login as root.

switch-root-login

You may also need to type this command to go to the root directory:

cd ~

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 “public_html” which is located at /var/www/domain.com/public_html/. Use this command:

cd /var/www/domain.com/public_html/

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.

change directory

Step 3 – Now download WordPress package to that directory. Use wget to do that:

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

wait for it to download WordPress which should happen in no time:

download 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:

all files

Step 5 – Next, create new MySQL database to hold WordPress data. Now login to MySQL server using your root account:

First, also read:

  • Basic Guide: Install MySQL Server On CentOS
  • Top Most Common Basic MySQL Commands

login mysql

Now create new database using this command:

CREATE DATABASE dbname;

For this example I use “fikitipsdata”

create database

Step 6 – Create new MySQL user and assign all privileges to that user for the newly created database. 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 PRIVILEGES ON fikitipsdb.* TO sawiyati@localhost IDENTIFIED BY 'pass1234';

That’s it. You must remember: database name, database username and its password. You may also need to flush privileges so the new setting will apply.

FLUSH PRIVILEGES;

Once done, you can now exit MySQL screen by typing “q“.

flush privileges

Step 7 – Now you have to edit WordPress config file that holds configuration to MySQL account. First of all, make a copy of the sample config:

cp wp-config-sample.php wp-config.php

So you are now having wp-config.php which will then you can edit it.

wp config

Step 8 – Now you can use either Nano or vi to edit it. For me, Nano is the most easiest one:

nano wp-config.php

Now find the section that says MySQL Settings:

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

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

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

/** MySQL hostname */
define('DB_HOST', 'localhost');

Now replace: database_name_here, username_here and password_here. Leave DB_HOST as localhost.

mysql setting

Once done, hit Control+O to save then Control+X to exit Nano editor.

Step 9 – Setup and configure Nginx virtual hosts file (server blocks) for your new website. I’ve posted about how to add new site on Nginx-based CentOS server here. Here’s I tell you again but I strongly recommend you to read my previous tutorial. Issue this command syntax:

nano /etc/nginx/conf.d/virtual.conf

The previous entries in virtual.conf file are below (created following my previous tutorial):

virtual configuration nginx

then change it to look like this one:

nginx virtual.conf setting for wordpress

or here it is the full records – replace “domain.com” with yours:

server {
    listen       80;
#   listen       *:80;
    server_name  domain.com www.domain.com;

    location / {
        root   /var/www/domain.com/public_html/;
         index  index.php index.html index.htm;
    }

    location ~ .php$ {
        root           /var/www/domain.com/public_html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

Once done, hit Control+O to save then Control+X to exit.

Step 10 – Now launch your favorite web browser and open your website. If everything is set correctly as described above then you should be able to see WordPress install wizard:

wordpress install wizard

Step 11 – That’s it. Now you can proceed installing WordPress as usual. Enter all needed information including: Site Title, Username and Password used to login to WP Admin dashboard, and of course enter your email.

needed info

Once done, hit that “Install” button.

install wordpress

That’s it. Now you can login to you blog via:http://domain.com/wp-admin

Note about Server Block config:

The server block used in this tutorial (step 9 above) allowing you to have WordPress pretty permalink (SEO friendly URL). If you see inside your WordPress admin, it looks like this:

wordpress permalink nginx

You can simply select “Custom Structure” then remove the index.php part and save it. It will then ask you to update .htaccess file but don;t worry you can simply ignore it.

nginx permalink for wordpress

But however the server block config has no lines that rule caching plugins like W3 Total Cache and WP Super Cache.

How to make your WordPress site accessible with “www” prefix?
Login to your WordPress Admin Dashboard and go to Settings >> General. Now add “www” in the WordPress Address (URL) and Site Address URL:

www url

Have a question? Have you done it successfully? Come on share your experience with me. Do not hesitate to drop a comment below. Follow me on Twitter for quick update.

This post How To Install New WordPress On A Nginx-based CentOS Server is part of ServerMom.

Source link