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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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's Purpose: Building Dynamic Websites PHP's Purpose: Building Dynamic Websites Apr 15, 2025 am 12:18 AM

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

How to optimize CentOS HDFS configuration How to optimize CentOS HDFS configuration Apr 14, 2025 pm 07:15 PM

Improve HDFS performance on CentOS: A comprehensive optimization guide to optimize HDFS (Hadoop distributed file system) on CentOS requires comprehensive consideration of hardware, system configuration and network settings. This article provides a series of optimization strategies to help you improve HDFS performance. 1. Hardware upgrade and selection resource expansion: Increase the CPU, memory and storage capacity of the server as much as possible. High-performance hardware: adopts high-performance network cards and switches to improve network throughput. 2. System configuration fine-tuning kernel parameter adjustment: Modify /etc/sysctl.conf file to optimize kernel parameters such as TCP connection number, file handle number and memory management. For example, adjust TCP connection status and buffer size

PHP: Handling Databases and Server-Side Logic PHP: Handling Databases and Server-Side Logic Apr 15, 2025 am 12:15 AM

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

Centos stops maintenance 2024 Centos stops maintenance 2024 Apr 14, 2025 pm 08:39 PM

CentOS will be shut down in 2024 because its upstream distribution, RHEL 8, has been shut down. This shutdown will affect the CentOS 8 system, preventing it from continuing to receive updates. Users should plan for migration, and recommended options include CentOS Stream, AlmaLinux, and Rocky Linux to keep the system safe and stable.

PHP and Python: Code Examples and Comparison PHP and Python: Code Examples and Comparison Apr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

Centos shutdown command line Centos shutdown command line Apr 14, 2025 pm 09:12 PM

The CentOS shutdown command is shutdown, and the syntax is shutdown [Options] Time [Information]. Options include: -h Stop the system immediately; -P Turn off the power after shutdown; -r restart; -t Waiting time. Times can be specified as immediate (now), minutes ( minutes), or a specific time (hh:mm). Added information can be displayed in system messages.

How to check CentOS HDFS configuration How to check CentOS HDFS configuration Apr 14, 2025 pm 07:21 PM

Complete Guide to Checking HDFS Configuration in CentOS Systems This article will guide you how to effectively check the configuration and running status of HDFS on CentOS systems. The following steps will help you fully understand the setup and operation of HDFS. Verify Hadoop environment variable: First, make sure the Hadoop environment variable is set correctly. In the terminal, execute the following command to verify that Hadoop is installed and configured correctly: hadoopversion Check HDFS configuration file: The core configuration file of HDFS is located in the /etc/hadoop/conf/ directory, where core-site.xml and hdfs-site.xml are crucial. use

PHP: An Introduction to the Server-Side Scripting Language PHP: An Introduction to the Server-Side Scripting Language Apr 16, 2025 am 12:18 AM

PHP is a server-side scripting language used for dynamic web development and server-side applications. 1.PHP is an interpreted language that does not require compilation and is suitable for rapid development. 2. PHP code is embedded in HTML, making it easy to develop web pages. 3. PHP processes server-side logic, generates HTML output, and supports user interaction and data processing. 4. PHP can interact with the database, process form submission, and execute server-side tasks.

See all articles