Deployment configuration and validation for the Linux Background Server development environment (NGINX+APACHE+PHP-FPM+FASTCGI (c + +)

Source: Internet
Author: User
Tags fpm phpinfo


Linux Background Server development environment Deployment configuration

Introduction
Background
As the Internet business continues to grow. The development environment is becoming more complex, and the configuration document is specially crafted to facilitate a unified server-side development deployment environment.


Using the Software
CentOS 6.3 (Linux version 2.6.32-279.el6.x86_64)
GCC (gcc) 4.4.6 20120305 (Red Hat 4.4.6-4)
This configuration
Nginx 1.5.8
Apache 2.4.7
PHP 5.3.26

Objective
Constructs a web front-end technology architecture. The deployment structure technology of the Web front end is complete.
The full description of the Nginx + Apache + FASTCGI (c + +) and Nginx + php-fpm +fastcgi (PHP) two FASTCGI architecture.
Nginx Installation
Software preparation
Http://nginx.org/en/download.html
Official website Download version number, nginx-1.5.8.tar.gz

http://www.pcre.org/
Official website Download pcre-8.34.tar.gz

http://zlib.net/
Official website Download zlib-1.2.5.tar.gz

http://www.openssl.org/source/
Official website Download openssl-1.0.1d.tar.gz

Working folder Preparation
Set up the working folder Nginx_make, and put the downloaded files in the folder below.
Unzip all the. tar.gz files, and a corresponding folder appears.
Installing Pcre
CD pcre-8.34
./configure--prefix=/usr/local/pcre-8.34
Make
Make install
Installing zlib
Suppose the zlib is already installed locally. Can not be installed.


The installation steps are similar to the above, but it is strongly recommended that you specify the folder and the installation version number when compiling the installation.
Installing OpenSSL
Assuming that you have installed OpenSSL locally, you can not install it.
The installation steps are similar to the above, but it is strongly recommended that you specify the folder and the installation version number when compiling the installation
Installing Nginx
CD nginx-1.5.8
./configure--user=root--group=root--prefix=/usr/local/nginx-1.5.8--pid-path=/usr/local/nginx-1.5.8/nginx.pid-- Error-log-path=/data/logs/nginx/err/nginx--http-log-path=/data/logs/nginx/acc/nginx--with-http_gzip_static_ Module--with-poll_module--without-mail_pop3_module--without-mail_imap_module--without-mail_smtp_module-- With-pcre=. /pcre-8.34--with-cc-opt=-o2
Make
Make install

Apache Installation
Software preparation
http://httpd.apache.org/
Official website Download version number, httpd-2.4.7.tar.gz

http://apr.apache.org/
Official website Download apr-1.5.0.tar.gz

http://apr.apache.org/
Official website Download apr-util-1.5.3.tar.gz

http://www.pcre.org/
Official website Download pcre-8.34.tar.gz
Working folder Preparation
Set up the working folder Apache_make, and put the downloaded files in the folder below.
Unzip all the. tar.gz files, and a corresponding folder appears.
Install Apr
CD apr-1.5.0
./configure--prefix=/usr/local/apr-1.5.0
Make
Make install
Installing Apr-util
CD apr-1.5.0
./configure--prefix=/usr/local/apr-util-1.5.3/--with-apr=/usr/local/apr-1.5.3/bin/apr-1-config
Installing Pcre
CD pcre-8.34
./configure--prefix=/usr/local/pcre-8.34/--with-apr=/usr/local/apr-1.5.3/bin/apr-1-config
The PCRE has been installed.


Installing Apache
CD httpd-2.4.7
./configure--prefix=/usr/local/apache2.4.7--with-pcre=/usr/local/pcre-8.34/--with-apr=/usr/local/apr-1.5.0-- with-apr-util=/usr/local/apr-util-1.5.3--enable-so--with-mpm=worker--disable-ssl--enable-cgid
Make
Make install

PHP Installation
Software preparation
http://www.php.net/releases/
Official website Download version number, php-5.3.26.tar.gz
Working folder Preparation
Set up the working folder Php_make, and put the downloaded files in the folder below.
Unzip all the. tar.gz files. A corresponding folder appears.


Construction libphp5.so
Compile PHP, construct libphp5.so, and use it for Apache parsing PHP.
CD php-5.3.26
Make clean;
./configure--prefix=/usr/local/php-5.3.26-with-apxs2=/usr/local/apache2.4.7/bin/apxs--with-curl-- With-curlwrappers
Make
Make install
Installing PHP-FPM
Compile PHP, support PHP-FPM and sockets, and enable the Curl module for Nginx to run PHP in FASTCGI mode.

CD php-5.3.26
Make clean;
./configure--prefix=/usr/local/php-5.3.26--enable-fpm--enable-sockets--with-curl--with-curlwrappers
Make
Make install

Install PHP
CD php-5.3.26
Make install
PHP.ini Installation
CD php-5.3.26
CP Php.ini-development/usr/local/php-5.3.26/lib/php.ini
NGINX+PHP-FPM Configuration
Start PHP-FPM
/usr/local/php-5.3.26/sbin/php-fpm-y/usr/local/php-5.3.26/etc/php-fpm.conf-c/usr/local/php-5.3.26/lib/php.ini
Configure nginx.conf
Change the/usr/local/nginx-1.5.8/conf/nginx.conf.
Listen 8090;
CharSet Utf-8;

Location ~ \.php$ {
/usr/local/web_umsa/
Fastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
#FASTCGI_param script_filename $document _root$fastcgi_script_name;
Include Fastcgi_params;
}

Configure Fastcgi_params
Change the/usr/local/nginx-1.5.8/conf/fastcgi_params.



# PHP only, required if PHP is built with--enable-force-cgi-redirect
Fastcgi_param Redirect_status 200;
Fastcgi_param script_filename $document _root$fastcgi_script_name;

Test phpinfo.php
Create a PHP test file as follows.



cat/usr/local/web_umsa/phpinfo.php
<?php
Echo Phpinfo ();
?>
Verifying fastcgi mode PHP
TCPDUMP-ILO-XAVS0 Port 9000
Grab the bag and then run the browser
http://127.0.0.1:8090/phpinfo.php
The browser outputs the installation configuration information for PHP.


Can see the grab bag. 9000 port has data sent to confirm that the transmission protocol is the FASTCGI protocol.


Apache Configuration
Php5_module Module Boot
Enable the/usr/local/apache2.4.7/conf/httpd.conf inside.
LoadModule Php5_module modules/libphp5.so
Configure Directory/
Change the/usr/local/apache2.4.7/conf/httpd.conf inside.

<directory/>
Options FollowSymLinks
AllowOverride None
Order Deny,allow
Allow from all
</Directory>

Configure DocumentRoot
Change the/usr/local/apache2.4.7/conf/httpd.conf inside.

DocumentRoot "/usr/local/web_umsa"
Configuring <ifmodule alias_module>
Change the/usr/local/apache2.4.7/conf/httpd.conf inside.



#支持cgi
scriptalias/cgi-bin/"/usr/local/web_umsa/cgi-bin/"
#支持 FASTCGI
scriptalias/fcg-bin/"/usr/local/web_umsa/fcgi-bin/"

Configuring <ifmodule mime_module>
Change the/usr/local/apache2.4.7/conf/httpd.conf inside.



AddType application/x-httpd-php. php phtml. PhP3. Inc
AddType application/x-httpd-php-source. Phps
Configure <directory "/usr/local/web_umsa/cgi-bin/";
Change/usr/local/apache2.4.7/conf/httpd.conf inside.

<directory "/usr/local/web_umsa/cgi-bin/"
    AddHandler cgi-script. CGI. UMS
    Options followsymlinks
    allowoverride all
    Order deny,allow
    allow from all
    Options +execcgi
</directory>

Launch Apache
/usr/local/apache2.4.7/bin/apachectl start

Verify Apache
http://127.0.0.1/phpinfo.php
HTTP://127.0.0.1/

Two visitors can come out and prove the installation is successful.



APACHE-FASTCGI (c + +) configuration
Mod_fcgid loading
File download
Official website Http://httpd.apache.org/mod_fcgid/Download
Get File mod_fcgid-2.3.9.tar.gz

Compiling the installation
Extract the mod_fcgid-2.3.9.tar.gz files to Apache original code folder httpd-2.4.7, get the folder
mod_fcgid-2.3.9, the complete structure should be httpd-2.4.7/mod_fcgid-2.3.9.
Run the Apache command: /bin/apachectl-k Restart, the httpd service up.
environment variable Settings APXS, set to see effects
# echo $APXS
/usr/local/apache2.4.7/bin/apxs
The/USR/LOCAL/APACHE2.4.7/BIN/APXS is the installation folder for Apache just now.
Run the following folder
./configure.apxs;make;make Install
View installation Results
# grep "Mod_fcgid.so"/usr/local/apache2.4.7/conf/httpd.conf
LoadModule Fcgid_module modules/mod_fcgid.so
You can see that the Mod_fcgid module is enabled.


Configuring FASTCGI Support
Configure <directory "/usr/local/web_umsa/fcgi-bin/" >
Change the/usr/local/apache2.4.7/conf/httpd.conf inside.




<directory "/usr/local/web_umsa/fcgi-bin" >
SetHandler Fcgid-script
AddHandler fcgid-script. fcgi. UMS
Options FollowSymLinks
AllowOverride All
Order Deny,allow
Allow from all
Options +execcgi
</Directory>

Restart Apache,.. /bin/apachectl-k restart.
Test-fastcgi (c + +)
Download FastCGI Library
The HTTP://WWW.FASTCGI.COM/DRUPAL/NODE/5 location of the official website http://www.FASTCGI.com/(current:download | docs | browse) downloads the development package for C/D + +.

The latest version number is 2.4.1 and gets the file fcgi-2.4.1-snap-0910052249.tar.gz.

Compiling libraries
Unzip the file. and go to the folder. Run legacy commands
./configure;make
See
Ranlib. LIBS/LIBFCGI.A
Indicates that the library is already in production. Other compilation errors are ignored (c + + error, version number is too old).


Run command LS libfcgi/.libs/-al, can query to LIBFCGI.A and libfcgi.so.0.0.0
Both the dynamic library and the static library are available.
Construction example
Go to Folder Exapmle, Run command (compile CGI and deploy to specified folder)
# gcc Echo.c-o echo.ums. /libfcgi/.libs/libfcgi.a
#cp echo.ums/usr/local/web_umsa/fcgi-bin/
View Effects
Http://127.0.0.1/fcgi-bin/echo.ums
To see the page output:
Request number 8, Process id:28256
The page is constantly refreshed and the process number does not change. Serial number is added continuously. At the same time, server side view discovery
# PS Aux|grep echo.ums
The process persists and the process number is consistent with the page.



Development environment Validation (internal validation only)
You need to configure Nginx forwarding to support. UMS parsing.

#TCP长连接, Nginx as Proxy
Upstream Tcp_keepalive {
Server 127.0.0.1:8080;
KeepAlive 256;
}

How to deploy fastcgi #以php-FPM implementation
Location ~ \.php$ {
Root/data/php_project;
Fastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
#fastcgi_param script_filename $document _root$fastcgi_script_name;
Include Fastcgi_params;
#记得改动 Fastcgi_params, add configuration
# PHP only, required if PHP is built with--enable-force-cgi-redirect
#fastcgi_param Redirect_status 200;
#fastcgi_param script_filename $document _root$fastcgi_script_name;
}


#以为. Fcgi,.ums end of request is forwarded to Tcpend using the HTTP protocol
Location ~* \. (fcgi|ums) $ {
#root Root
# Add the specified header header information to the backend server when it initiates the request
#proxy_set_header Host $http _host;
# Send Real IP to back-end server
#proxy_set_header X-real-ip $remote _addr;
# let backend such as PHP can directly through the variable to obtain the real IP
#proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
Proxy_pass Http://tcpend;
Proxy_http_version 1.1;
Proxy_set_header Connection "";
Proxy_set_header Host $http _host;
Proxy_set_header x-forwarded-by $server _addr: $server _port;
Proxy_set_header x-forwarded-for $remote _addr;
#proxy_set_header Connection "";
Proxy_connect_timeout 5s;
Proxy_read_timeout 10s;
Proxy_send_timeout 5s;
}



Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.

Deployment configuration and validation for the Linux Background Server development environment (NGINX+APACHE+PHP-FPM+FASTCGI (c + +)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.