CentOSMy SQLServer

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

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

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/6/$basearch/
gpgcheck=0
enabled=1
For Centos 5.x
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/5/$basearch/
gpgcheck=0
enabled=1
For RHEL 6.x (Red Hat Enterprise Linux)
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/rhel/6/$basearch/
gpgcheck=0
enabled=1
For RHEL 5.x (Red Hat Enterprise Linux)
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/rhel/5/$basearch/
gpgcheck=0
enabled=1
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
Nginx from nginx repository
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

Modify / append as follows:

Related Articles

Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
Back to top button