It is a guide to install LEMP on a Centos 6.4 64bit VPS at Burst.net. It is also working on other VPS. LEMP stands for Linux, NginX, MySQL, PHP.

First of all, rebuild the OS on VPS with Centos-6.2-x86_64.
os-load

Other VPS providers have similar interface to rebuild / reload operation system.

After 5 to 10 minutes, the VPS is ready to use.

SSH to VPS through PUTTY with root account.  The following installation steps will be done in terminal window.

1) Update the system to Centos 6.4

yum update

There are 158 updates need to be installed. So just confirm it and wait all the updates completed. Then the Centos is updated from 6.2 to 6.4.

2) Install the required repositories

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

3) Install MySQL server

yum install mysql mysql-server

Start MySQL

/etc/init.d/mysqld restart

Configure MySQL server

/usr/bin/mysql_secure_installation

It will guide you the whole procedure of steps to make the MySQL more security. It includes adding root password, remove sample database, remove anonymous user, disable root login remotely.

4) Install NginX

yum install nginx

Start nginx

/etc/init.d/nginx start

Check the IP address

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

or

ifconfig venet0:0 | grep inet | awk '{ print $2 }'

5) 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:

yum --enablerepo=remi install php-fpm php-mysql

6) Configure PHP

vi /etc/php.ini

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

cgi.fix_pathinfo=0

7) Configure Nginx

vi /etc/nginx/nginx.conf

Raise the number of worker processes to 4 then save and exit that file. Actually, my Burst.net VPS has one core only.

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.

vi /etc/nginx/conf.d/default.conf

The configuration should be including following things. Make sure the server_name is changed to your domain or IP address.


#
# The default server
#
server {
listen       80 default_server;
server_name sample.com;

#charset koi8-r;

#access_log  logs/host.access.log  main;

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;
}

# redirect server error pages to the static page /50x.html
#
error_page   500 502 503 504  /50x.html;
location = /50x.html {
root   /usr/share/nginx/html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
#    proxy_pass   http://127.0.0.1;
#}

# 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;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
#    deny  all;
#}
}

Configure php-fpm configuration

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

Replace apache by 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
[...]

Restart php-fmp

 service php-fpm restart

8) Add autostart services

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

8) Make a testing page with phpinfo() function and look at the following screenshots
NginX default page
nginx
PHP information page
php-nginx

There is one issue I have during installation. When I restart nginx, following error message shown:

 * Restarting nginx
 * Stopping nginx nginx
   ...done.
 * Starting nginx nginx
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
   ...done.
   ...done.

After do a little bit research, I found it is because of the port 80 is used by others. So I found it is Apache, another web server is running already.
I enter the command to remove Apache

yum remove httpd

David Yin

David is a blogger, geek, and web developer — founder of FreeInOutBoard.com. If you like his post, you can say thank you here

Leave a Reply

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