Posted on

How to Install the latest LEMP Stack on CentOS 6.5

In this tutorial,we’ll learn that how we can install the latest LEMP (Nginx, MySQL & PHP) Stack and it’s initial configuration on CentOS 6.5, because Base and EPEL repo are containing really old version of LEMP Stack.

Please add the required repos by using the following commands:

sudo rpm --import http://ftp.riken.jp/Linux/fedora/epel/RPM-GPG-KEY-EPEL-6
sudo rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
sudo rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
sudo yum repolist

1

We’ll have mysql55-libs conflicts with mysql-libs error, if we’ll proceed like this. To resolve this conflict, we need to issue these commands:

sudo yum install yum-plugin-replace
sudo yum replace mysql-libs --replace-with mysql55w-libs

2

Now, we can safely issue this command to install the latest version of Nginx, MySQL and PHP with PHP-Fpm:

sudo yum install nginx16 mysql55w mysql55w-server php55w php55w-opcache php55w-fpm

3

Enable Nginx, MySQL and PHP-FPM to automatically begin when the server boot:

sudo chkconfig nginx on
sudo chkconfig mysqld on
sudo chkconfig php-fpm on

3a

Secure the PHP by editing the php.ini file:

sudo vi /etc/php.ini

4

Uncomment the cgi.fix_pathinfo and change it from 1 to 0:

cgi.fix_pathinfo=0

5

Edit the  /etc/php-fpm.d/www.conf  file:

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

6

Change the user and group:

user = nginx
group = nginx

7

Next we need to do some modification in default nginx.conf file:

sudo vi /etc/nginx/nginx.conf

8

Increase the worker processes from 1 to 4:

9

Also delete the default server config block to make the file more concise:

10

Move to the /etc/nginx/conf.d/ directory:

cd /etc/nginx/conf.d/

11

Next, we’ll create the virtual host file for our domain (In my case it’s rbgeek.conf):

sudo vi rbgeek.conf

12

This is a basic virtual host config file:

server {
       listen 80;
       server_name rbgeek.com;

       access_log /var/log/nginx/rbgeek_access.log main;
       error_log /var/log/nginx/rbgeek_error.log;
     
   location / {
       root /var/www/rbgeek;
       index index.php index.html index.htm;
   }
   
   # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

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

13

Finally, restart the Nginx and PHP-FPM services:

sudo service nginx restart
sudo service php-fpm restart

13a

Create a directory structure for the website under /var/www/.If you have another preference, please update the config files accordingly:

sudo mkdir -p /var/www/rbgeek

14

Adjust the permission:

sudo chgrp -R nginx /var/www/rbgeek
sudo chmod g+s /var/www/rbgeek

15

Create a phpinfo page to verify that the php is working correctly with Nginx:

sudo vi /var/www/rbgeek/info.php

16

Add the following code in it:

<?php
phpinfo();
?>

17

Navigate to the site in web browser and verify that the php information is returned:

http://rbgeek.com/info.php

20

(Optional) Verify that all the packages are updated by using the code in your index page:

19

Hope this will help you!

Posted on

How To Install WordPress with Nginx in Ubuntu Server 14.04 LTS

Install the LEMP stack(Linux, Nginx, Mysql, PHP) with the command below:

sudo apt-get install nginx mysql-server php5-fpm php5-mysql

1Note: Please set the MySQL root password, when it will prompt for it during the installation of MySQL-Server.

Secure the PHP by editing the php.ini file:

sudo vi /etc/php5/fpm/php.ini

2

Uncomment the cgi.fix_pathinfo and change it from 1 to 0:

cgi.fix_pathinfo=0

3

Create the new virtual host for wordpress (In my case, I have named it tendosite):

sudo vi /etc/nginx/sites-available/tendosite

4

Add the following code to the virtual host file (change these parameters that are marked with blue colour):

server {
             listen 80;
             server_name rbgeek.com;
            
             root /var/www/wordpress;
             index index.php index.html index.htm;

             location / {
                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$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+.php)(/.+)$;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
              }
}

Enable the virtual host by creating it’s link inside the /etc/nginx/sites-enabled:

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

6

Change the permission and owner of php5-fpm.sock by editing the /etc/php5/fpm/pool.d/www.conf file:

sudo vi /etc/php5/fpm/pool.d/www.conf

7

Remove the comment for listen.mode, .group and .owner:

listen.owner = www-data
listen.group = www-data
listen.mode = 0660

8

To start the MySQL command-line client, use this command:

mysql -u root -p

9

Create a wordpress database and granting all privileges to the wordpress user on that database:

CREATE DATABASE wordpress;
GRANT ALL PRIVILEGES ON wordpress.* TO wpuser@localhost IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
EXIT;

10Note: In this tutorial, wpuser will be used for wordpress.

Download the latest version of wordpress:

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

11

Use this command to unpack the WordPress files:

tar -zxvf latest.tar.gz

12

Move to the extracted wordpress directory and change the name of the config file from wp-config-sample.php towp-config.php and then edit the wp-config.php file:

cd wordpress/
mv wp-config-sample.php wp-config.php
vi wp-config.php

13

Insert your MySQL settings that you have created for wordpress:

14

Create the wordpress directory inside www and move all the wordpress file to it:

sudo mkdir -p /var/www/wordpress
sudo cp -r * /var/www/wordpress/

15

Change the ownership of /var/www/wordpress directory to www-data:

sudo chown -R www-data. /var/www/wordpress

16

Move to the /var/www/wordpress/ directory and check the permission:

cd /var/www/wordpress/
ls -l

17

Restart the nginx service:

sudo service nginx restart

19

Finally restart the php5-fpm service:

sudo service php5-fpm restart

18

Open up the browser and go to http://hostname/wp-admin/install.php  to begin configuring WordPress:

http://rbgeek.com/wp-admin/install.php

20

Login to the admin section:

21

Congratulations!

22

Hope this will help you!