


Install Nginx/PHP-FPM environment on CentOS/RHEL6.2/5.8, Fedora17/16_PHP tutorial
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/
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

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver CS6
Visual web development tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment