ScaleScaleScaleScale

Tips / Nginx


Install Nginx with PHP-FPM + MySQL support on CentOS/RHEL

Installing a full Nginx + PHP-FPM + MySQL stack in CentOS is pretty easy, you just need to run a few commands and then configure all the services. Since CentOS 6.x yum natively supports php-fpm, so there is no need to use EPEL repo as we used before.

Let’s get started:

Nginx installation

Download latest Nginx CentOS repo from: http://nginx.org/en/download.html. In my case I used CentOS 6.x RPM.

wget http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
rpm -i nginx-release-centos-6-0.el6.ngx.noarch.rpm
yum install nginx -y

PHP-FPM installation

yum install php-gd php-mbstring php-mysql php-xml php-fpm -y

MySQL installation

yum install mysql mysql-server -y

Ensure all these services start after reboot:

chkconfig nginx on
chkconfig php-fpm on
chkconfig mysqld on

All done, now you need to:

* Configure nginx from /etc/nginx/nginx.conf
* Configure php-fpm from /etc/php-fpm.conf and /etc/php-fpm.d/www.conf
* Configure mysql from /etc/my.conf

How to start/restart services once configured:

service nginx start/stop/reload/restart
service php-fpm start/stop/reload/restart
service mysqld start/stop/reload/restart

Popular search terms:

  • openbsd nginx php mysql
  • fpm rpm mysql
  • rhel7 nginx php 5 4
profile

Esteban Borges

Linux Geek, Webperf Addict, Nginx Fan. CTO @Infranetworking

  • Tux

    I wonder how would you do it when you want to upgrade php 5.3.3 which is the latest version supported by centos v6.x…

  • admin

    @Tux

    If you need to update php 5.3.3 to it’s latest version, just:
    yum update php* and then service php-fpm restart.

    If you need to upgrade to PHP 5.4:

    1.- Install this repo to match your server version and architecture: http://iuscommunity.org/pages/Repos.html
    2.- service nginx stop; yum remove php*; install: yum install php54u*
    3.- Configure /etc/php-fpm.d/www.conf again and restart the service: service php-fpm restart; service nginx start.

    Be careful about this, following this 2nd option involes downtime.

  • Sam

    Thanks very much for this helpful article! I wasn’t aware that PHP-FPM was already available in CentOS 6.x, and their provided PHP version is at the exact version that I need.