﻿{"id":1079,"date":"2012-12-26T13:38:16","date_gmt":"2012-12-26T05:38:16","guid":{"rendered":"http:\/\/nick.workao.org\/?p=1079"},"modified":"2012-12-26T13:38:17","modified_gmt":"2012-12-26T05:38:17","slug":"install-nginxphp-fpm-on-fedora-1716-centosrhel-6-35-8","status":"publish","type":"post","link":"https:\/\/nick.txtcc.com\/index.php\/linux\/1079","title":{"rendered":"Install Nginx\/PHP-FPM on Fedora 17\/16, CentOS\/RHEL 6.3\/5.8"},"content":{"rendered":"<p>I have once written\u00a0<a href=\"http:\/\/www.if-not-true-then-false.com\/2009\/install-nginx-php-5-3-and-fastcgi-on-centos-fedora-red-hat-rhel\/\">Install nginx, PHP 5.3 and FastCGI on CentOS 5.5, Fedora 13, Red Hat RHEL 5.5\/6<\/a>\u00a0guide, but this guide is \u201cupdated\u201d version,\u00a0<strong>howto install Nginx with PHP 5.4.10 and PHP-FPM on Fedora 17\/16\/15\/14, CentOS 6.3\/6.2\/6.1\/6\/5.8 and Red Hat (RHEL) 6.3\/6.2\/6.1\/6\/5.8<\/strong>. PHP-FPM is easier to use and configure than FastCGI and some tests says that PHP-FPM is even much more efficient than FastCGI.<\/p>\n<p><strong><a title=\"nginx Home Page\" href=\"http:\/\/nginx.org\/\" target=\"_blank\">Nginx (engine x)<\/a><\/strong>\u00a0is a robust, small and high performance http server, reverse proxy server and also mail proxy server.<\/p>\n<p><strong><a title=\"PHP-FPM Home Page\" href=\"http:\/\/php-fpm.org\/\" target=\"_blank\">PHP-FPM (FastCGI Process Manager)<\/a><\/strong>\u00a0is an alternative PHP FastCGI implementation with some additional features useful for sites of any size, especially busier sites.<\/p>\n<div><\/div>\n<h2>Install Nginx, PHP 5.4.10 and PHP-FPM on Fedora 17\/16\/15\/14, CentOS 6.3\/6.2\/6.1\/6\/5.8, Red Hat (RHEL) 6.3\/6.2\/6.1\/6\/5.8<\/h2>\n<div><\/div>\n<h3>1. Change to root user.<\/h3>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre>sudo -i\n## OR ##\nsu -<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div><\/div>\n<h3>2. Install needed repositories<\/h3>\n<h4>Fedora 17\/16\/15\/14 Remi repository<\/h4>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre>## Remi Dependency on Fedora 17, 16\nrpm -Uvh http:\/\/download1.rpmfusion.org\/free\/fedora\/rpmfusion-free-release-stable.noarch.rpm \nrpm -Uvh http:\/\/download1.rpmfusion.org\/nonfree\/fedora\/rpmfusion-nonfree-release-stable.noarch.rpm\n\n## Fedora 17 ##\nrpm -Uvh http:\/\/rpms.famillecollet.com\/remi-release-17.rpm\n\n## Fedora 16 ##\nrpm -Uvh http:\/\/rpms.famillecollet.com\/remi-release-16.rpm\n\n## Fedora 15 ##\nrpm -Uvh http:\/\/rpms.famillecollet.com\/remi-release-15.rpm\n\n## Fedora 14 ##\nrpm -Uvh http:\/\/rpms.famillecollet.com\/remi-release-14.rpm<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div><\/div>\n<h4>CentOS 6.3\/6.2\/6.1\/6\/5.8 and Red Hat (RHEL) 6.3\/6.2\/6.1\/6\/5.8 Remi repository<\/h4>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre>## Remi Dependency on CentOS 6 and Red Hat (RHEL) 6 ##\nrpm -Uvh http:\/\/download.fedoraproject.org\/pub\/epel\/6\/i386\/epel-release-6-7.noarch.rpm\n\n## CentOS 6 and Red Hat (RHEL) 6 ##\nrpm -Uvh http:\/\/rpms.famillecollet.com\/enterprise\/remi-release-6.rpm\n\n## Remi Dependency on CentOS 5 and Red Hat (RHEL) 5 ##\nrpm -Uvh http:\/\/dl.fedoraproject.org\/pub\/epel\/5\/i386\/epel-release-5-4.noarch.rpm\n\n## CentOS 5 and Red Hat (RHEL) 5 ## \nrpm -Uvh http:\/\/rpms.famillecollet.com\/enterprise\/remi-release-5.rpm<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h4>CentOS 6.3\/6.2\/6.1\/6\/5.8 and Red Hat (RHEL) 6.3\/6.2\/6.1\/6\/5.8 Nginx repository<\/h4>\n<p>Create file \/etc\/yum.repos.d\/nginx.repo and add following content to repo file:\n<strong>CentOS<\/strong><\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre>[nginx]\nname=nginx repo\nbaseurl=http:\/\/nginx.org\/packages\/centos\/$releasever\/$basearch\/\ngpgcheck=0\nenabled=1<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p><strong>Red Hat (RHEL)<\/strong><\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre>[nginx]\nname=nginx repo\nbaseurl=http:\/\/nginx.org\/packages\/rhel\/$releasever\/$basearch\/\ngpgcheck=0\nenabled=1<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div><\/div>\n<h3>3. Install Nginx, PHP 5.4.10 and PHP-FPM<\/h3>\n<h4>Fedora 17\/16\/15\/14, CentOS 6.3\/5.8 and Red Hat (RHEL) 6.3\/5.8<\/h4>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre>yum --enablerepo=remi install nginx php php-fpm php-common<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h4>CentOS 6.3\/5.8 and Red Hat (RHEL) 6.3\/5.8<\/h4>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre>yum --enablerepo=remi,remi-test install nginx php php-fpm php-common<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div><\/div>\n<h3>4. Install PHP 5.4.10 modules<\/h3>\n<ul>\n    <li><strong>APC (php-pecl-apc)<\/strong>\u00a0\u2013 APC caches and optimizes PHP intermediate code<\/li>\n    <li><strong>CLI (php-cli)<\/strong>\u00a0\u2013 Command-line interface for PHP<\/li>\n    <li><strong>PEAR (php-pear)<\/strong>\u00a0\u2013 PHP Extension and Application Repository framework<\/li>\n    <li><strong>PDO (php-pdo)<\/strong>\u00a0\u2013 A database access abstraction module for PHP applications<\/li>\n    <li><strong>MySQL (php-mysql)<\/strong>\u00a0\u2013 A module for PHP applications that use MySQL databases<\/li>\n    <li><strong>PostgreSQL (php-pgsql)<\/strong>\u00a0\u2013 A PostgreSQL database module for PHP<\/li>\n    <li><strong>MongoDB (php-pecl-mongo)<\/strong>\u00a0\u2013 PHP MongoDB database driver<\/li>\n    <li><strong>SQLite (php-sqlite)<\/strong>\u00a0\u2013 Extension for the SQLite V2 Embeddable SQL Database Engine<\/li>\n    <li><strong>Memcache (php-pecl-memcache)<\/strong>\u00a0\u2013 Extension to work with the Memcached caching daemon<\/li>\n    <li><strong>Memcached (php-pecl-memcached)<\/strong>\u00a0\u2013 Extension to work with the Memcached caching daemon<\/li>\n    <li><strong>GD (php-gd)<\/strong>\u00a0\u2013 A module for PHP applications for using the gd graphics library<\/li>\n    <li><strong>XML (php-xml)<\/strong>\u00a0\u2013 A module for PHP applications which use XML<\/li>\n    <li><strong>MBString (php-mbstring)<\/strong>\u00a0\u2013 A module for PHP applications which need multi-byte string handling<\/li>\n    <li><strong>MCrypt (php-mcrypt)<\/strong>\u00a0\u2013 Standard PHP module provides mcrypt library support<\/li>\n<\/ul>\n<p>Select what you need: APC, CLI, PEAR, PDO, MySQL, PostgreSQL, MongoDB, SQLite, Memcache, Memcached, GD, MBString, MCrypt, XML<\/p>\n<p>More info about PHP APC from\u00a0<a href=\"http:\/\/www.if-not-true-then-false.com\/2012\/php-apc-configuration-and-usage-tips-and-tricks\/\">PHP APC Configuration and Usage Tips and Tricks<\/a><\/p>\n<h4>Fedora 17\/16\/15\/14<\/h4>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre>yum --enablerepo=remi install php-pecl-apc php-cli php-pear php-pdo php-mysql php-pgsql php-pecl-mongo php-sqlite php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h4>CentOS 6.3\/5.8 and Red Hat (RHEL) 6.3\/5.8<\/h4>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre>yum --enablerepo=remi,remi-test install php-pecl-apc php-cli php-pear php-pdo php-mysql php-pgsql php-pecl-mongo php-sqlite php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div><\/div>\n<h3>5. Stop httpd (Apache) server, Start Nginx HTTP server and PHP-FPM (FastCGI Process Manager)<\/h3>\n<h4>Stop httpd (Apache)<\/h4>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre>\/etc\/init.d\/httpd stop\n## OR ##\nservice httpd stop<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h4>Start Nginx<\/h4>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre>\/etc\/init.d\/nginx start ## use restart after update\n## OR ##\nservice nginx start ## use restart after update<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h4>Start PHP-FPM<\/h4>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre>\/etc\/init.d\/php-fpm start ## use restart after update\n## OR ##\nservice php-fpm start ## use restart after update<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div><\/div>\n<h3>6. Autostart Nginx and PHP-FPM on boot, also prevent httpd (Apache) autostarting on boot<\/h3>\n<h4>Prevent httpd (Apache) autostarting on boot<\/h4>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre>chkconfig httpd off<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h4>Autostart Nginx on boot<\/h4>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre>chkconfig --add nginx\nchkconfig --levels 235 nginx on<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h4>Autostart PHP-FPM on boot<\/h4>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre>chkconfig --add php-fpm\nchkconfig --levels 235 php-fpm on<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div><\/div>\n<h3>7. Configure Nginx and PHP-FPM<\/h3>\n<h4>Create directory layout for your site<\/h4>\n<p>I use here\u00a0<em>testsite.local<\/em>\u00a0site, but this could of course be your real site, like\u00a0<em>www.if-not-true-then-false.com<\/em>.<\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre>## public_html directory and logs directory ##\nmkdir -p \/srv\/www\/testsite.local\/public_html\nmkdir \/srv\/www\/testsite.local\/logs\nchown -R apache:apache \/srv\/www\/testsite.local<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>Alternative setup to add logs under\u00a0<em>\/var\/log<\/em>\u00a0directory.<\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre>## public_html directory and logs directory ##\nmkdir -p \/srv\/www\/testsite.local\/public_html\nmkdir -p \/var\/log\/nginx\/testsite.local\nchown -R apache:apache \/srv\/www\/testsite.local\nchown -R nginx:nginx \/var\/log\/nginx<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p><strong>Note:<\/strong>\u00a0I use apache user and group here, because PHP-FPM runs as apache default (apache choosed to be able to access some dir as httpd). If you use some other user on your php-fpm conf then change this accordingly.<\/p>\n<h4>Create and configure virtual host directories under\u00a0<em>\/etc\/nginx<\/em><\/h4>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre>mkdir \/etc\/nginx\/sites-available\nmkdir \/etc\/nginx\/sites-enabled<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>Add following lines to\u00a0<em>\/etc\/nginx\/nginx.conf<\/em>\u00a0file, after\u00a0<em>\u201cinclude \/etc\/nginx\/conf.d\/*.conf\u201d<\/em>\u00a0line (inside http block).<\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre>## Load virtual host conf files. ##\ninclude \/etc\/nginx\/sites-enabled\/*;<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h4>Create\u00a0<em>testsite.local<\/em>\u00a0virtual host file<\/h4>\n<p>Add following content to\u00a0<em>\/etc\/nginx\/sites-available\/testsite.local<\/em>\u00a0file. This is very basic virtual host config.<\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre>server {\n    server_name testsite.local;\n    access_log \/srv\/www\/testsite.local\/logs\/access.log;\n    error_log \/srv\/www\/testsite.local\/logs\/error.log;\n    root \/srv\/www\/testsite.local\/public_html;\n\n    location \/ {\n        index index.html index.htm index.php;\n    }\n\n    location ~ \\.php$ {\n        include \/etc\/nginx\/fastcgi_params;\n        fastcgi_pass  127.0.0.1:9000;\n        fastcgi_index index.php;\n        fastcgi_param SCRIPT_FILENAME \/srv\/www\/testsite.local\/public_html$fastcgi_script_name;\n    }\n}<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h4>Link your virtual host to\u00a0<em>\/etc\/nginx\/sites-enabled<\/em><\/h4>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre>cd \/etc\/nginx\/sites-enabled\/\nln -s \/etc\/nginx\/sites-available\/testsite.local\nservice nginx restart<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h4>Add your testsite.local \u201cdomain\u201d to \/etc\/hosts file<\/h4>\n<p><strong>\/etc\/hosts file Nginx on same machine<\/strong>\n127.0.0.1 \u2026 row should look like example following:<\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre>127.0.0.1               localhost.localdomain localhost testsite.local<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p><strong>And if you use another machine where you are running your Nginx server, then add it\u2019s public IP as following:<\/strong><\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre>10.0.2.19               wordpress<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p><strong>Note:<\/strong>\u00a0This is just very simple basic configuration, but if you want configure and optimize Nginx and PHP-FPM more then check following guide,\u00a0<a title=\"Nginx and PHP-FPM Configuration and Optimizing Tips and Tricks\" href=\"http:\/\/www.if-not-true-then-false.com\/2011\/nginx-and-php-fpm-configuration-and-optimizing-tips-and-tricks\/\" target=\"_blank\">Nginx and PHP-FPM Configuration and Optimizing Tips and Tricks<\/a><\/p>\n<div><\/div>\n<h3>8. Test your Nginx and PHP-FPM setup<\/h3>\n<p>Create\u00a0<em>\/srv\/www\/testsite.local\/public_html\/index.php<\/em>\u00a0file with following content:<\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre><?php \n    phpinfo();\n?><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>Access following address, with your browser.\u00a0<a title=\"Just testing\" href=\"http:\/\/testsite.local\/\" target=\"_blank\" rel=\"nofollow\"><a href=\"http:\/\/testsite.local\/\">http:\/\/testsite.local\/<\/a><\/a>\n<a href=\"http:\/\/media.if-not-true-then-false.com\/2011\/10\/nginx-php-5.4.4-php-fpm.png\"><img loading=\"lazy\" decoding=\"async\" title=\"Nginx PHP 5.4.4 PHP-FPM\" alt=\"Nginx PHP 5.4.4 PHP-FPM\" src=\"http:\/\/nick.txtcc.com\/wp-content\/uploads\/remote_image\/2012\/12\/053816DDU.png\" width=\"560\" height=\"496\" \/><\/a><\/p>\n<div><\/div>\n<h2>Enable Remote Connection to Nginx Web Server (Open Port 80 on Iptables Firewall)<\/h2>\n<h3>1. Edit \/etc\/sysconfig\/iptables file:<\/h3>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre>nano -w \/etc\/sysconfig\/iptables<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div><\/div>\n<h3>2. Add following line before COMMIT:<\/h3>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre>-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div><\/div>\n<h3>3. Restart Iptables Firewall:<\/h3>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre>service iptables restart\n## OR ##\n\/etc\/init.d\/iptables restart<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div><\/div>\n<h3>4. Test remote connection<\/h3>\n<p>Access following address, with your browser.\u00a0<a href=\"http:\/\/your.domain\/\" target=\"_blank\" rel=\"nofollow\"><a href=\"http:\/\/your.domain\/\">http:\/\/your.domain\/<\/a><\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>I have once written\u00a0Install nginx, PHP 5.3 and FastCGI on CentOS 5.5, Fedora 13, Red Hat RHEL 5.5\/6\u00a0&#46;&#46;&#46;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[268,442,354],"class_list":["post-1079","post","type-post","status-publish","format-standard","hentry","category-linux","tag-nginx","tag-php","tag-redhat"],"_links":{"self":[{"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/1079","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/comments?post=1079"}],"version-history":[{"count":1,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/1079\/revisions"}],"predecessor-version":[{"id":1081,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/1079\/revisions\/1081"}],"wp:attachment":[{"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/media?parent=1079"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/categories?post=1079"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/tags?post=1079"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}