Nginx + php compilation and Installation

Source: Internet
Author: User
Tags install openssl mcrypt

1. System Environment

Centos6.3 _ x64

Nginx: 1.1.5

Php: php-5.4.14

######################################## ####

2. Environment Installation

# Software packages required by yum to install the system environment

Yum-y install yum-fastestmirror ntp

Yum-y install patch make flex bison tar

Yum-y install libtool-libs kernel-devel

Yum-y install libjpeg-devel libpng-devel

Yum-y install libtiff-devel gettext-devel

Yum-y install libxml2 libxml2-devel zlib-devel net-snmp

Yum-y install file glib2 glib2-devel bzip2 diff * openldap-devel

Yum-y install ncurses-devel curl-devel e2fsprogs

Yum-y install e2fsprogs-devel krb5 krb5-devel libidn-devel

Yum-y install openssl-devel vim-minimal unzip

# Install PHP to support the GD library module

Yum-y install freetype-devel png jpeg zlib gd php-gd *

# Install the PHP 5. * component

Yum-y install libiconv libevent mhash mcrypt

# System library files required for installing MYDSQL

Yum install-y gcc-c ++ gcc-g77 autoconf automake fiex * ncurses-devel libmcrypt * libtool-ltdl-devel *

# Install NGINX Components

Yum-y install pcre *

####################################

3. install PHP

Php and nginx are integrated through php-FastCGI

FastCGI is a scalable and fast interface for communication between web server and scripting languages. It is supported by many scripting languages, including most popular php web servers that support FastCGI.

Under normal circumstances, nginx and php are completely unknown. we integrate the two through php-fastcgi.

For versions earlier than php5.3.0, php-FastCGI must be installed separately. However, after that, php-FastCGI is integrated into the php source code package and does not have to be installed separately. Here I use php5.3.8, which has built-in php-fpm. It is enabled during compilation and the php-cgi file exists after compilation.

Note: PHP compilation supports the php-fpm function, so it does not support apache's apxs module function. Otherwise, an error is returned.


Tar jxf php-5.4.14.tar.bz2 & cd php-5.4.14

./configure '--prefix=/usr/local/php' '--with-iconv' '--with-mysql' '--with-mysqli' '--with-gd' '--with-zlib' '--with-jpeg-dir=/usr/lib64' '--with-png-dir' '--with-freetype-dir=/usr/lib64' '--with-curl=/usr/bin' '--with-openssl' '--with-openssl-dir=/usr' '--with-xsl=/usr' '--with-xmlrpc' '--enable-exif' '--enable-cli' '--enable-calendar' '--with-mhash' '--enable-mbstring' '--enable-mbregex' '--enable-soap' '--enable-sockets' '--enable-sysvmsg' '--enable-sysvsem' '--enable-sysvshm' '--enable-zip' '--enable-ftp' '--with-pear' '--disable-debug' '--with-bz2' '--with-mcrypt' '--with-mhash' --disable-cgi --enable-bcmath --enable-libxml --with-libxml-dir --with-gettext --enable-pcntl --enable-inline-optimization --disable-ipv6 --enable-fpm --enable-ftp --enable-gd-native-ttf

Make & make install

Cp php-5.4.14/php. ini-production/usr/local/php/lib/php. ini

# Cd/usr/local/php/etc/# Switch to the configuration file directory under the installation directory

# Cp php-fpm.conf.default php-fpm.conf

# Vi php-fpm.conf

Enable the following lines to remove the semicolon (;)

pid = run/php-fpm.pid  error_log = log/php-fpm.log  log_level = notice  listen = 127.0.0.1:9000  listen.allowed_clients = 127.0.0.1  pm = dynamic  pm.max_children = 50  pm.start_servers = 5  pm.min_spare_servers = 5  pm.max_spare_servers = 35  pm.max_requests = 500  env[HOSTNAME] = $HOSTNAME  env[PATH] = /usr/local/bin:/usr/bin:/bin  env[TMP] = /tmp  env[TMPDIR] = /tmp  env[TEMP] = /tmp

Wq save and exit

#/Usr/local/php/sbin/php-fpm start PHP)

# Netstat-antpl (if you see port 9000, The PHP-FPM is configured successfully)

######################################## ###################

4. Install nginx

Http://nginx.org/download/nginx-1.1.5.tar.gz wget-c

Tar zxf nginx-1.1.5.tar.gz & cd nginx-1.1.5

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre --http-client-body-temp-path=/tmp/nginx_client --http-proxy-temp-path=/tmp/nginx/proxy --http-fastcgi-temp-path=/tmp/nginx/fastcgi --http-uwsgi-temp-path=/tmp/nginx/uwsgi --http-scgi-temp-path=/tmp/nginx/scgi

Make & make install

NGINX Configuration File Settings: This configuration only associates NGX with PHP.

/Usr/local/nginx/conf/nginx. conf

User nginx; nginx users need to create a new one and comment out OK) worker_processes 8; # error_log logs/error. log; // The default value is/usr/local/nginx/logs/error. logerror_log/var/log/5aixue_error.log; // specify the log Path # error_log logs/error. log notice; # error_log logs/error. log info; pid logs/nginx. pid; events {worker_connections 2048;} http {include mime. types; default_type application/octet-stream; charset UTF-8; // set the character set sendfile on; keepalive_timeo Ut 65; server {listen 80; server_name test1.5aixue.com; // The website domain name root/home/aixue/public_html/; // The website path index. php index.html index.htm; // index. php must be put in front # pass the PHP scripts to FastCGI server listening on 127.0.0.1: 9000 location ~ \. Php $ {# root html; fastcgi_pass 127.0.0.1: 9000; fastcgi_index index. php; fastcgi_param SCRIPT_FILENAME/scripts $ fastcgi_script_name; # include fastcgi_params; include fastcgi. conf;} location/{if (! -E $ request_filename) {rewrite ^/(. *) $/index. php last ;}}}}

5. test and start nginx

Mkdir-p/tmp/nginx/proxy

Cd/usr/local/nginx/sbin

./Nginx-t Detection

Nginx: the configuration file/usr/local/nginx/conf/nginx. conf syntax is OK

Nginx: configuration file/usr/local/nginx/conf/nginx. conf test is successful

./Nginx start nginx


Compile the Index. php file in/home/aixue/public_html /.

<?

Phpinfo ();

?>

Open the browser http: // IP/index. php. You can browse and the installation is successful.


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.