Breaking News
Loading...
September 7, 2014

How to install LEMP web server with Nginx, PHP-FPM 5.5, MySQL 5.5 on Centos Linux

1:02 AM
I have shown you How to install LEMP server with Linux, Nginx, PHP-FPM, and MySQL on Centos with standard packages from Centos repository, which comes with older version of PHP 5.3.x and MySQL 5.1.x. Since there are many new great features from PHP 5.5.x and MySQL 5.5.x which I mentioned in How to install LAMP server with Apache 2.2, MySQL 5.5.37, PHP 5.5.11 on Centos Linux. Why not install newer version of PHP 5.5.x and MySQL 5.5.x on nginx, HP-FPM, MySQL or LEMP server stack.
We are going to use EPEL (Extra Packages for Enterprise Linux) and REMI (Les RPM de Remi) repositories for this article, since EPEL repository already has nginx package so we don’t need to add nginx repository to our server.
Installing EPEL and REMI Repository for Centos 32 bit
# 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
Installing EPEL and REMI Repository for Centos 64 bit
# rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
Installing EPEL and REMI Repository for Fedora 17 / 18 / 19 / 20
# rpm -Uvh http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm# rpm -Uvh http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm
Installing Nginx repository for Red Hat/CentOS/Fedora
nginx package does not come as default package for Centos or RHEL (Red Hat Enterprise Linux), both REMI and EPEL have nginx packages but not the newest. To install nginx, you have to add nginx yum repository or directly install rpm package.
Create a file named nginx.repo in /etc/yum.repos.d/ directory
# nano /etc/yum.repos.d/nginx.repo
with the content
For Centos 6.x
For Centos 5.x
For RHEL 6.x (Red Hat Enterprise Linux)
For RHEL 5.x (Red Hat Enterprise Linux)
Install nginx web-server
After adding EPEL and REMI repositories, we now can install nginx
# yum install nginx
To start nginx
# service nginx start
To start nginx automatically when the system boot/reboot
# chkconfig nginx on
Your nginx web server should be running by now, if you can’t access your nginx web server, you may have not allowed http or port 80 access to your server on iptables rules. To allow http access to your server
# iptables -F# iptables -P OUTPUT ACCEPT# iptables -P INPUT ACCEPT# iptables -P FORWARD ACCEPT# iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT# iptables -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT# iptables -I INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT# iptables-save
When you install nginx from EPEL repository, the default nginx placeholder web page will look different from the nginx from nginx repository.
Nginx from EPEL repository
namhuy_nginx_epel
Nginx from nginx repository
namhuy_welcome_to_nginx
Install MySQL 5.5.x server
We are going to install MySQL database server from remi repository instead of Centos default repository.
Centos 5.10 / Centos 6.5
# yum --enablerepo=remi,remi-php55 install mysql-server
Fedora 20 Heisenbug / 19 Schrödinger’s Cat
# yum --enablerepo=remi install mysql-server
Fedora 18 Spherical Cow / 17 Beefy Miracle
# yum --enablerepo=remi,remi-test install mysql-server
To start MySQL database server
# service mysqld start
To start MySQL server at Startup
# chkconfig mysqld on
Secure MySQL server
You should always run mysql_secure_installation after install mysql since default mysql server configuration isn’t safe enough. You will be asked to type in your new MySQL root password, and say Y for yes for the rest of the options
  • Remove root’s remote access
  • Remove anonymous users
  • Disallow root login remotely
  • Reload privilege tables
# mysql_secure_installation
Install PHP or PHP-FPM
We are going to install PHP, PHP-FPM/FastCGI, from remi-php55 repository to get the latest php5 packages. PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features.
# yum --enablerepo=remi,remi-php55 install php-fpm php-common php-mysql php-pear php-gd php-devel php-mbstring php-mcrypt php-cli php-pdo php-xml
To start PHP-FPM
# /etc/init.d/php-fpm start
or
# service php-fpm start
To run PHP-FPM automatically when the system boot/reboot
# chkconfig php-fpm on
Configure nginx to work with PHP
# nano /etc/nginx/conf.d/default.conf
Modify / append as follows:
Search for
add index.php to index line
Save and close the file. Restart nginx:
# service nginx restart
To confirm nginx and PHP are working
Default nginx html/php files will be stored in /usr/share/nginx/html . You can change nginx default document root directory in /etc/nginx/conf.d/default.conf if you wish to. By the way we are creating php test file to check if nginx and php are working
# nano /usr/share/nginx/html/info.php
With the content
Save and exit, fire up your website and go to info.php file by going http://yourdomain/info.php
namhuy_nginx_php5_5
You should see PHP version 5.5.x, and at “server API” line you should see FPM/FastCGI
——————————
Note:
To start/restart/stop nginx web server
# service nginx start# service nginx restart# service nginx stop
To start/restart/stop MySQL server
# service mysqld start# service mysqld restart# service mysqld stop
To start/restart/stop PHP-FPM server
# service php-fpm start# service php-fpm restart# service php-fpm stop
REMI repository is not enabled by default, every time you want to install/update packages via remi repository you will have to include enablerepo=remi option in yum command.
Centos 5.10 / Centos 6.5
# yum --enablerepo=remi,remi-php55 update
Fedora 20 Heisenbug / 19 Schrödinger’s Cat
# yum --enablerepo=remi update
Fedora 18 Spherical Cow / 17 Beefy Miracle
# yum --enablerepo=remi,remi-test update


Source URL:http://www.namhuy.net/

0 comments:

Post a Comment

 
Toggle Footer