Home Backend Development PHP Tutorial Install Nginx/PHP-FPM environment on CentOS/RHEL6.2/5.8, Fedora17/16_PHP tutorial

Install Nginx/PHP-FPM environment on CentOS/RHEL6.2/5.8, Fedora17/16_PHP tutorial

Jul 13, 2016 pm 05:52 PM
centos nginx php php-fpm superior What exist Install yes environment

What is PHP-FPM
PHP-FPM is a PHP FastCGI manager, which is only used for PHP,
PHP-FPM is actually a patch of the PHP source code, designed to integrate FastCGI process management into the PHP package. It must be patched into your PHP source code, and it can be used after compiling and installing PHP.
Now we can download the branch that directly integrates PHP-FPM in the source tree of the latest PHP 5.3.2. It is said that the next version will be integrated into the main branch of PHP. Compared with Spawn-FCGI, PHP-FPM has better CPU and memory control, and the former crashes easily and must be monitored with crontab, while PHP-FPM does not have such troubles.
PHP5.3.3 has integrated php-fpm and is no longer a third-party package. PHP-FPM provides a better PHP process management method, which can effectively control memory and processes, and can smoothly reload PHP configuration. It has more advantages than spawn-fcgi, so it is officially included in PHP. PHP-FPM can be turned on by passing the –enable-fpm parameter in ./configure.
The above is excerpted from: What are CGI, FastCGI, PHP-CGI, PHP-FPM, Spawn-FCGI?
What is Nginx
Nginx ("engine x") is a high-performance HTTP and reverse proxy server, as well as an IMAP/POP3/SMTP proxy server.
Install and configure Nginx/PHP-FPM on Fedora17/16/15/14, CentOS6.2/6.1/6/5.8 and Red Hat (RHEL)6.2/6.1/6/5.8
Let’s get started

STEP1. Switch to root user
[plain]
su -
## OR ##
sudo -i


STEP2. Install necessary software sources
2-1. Install Remi source under Fedora 17/16/15/14
[plain]
## Remi Dependency on Fedora 17, 16, 15
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

## Fedora 17 ##
rpm -Uvh http://rpms.famillecollet.com/remi-release-17.rpm

## Fedora 16 ##
rpm -Uvh http://rpms.famillecollet.com/remi-release-16.rpm

## Fedora 15 ##
rpm -Uvh http://rpms.famillecollet.com/remi-release-15.rpm

## Fedora 14 ##
rpm -Uvh http://rpms.famillecollet.com/remi-release-14.rpm


2-1. Install Remi source under CentOS 6.2/6.1/6/5.8 and Red Hat (RHEL) 6.2/6.1//6/5.8
[plain]
## Remi Dependency on CentOS 6 and Red Hat (RHEL) 6 ##
rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-7.noarch.rpm

## CentOS 6 and Red Hat (RHEL) 6 ##
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm


## Remi Dependency on CentOS 5 and Red Hat (RHEL) 5 ##
rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm

## CentOS 5 and Red Hat (RHEL) 5 ##
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-5.rpm


2-2. Under CentOS 6.2/6.1/6/5.8 and Red Hat (RHEL) 6.2/6.1/6/5.8, Nginx source must also be configured
Create /etc/yum.repos.d/nginx.repo file and write the following content
CentOS
[plain]
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

RedHat(RHEL)
[plain]
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/rhel/$releasever/$basearch/
gpgcheck=0
enabled=1

STEP3. Install Nginx,PHP5.4.4&PHP-FPM
3-1. Fedora 17/16/15/14
[plain]
yum --enablerepo=remi install nginx php php-fpm php-common


3-1. Under CentOS 6.2/5.8 and Red Hat (RHEL) 6.2/5.8
[plain]
yum --enablerepo=remi,remi-test install nginx php php-fpm php-common


STEP4. Install PHP5.4.4 module extension
APC (php-pecl-apc) – APC cache optimization middleware
CLI (php-cli) – PHP command line plugin
PEAR (php-pear) – Official PHP extension
PDO (php-pdo) – Database PDO extension
MySQL (php-mysql) –MYSQL driver
PostgreSQL (php-pgsql) – PostgreSQL driver
MongoDB (php-pecl-mongo) – PHP MongoDB driver
SQLite (php-sqlite) – SQLite V2 engine and driver
Memcache (php-pecl-memcache) – Memcache driver
Memcached (php-pecl-memcached) – Memcached driver
GD (php-gd) – GD image library extension
XML (php-xml) –XML extension
MBString (php-mbstring) – Multi-byte string processing extension
MCrypt (php-mcrypt) – MCrypt library extension

4-1. Use the command under Fedora 17/16/15/14:
[plain]
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

4-1. Commands used under CentOS 6.2/5.8 and Red Hat (RHEL) 6.2/5.8:
[plain]
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

STEP5. Stop the httpd (Apache) server and start the Nginx HTTP service and PHP-FPM
5-1. Stop httpd
[plain]
/etc/init.d/httpd stop
## OR ##
service httpd stop

5-2. Start Nginx
[plain]
/etc/init.d/nginx start
## OR ##
service nginx start
5-3. Start PHP_FPM
[plain]
/etc/init.d/php-fpm start
## OR ##
service php-fpm start

【Translator's Note】
At this point, follow step 9 to configure the firewall to open port 80. Open the browser and enter http://localhost to see the nginx default page.

STEP6. Set Nginx&PHP-FPM to start automatically at boot (disable Httpd from starting automatically)
6-1. Disable Httpd from starting
[plain]
chkconfig httpd off

5-2 Set Nginx&PHP-FPM to start automatically at boot
[html]
chkconfig --add nginx
chkconfig --levels 235 nginx on
chkconfig --add php-fpm
chkconfig --levels 235 php-fpm on


STEP7. Configure Nginx&PHP-FPM
7-1. Create website directory
Here I use testsite.local as the site directory. In practical applications, we often use the corresponding domain name as the site directory, such as www.csdn.com
[plain] view plaincopy
##Create public_html directory and logs log directory
mkdir -p /srv/www/testsite.local/public_html
mkdir /srv/www/testsite.local/logs
##Change the owner of the above directory to nginx
chown -R nginx:nginx /srv/www/testsite.local
Configure the log directory
[plain]
mkdir -p /srv/www/testsite.local/public_html
mkdir -p /var/log/nginx/testsite.local
chown -R nginx:nginx /srv/www/testsite.local
chown -R nginx:nginx /var/log/nginx
7-2. Create and configure nginx virtual host directory
[plain]
mkdir /etc/nginx/sites-available
mkdir /etc/nginx/sites-enabled
Open the /etc/nginx/nginx.conf file and add the following code after the include /etc/nginx/conf.d/*.conf" line (within the http block)
[plain]
include /etc/nginx/sites-enabled/*;
7-3. Configure nginx virtual host for the site testsite.local
Add the testsite.local file in the /etc/nginx/sites-available/ directory with the following content.
[plain]
server {
Server_name testsite.local;
access_log /srv/www/testsite.local/logs/access.log;
​ error_log /srv/www/testsite.local/logs/error.log;
Root /srv/www/testsite.local/public_html;

Location / {
index index.html index.htm index.php;
}  

location ~ .php$ {
include /etc/nginx/fastcgi_params;
         fastcgi_pass 127.0.0.1:9000;
          fastcgi_index index.php;
         fastcgi_param SCRIPT_FILENAME /srv/www/testsite.local/public_html$fastcgi_script_name;
}  
}
Link testsite.local to /etc/nginx/sites-enabled
[plain]
cd /etc/nginx/sites-enabled/
ln -s /etc/nginx/sites-available/testsite.local
service nginx restart
Add the "domain name" testsite.local to /etc/hosts
Modify the /etc/hosts file
[plain]
cd /etc/nginx/sites-enabled/
127.0.0.1 localhost.localdomain localhost testsite.local

STEP8. Test
Create the index.php file under /srv/www/testsite.local/public_html/ with the following content
[plain]
cd /etc/nginx/sites-enabled/
phpinfo();
?>
Open your browser and visit http://testsite.local/

Install Nginx/PHP-FPM environment on CentOS/RHEL6.2/5.8, Fedora17/16_PHP tutorial


STEP9. Firewall iptables configuration
Open port 80 for Nginx Web Server, modify the /etc/sysconfig/iptables file and add the following content
[plain]
cd /etc/nginx/sites-enabled/
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
Restart iptables firewall
[plain]
cd /etc/nginx/sites-enabled/
service iptables restart
## OR ##
/etc/init.d/iptables restart
Author: uuleaf

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478098.htmlTechArticleWhat is PHP-FPM PHP-FPM is a PHP FastCGI manager, which is only used for PHP, PHP- FPM is actually a patch of the PHP source code, designed to integrate FastCGI process management into the PHP package. It must be...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.

CakePHP Logging CakePHP Logging Sep 10, 2024 pm 05:26 PM

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide

See all articles