Linux Background Server development environment deployment Configuration and Validation (nginx+apache+php-fpm+fastcgi)

Source: Internet
Author: User
Tags phpinfo
Linux Background Server development environment Deployment configuration

Introduction
Background
As the company's internet business continues to grow, the development environment becomes more complex, and the configuration document is specially crafted to facilitate a unified server-side development and 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 the Web front-end technology architecture, the Web front-end deployment structure technology completes completely.
Full description of Nginx + Apache + FASTCGI (c + +) and Nginx + php-fpm +fastcgi (PHP) two FASTCGI architectures.
Nginx Installation
Software preparation
Http://nginx.org/en/download.html
Official website download version, 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 Directory Preparation
Set up the working directory Nginx_make and put the downloaded files in this directory.
Unzip all the. tar.gz files, corresponding to the directory that appears.
Installing Pcre
CD pcre-8.34
./configure--prefix=/usr/local/pcre-8.34
Make
Make install
Installing zlib
If Zlib is already installed locally, you can not install it.
The installation steps are similar to the above, but it is strongly recommended that you specify the directory and the installation version when compiling the installation.
Installing OpenSSL
If you have already 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 directory and the installation version 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, 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 Directory Preparation
Set up the working directory Apache_make and put the downloaded files in this directory.
Unzip all the. tar.gz files, corresponding to the directory that 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
Refer to the Pcre already installed above.
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/
Make
Make install

PHP Installation
Software preparation
http://www.php.net/releases/
Official website download version, php-5.3.26.tar.gz
Working Directory Preparation
Set up the working directory Php_make and put the downloaded files in this directory.
Unzip all the. tar.gz files, corresponding to the directory that 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 parse 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
Modify 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
Modify 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
Build the PHP test file as below.

cat/usr/local/web_umsa/phpinfo.php
Echo Phpinfo ();
?>
Verifying fastcgi mode PHP
TCPDUMP-ILO-XAVS0 Port 9000
Grab the package, and then the browser executes
http://169.254.10.12:8090/phpinfo.php
The browser outputs the installation configuration information for PHP.
Can see grab packet, 9000 port has data send, can confirm, transmission protocol is 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/
Modify the inside of the/usr/local/apache2.4.7/conf/httpd.conf.


Options FollowSymLinks
AllowOverride None
Order Deny,allow
Allow from all


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

DocumentRoot "/usr/local/web_umsa"
Configuration
Modify the inside of the/usr/local/apache2.4.7/conf/httpd.conf.

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

Configuration
Modify the inside of the/usr/local/apache2.4.7/conf/httpd.conf.

AddType application/x-httpd-php. php. phtml. PhP3. Inc
AddType Application/x-httpd-php-source. Phps
Configuration
Modify the inside of the/usr/local/apache2.4.7/conf/httpd.conf.


AddHandler cgi-script. CGI. ums
Options FollowSymLinks
AllowOverride All
Order Deny,allow
Allow from all
Options +execcgi


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

Verify Apache
http://169.254.10.12/phpinfo.php
http://169.254.10.12/

Two visits are available to prove the installation was 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 directory httpd-2.4.7, get the directory
mod_fcgid-2.3.9, the complete structure should be httpd-2.4.7/mod_fcgid-2.3.9.
Execute Apache Command: /bin/apachectl-k Restart, the httpd service up.
Set environment variable APXS, set to view effects
# echo $APXS
/usr/local/apache2.4.7/bin/apxs
The/USR/LOCAL/APACHE2.4.7/BIN/APXS is the installation directory for Apache just now.
Execute the following directory
./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
Configuration
Modify the inside of the/usr/local/apache2.4.7/conf/httpd.conf.



SetHandler Fcgid-script
AddHandler fcgid-script. fcgi. ums
Options FollowSymLinks
AllowOverride All
Order Deny,allow
Allow from all
Options +execcgi


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 is 2.4.1, which gets the file fcgi-2.4.1-snap-0910052249.tar.gz.

Compiling libraries
Unzip the file and enter the directory. Execute traditional commands
./configure;make
See
Ranlib. LIBS/LIBFCGI.A
Indicates that the library has been produced, other compilation errors are ignored (c + + error, version is too old).
Execute command LS libfcgi/.libs/-al, can be queried to LIBFCGI.A and libfcgi.so.0.0.0
Both the dynamic library and the static library are available.
Construction examples
Enter directory exapmle, execute command (compile CGI and deploy to specified directory)
# gcc Echo.c-o echo.ums. /libfcgi/.libs/libfcgi.a
#cp echo.ums/usr/local/web_umsa/fcgi-bin/
View Effects
Http://169.254.10.12/fcgi-bin/echo.ums
You can see the page output:
Request number 8, Process id:28256
Constantly refresh the page, the process number is constant, the serial number is increasing. 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 back-end server when the request is initiated
#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;
}
  • 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.