Install Nginx PHP-FPM on CentOS
NGINX (pronounced engine-x) is an open source web server that excels at large scale web integration, application security, web acceleration, content and application delivery and PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features useful especially for heavy traffic sites.
Below are the steps to install Nginx + PHP-FPM on CentOS 6 Server.
First of all you will have to add the remi repository and install php-fpm with php modules.
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm yum --enablerepo=remi install php php-common php-cli php-fpm php-mysql php-pdo php-pecl-apc php-mcrypt php-xml php-gd php-mbstring
The add the nginx repo and install nginx. Create file /etc/yum.repos.d/nginx.repo and add the below contents to it
[nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=0 enabled=1
Now install the nginx
yum -y install nginx
Now it’s time to do the configuration. PHP-FPM daemon process by default listens on port 9000 and the default user is apache. We can configure it to listen on unix socket and run as user nginx. Edit the file /etc/php-fpm.d/www.conf and make the below changes
#listen = 127.0.0.1:9000 listen = /var/run/php-fpm/php-fpm.sock # change user to nginx instead of apache #user = apache user = nginx #group = apache group = nginx
Now edit the nginx configuration file /etc/nginx/conf.d/default.conf and make the below changes.( Add the lines if they don’t exist)
location ~ \.php$ { #include /etc/nginx/fastcgi.conf; fastcgi_split_path_info ^(.+\.php)(.*)$; #fastcgi_pass 127.0.0.1:9000; fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #fastcgi_param SCRIPT_FILENAME $request_filename; include fastcgi_params; }