Nginx + PhP (5.4.14) installation and configuration (single-host version)

Source: Internet
Author: User
Tags sapi openldap
Document directory
  • 1.1 Problems
  • 1.2 compile and install

Environment:

System: centos 6.2 linux2.6

PHP: 5.4.14 (Latest Version)

Nginx: 1.3.16 (Latest Version)

1. install PHP

Install software and library files before installation
Yum install-y GCC gcc-C ++ make zlib-devel PCRE-devel libjpeg-devel libpng-devel FreeType-devel libxml2 libxml2-devel glibc-devel glib2 glib2-devel Bzip2 the bzip2-devel ncurses-devel curl-devel e2fsprogs e2fsprogs-devel
Krb5 krb5-devel OpenSSL-devel OpenLDAP openldap-devel nss_ldap openldap-clients openldap-servers

Some of them are not required. They must be LibPNG, JPEG, FreeType, and GD.

1.1 Problems

If we do not use the preceding command for one installation, the following problems will occur:

Error 1
Check for xml2-config path...
Configure: Error: xml2-config not found. Please check your libxml2 installation.

(Check the prompt to see if a lib library is not installed. first use the yum search name to check whether the name can be found. Find the name and then package the software package for development)
Solution
Yum install libxml2-devel.x86_64

Error 2
Checking for PKG-config.../usr/bin/PKG-config
Configure: Error: cannot find OpenSSL's <EVP. h>
This is SSL Not Installed
Solution
Yum install OpenSSL. x86_64 openssl-devel.x86_64-y

Error 3
Checking for Bzip2 in default path... not found
Configure: Error: Please reinstall the Bzip2 Distribution
This is not installed in Bzip2 Software Package
Solution
Yum install bzip2-devel.x86_64-y

Error 4
Configure: Error: Please reinstall the libcurl distribution-
Easy. h shoshould be in <curl-dir>/include/curl/
The curl and curl library files are not installed

Solution
Yum install libcurl. x86_64 libcurl-devel.x86_64-y

Error 5
Checking whether to enable JIS-mapped Japanese font support in GD... no
Checking for fabsf... yes
Checking for flograding... yes
Configure: Error: Invalid Lib. h not found

GD library Not Installed
Solution
Yum install libjpeg. x86_64 LibPNG. x86_64 FreeType. x86_64 libjpeg-devel.x86_64 libpng-devel.x86_64 freetype-devel.x86_64-y

Error 6
Checking for stdarg. H... (cached) Yes
Checking for mcrypt support... yes
Configure: Error: mcrypt. h not found. Please reinstall libmcrypt.
The libmcrypt library is not installed. If you cannot install it using Yun, You need to download a GZ package and compile and install it yourself.
Address: http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/
(Compile and install./configure -- piefix =/usr/local/libmcrypt make & make install)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~
If the error contains MySQL, MySQL-devel is not installed.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~

1.2 compile and install

Here the least-secure compilation aims to be run. If the graph is simplified, run the following command: OK

$ Yum install-y gcc-C ++ GCC make libxml2-devel libjpeg-devel libpng-devel

$/Configure -- enable-FastCGI -- enable-FPM
Note: For nginx + PhP integration, you must enable -- enable-FastCGI and -- enable-FPM during installation. The two options are described above. After execution, the system will prompt that -- enable-FastCGI is an unknown option.

$ Make & make install

Appears
Generating files configure: Creating./config. Status creating main/internal_functions.c creating main/internal_functions_cli.c
+ -------------------------------------------------------------------- +
| License: |

| This software is subject to the PHP license, available in this |
| Distribution in the file license. By continuing this installation |
| Process, you are bound by the terms of this License Agreement. |

| If you do not agree with the terms of this License, you must abort |
| The installation process at this point. |

+ -------------------------------------------------------------------- +
Thank you for using PHP.
Onfig. Status: Creating php5.spec
Config. Status: Creating main/build-defs.h
Config. Status: Creating scripts/phpize
Config. Status: Creating scripts/Man1/phpize.1
Config. Status: Creating scripts/PHP-config
Config. Status: Creating scripts/Man1/php-config.1
Config. Status: Creating SAPI/CLI/php.1
Config. Status: Creating SAPI/FPM/php-fpm.conf
Config. Status: Creating SAPI/FPM/init. d. php-FPM
Config. Status: Creating SAPI/FPM/php-fpm.8
Config. Status: Creating SAPI/FPM/status.html
Config. Status: Creating main/php_config.h
Config. Status: executing default commands

Indicates that PHP installation is successful.

2. Install nginx

You can upload the latest version, http://nginx.org/

Decompress the package and install it by default.

$./Configure & make install

3. modify the configuration file

After make is complete, go to the PHP decompress directory to find the php. ini-production file copied to/usr/local/etc/and change the file name to PhP. ini.

$ Cp php. ini-production/usr/local/etc/PHP. ini

Copy/usr/local/etc/php-fpm.conf.default and rename the php-fpm.conf.default

$ CP/usr/local/etc/php-fpm.conf.default/usr/local/etc/php-fpm.conf


3. 1. Modify/usr/local/nginx/CONF/nginx. conf

# Proxy the PHP scripts to Apache listening on 127.0.0.1: 80
#
# Location ~ \. Php $ {
# Proxy_pass http: // 127.0.0.1;
#}

# Pass the PHP scripts to FastCGI server listening on Fig: 9000
#
Location ~ \. Php $ {
Root HTML;
Fastcgi_pass 127.0.0.1: 9000; // listen to port 9000 of the local PHP-FPM
Fastcgi_index index. php;
Fastcgi_param script_filename/Usr/local/nginx/html/$ Fastcgi_script_name; # the path of the PHP file to be laid down
Include fastcgi_params;
}

# Deny access to. htaccess files, if Apache's document root
# Concurs with nginx's one

3. Modify the/usr/local/etc/php-fpm.conf File

**************************************** *****************

  1. [Global]
  2. ; PID File
  3. ; Note: the default prefix is/usr/local/webserver/PHP/var
  4. ; Default value: None
  5. PID = run/php-fpm.pid

  6. ; Error Log File
  7. ; If it's set to "syslog", log is sent to syslogd instead of being written
  8. ; In a local file.

**************************************** **************************************** ***************************

; Specific port;
'/Path/to/Unix/socket'-To listen on a UNIX socket.
; Note: this value is mandatory.
Listen = 127.0.0.1: 9000 # You do not need to change it here. However, you need to use nginx as a proxy.

; Set listen (2) backlog.
; Default value: 128 (-1 on FreeBSD and OpenBSD)

**************************************** **************************************** **************************************** *


The red part above is the modified part, and the rest remains unchanged.

4. Run the test

Run php-FPM and nginx

$/Usr/local/sbin/PHP-FPM

$/Usr/local/nginx/sbin/nginx


Find the HTML directory (the default website directory) under the installation directory of the nginx, and create an index. php

Content:

<? PHP
Echo phpinfo ();
?>

Finally, visit the web page on another machine to view the PHP page information.

Now the success

Configuration reference:

Install nginx 1.2.0 + PhP 5.4.3 (FastCGI) + MySQL 5.5.24 http://blog.chinaunix.net/uid-20556054-id-3226209.html

How to solve the problem when compiling and installing PHP. http://www.cnblogs.com/z-ping/archive/2012/06/18/2553929.html

Centos + nginx + PHP + MySQL detailed http://www.jb51.net/article/26597.htm Configuration

Nginx 0.8.x + PhP 5.2.13 (FastCGI) build a web server http://blog.s135.com/nginx_php_v6/ that is 10 times better than Apache

Related Article

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.