Skip to content
WJunction - Webmaster Forum

How to Install Wordpress With Nginx On CentOS 6

Status
Not open for further replies.

Bharat

Active Member
2,003
2010
841
Installing Linux, nginx, MySQL, PHP (LEMP) stack

LEMP stack is a group of open source software to get web servers up and running. The acronym stands for Linux, nginx (pronounced Engine x), MySQL, and PHP. Since the server is already running CentOS, the linux part is taken care of. Here is how to install the rest.

Step One—Install the Required Repositories

We will be installing all of the required software with Yum. However, because neither nginx nor php-fpm are available straight from CentOS, we need to download two extra repositories to our virtual private server first.

Code:
sudo rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

MOXpnT9.png


Step Two—Install MySQL

The next step is to begin installing the server software on the virtual private server, starting with MySQL and dependancies.

Code:
sudo yum install mysql mysql-server
AR7l4Rp.png


Once the download is complete, restart MySQL:

Code:
sudo /etc/init.d/mysqld restart

Om6b8oZ.png


You can do some configuration of MySQL with this command:

Code:
sudo /usr/bin/mysql_secure_installation

The prompt will ask you for your current root password.

Since you just installed MySQL, you most likely won’t have one, so leave it blank by pressing enter.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Then the prompt will ask you if you want to set a root password. Go ahead and choose Y and follow the instructions.

CentOS automates the process of setting up MySQL, asking you a series of yes or no questions.

It’s easiest just to say Yes to all the options. At the end, MySQL will reload and implement the changes.
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
... Success!

Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
... Success!

By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
... Success!

Cleaning up...

All done! If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

Aj8I9Zy.png

Vy4f8zG.png


Step Three—Install nginx

As with MySQL, we will install nginx on our virtual private server using yum:

Code:
sudo yum install nginx

bStzyUi.png


nginx does not start on its own. To get nginx running, type:

Code:
sudo /etc/init.d/nginx start

LWtH21B.png


You can confirm that nginx has installed on your virtual private server by directing your browser to your IP address. You can run the following command to reveal your server’s IP address.

Code:
ifconfig eth0 | grep inet | awk '{ print $2 }'

Step Four—Install PHP

The php-fpm package is located within the REMI repository, which, at this point, is disabled. The first thing we need to do is enable the REMI repository and install php and php-fpm:

Code:
sudo yum --enablerepo=remi install php-fpm php-mysql

qOMWUGS.png


Step Five—Configure php

We need to make one small change in the php configuration.

Open up php.ini:

Code:
sudo vi /etc/php.ini

Find the line, cgi.fix_pathinfo=1, and change the 1 to 0.

Code:
cgi.fix_pathinfo=0

If this number is kept as a 1, the php interpreter will do its best to process the file that is as near to the requested file as possible. This is a possible security risk. If this number is set to 0, conversely, the interpreter will only process the exact file path—a much safer alternative.

Save and Exit.

ZZQRwx2.png


Step Six—Configure nginx

Open up the default nginx config file:

Code:
sudo vi /etc/nginx/nginx.conf

Raise the number of worker processes to 4 then save and exit that file.

bQUD2Pi.png


Now we should configure the nginx virtual hosts. In order to make the default nginx file more concise, the virtual host details are in a different location.

Code:
sudo vi /etc/nginx/conf.d/default.conf

The configuration should include the changes below (the details of the changes are under the config information):

Code:
#
# The default server
#
server {
    listen       80;
    server_name example.com;

    location / {
        root   /usr/share/nginx/html;
        index index.php  index.html index.htm;
    }

    error_page  404              /404.html;
    location = /404.html {
        root   /usr/share/nginx/html;
    }

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

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        root           /usr/share/nginx/html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

Here are the details of the changes:

  • Add index.php within the index line.


  • Change the server_name to your domain name or IP address (replace the example.com in the configuration)


  • Change the root to /usr/share/nginx/html;


  • Uncomment the section beginning with "location ~ \.php$ {",


  • Change the root to access the actual document root, /usr/share/nginx/html;


  • Change the fastcgi_param line to help the PHP interpreter find the PHP script that we stored in the document root home.

Save and Exit

LN1PrHK.png

TIHrVk8.png


Open up the php-fpm configuration:

Code:
sudo vi /etc/php-fpm.d/www.conf

Replace the apache in the user and group with nginx:

[...]
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
; RPM: apache Choosed to be able to access some dir as httpd
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx
[...]

teaKgsF.png


Finish by restarting php-fpm.

Code:
sudo service php-fpm restart

IBl5HxB.png


Step Seven—RESULTS: Create a php info page

Although LEMP is installed, we can still take a look and see the components online by creating a quick php info page To set this up, first create a new file:

Code:
sudo vi /usr/share/nginx/html/info.php

Add in the following line:

Code:
<?php
phpinfo();
?>

Then Save and Exit. Restart nginx so that all of the changes take effect:

Code:
sudo service nginx restart

Finish up by visiting your php info page (make sure you replace the example ip address with your correct one):

http://IP/info.php

IT14JPj.png


Step Eight—Set Up Autostart

You are almost done. The last step is to set all of the newly installed programs to automatically begin when the VPS boots.

Code:
sudo chkconfig --levels 235 mysqld on 
sudo chkconfig --levels 235 nginx on 
sudo chkconfig --levels 235 php-fpm on

UMTnuOx.png


About Wordpress

Wordpress is a free and open source website and blogging tool that uses php and MySQL. It was created in 2003 and has since then expanded to manage 22% of all the new websites created and has over 20,000 plugins to customize its functionality.

Step Nine—Download WordPress

We can download Wordpress straight from their website:

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

This command will download the zipped wordpress package straight to your user's home directory. You can unzip it the the next line:

Code:
tar -xzvf latest.tar.gz

Step Ten—Create the WordPress Database and User

After we unzip the wordpress files, they will be in a directory called wordpress in the home directory.
Now we need to switch gears for a moment and create a new MySQL directory for wordpress.
Go ahead and log into the MySQL Shell:

Code:
mysql -u root -p

Login using your MySQL root password, and then we need to create a wordpress database, a user in that database, and give that user a new password. Keep in mind that all MySQL commands must end with semi-colon.
First, let's make the database (I'm calling mine wordpress for simplicity's sake; feel free to give it whatever name you choose):

Code:
CREATE DATABASE wordpress; 
Query OK, 1 row affected (0.00 sec)

Then we need to create the new user. You can replace the database, name, and password, with whatever you prefer:
Code:
CREATE USER wordpressuser@localhost; 
Query OK, 0 rows affected (0.00 sec)

Set the password for your new user:
Code:
SET PASSWORD FOR wordpressuser@localhost= PASSWORD("password"); Query OK, 0 rows affected (0.00 sec)

Finish up by granting all privileges to the new user. Without this command, the wordpress installer will not be able to start up:
Code:
GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost IDENTIFIED BY 'password'; 
Query OK, 0 rows affected (0.00 sec)

Then refresh MySQL:
Code:
FLUSH PRIVILEGES; 
Query OK, 0 rows affected (0.00 sec)

Exit out of the MySQL shell:

Code:
exit

NvLjPmC.png


Step Eleven—Setup the WordPress Configuration

The first step to is to copy the sample WordPress configuration file, located in the WordPress directory, into a new file which we will edit, creating a new usable WordPress config:

Code:
cp ~/wordpress/wp-config-sample.php ~/wordpress/wp-config.php

Then open the wordpress config:

Code:
sudo nano ~/wordpress/wp-config.php

Find the section that contains the field below and substitute in the correct name for your database, username, and password:

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

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

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

Save and Exit.

DPI0igz.png


Step Four—Copy the Files

We are almost done uploading Wordpress to the server. We need to create the directory where we will keep the wordpress files:

Code:
sudo mkdir -p /usr/share/nginx/html/wordpress

The final move that remains is to transfer the unzipped WordPress files to the website's root directory.

Code:
sudo cp -r ~/wordpress/* /usr/share/nginx/html/wordpress

OCbGEGP.png


Step Twelve—RESULTS: Access the WordPress Installation

Once that is all done, the wordpress online installation page is up and waiting for you:

http://IP/wordpress

GpKT9U1.png


So finally its done ! Once it is installed you can access .

0J4ZXRf.png



If anyone is facing any issues you can comment below or PM me or Email me , i'll help you to sort that out .
 

5 comments

That's one awesome tutorial you've got there. We can clearly see the effort you have put into this thing, appreciate it Bharat. Good work, keep it up. (y)

Looking forward for more.
 
Status
Not open for further replies.

About the author

Bharat
Active Member · Joined
2,003
Messages
841
Reactions
113
Points

Advertise on WJunction

Reach 1000's of webmasters, hosts & affiliates. Banner & sponsored-thread slots available.

Contact us
Back
Top Bottom