Nginx+php-fpm+mysql+redis source code Compilation Installation Guide

Source: Internet
Author: User
Tags diff fpm install php openssl php and mysql nginx server nginx reverse proxy

Description: This tutorial mainly consists of the following three sections:

1. Source code Compiler installation Nginx

2. Source code Compilation install PHP and MySQL, Redis extension module

3. Configure the Virtual host

Download links are available in the installation package program, Welcome to use

Operating environment and preconditions: Ubuntu 12.04 LTS installed g++ compilation environment

All source program paths are located in: [Email Protected]:/home/shihai/desktop/nginx folder, as shown:

The program installation path is located under:/usr/local folder

Part I: Installing Nginx

Install the dependent Library Pcre Library, zlib library, SSL library before installing Nginx

Install Pcre Library--for rewrite

TAR–ZXVF pcre-8.21.tar.gz

CD pcre-8.21

./configure--prefix=/usr/local/pcre-8.21

Make

Make install

Install the Zlib Library--for gzip compression

TAR–ZXVF zlib-1.2.8.tar.gz

CD zlib-1.2.8

./configure--prefix=/usr/local/zlib-1.2.8

Make

Make install

Install SSL Library--Support SSL encryption

TAR-ZXVF openssl-1.0.1c.tar.gz

CD openssl-1.0.1c

./config--prefix=/usr/local/openssl-1.0.1

Make

Make install

Installing the nginx--Server Software

TAR-ZXVF nginx-1.2.8.tar.gz

CD nginx-1.2.8

./configure--prefix=/usr/local/nginx-1.2.8 \

--with-pcre=. /pcre-8.21/\

--with-zlib=. /zlib-1.2.8/

Make

Make install

Setting Nginx-Initiated configuration files

/usr/local/nginx-1.2.8/sbin#./nginx-c/usr/local/nginx-1.2.8/conf/nginx.conf

/usr/local/nginx-1.2.8/sbin#./nginx-s Reload

View Nginx Process

Ps–ef|grep Nginx

Open localhost

When you see the content shown, the Nginx server has been successfully installed

Part II: Installation of PHP and MySQL, Redis expansion module installation ncurses--install MySQL pre-conditions:

TAR-ZXVF ncurses-5.4.tar.gz

CD ncurses-5.4

./configure

Make

Make install

Install mysql--here use is source package compiled installation

TAR-ZXVF mysql-5.1.73.tar.gz

CD mysql-5.1.73

./configure--prefix=/usr/local/mysql-5.1.73

Make

Make install

Installing the Curl Library--for Curl requests

TAR-ZXVF curl-7.39.0.tar.gz

./configure--prefix=/usr/local/curl-7.39.0

Make

Make install

Install PHP

TAR-ZXVF php-5.2.14.tar.gz

Gunzip php-5.2.14-fpm-0.5.14.diff.gz

Patch-d Php-5.2.14-p1 < Php-5.2.14-fpm-0.5.14.diff

CD php-5.2.14

./configure--prefix=/usr/local/php-5.2.14\

--ENABLE-FASTCGI \

--ENABLE-FPM \

--enable-sockets \

--enable-mbstring \

--with-mysql=/usr/local/mysql-5.1.73 \

--with-mysqli=/usr/local/mysql-5.1.73/bin/mysql_config\

--with-pdo-mysql=/usr/local/mysql-5.1.73 \

--with-curl=/usr/local/curl-7.39.0 \

--with-openssl=/usr/local/openssl-1.0.1 \

--with-mcrypt

Make

Make install

Start PHP-FPM using the following command:

/usr/local/php-5.2.14/sbin#./php-fpm Start

When starting php-fpm startingphp_fpm Dec 15:27:32.502790 [ERROR] fpm_unix_conf_wp (), line 124:pleasespecify user and group Other than root, pool ' default '

Workaround: Go to directory:/usr/local/php-5.2.14/etc only need to modify php-fpm.conf

Unix User of processes <!--<value name= "user" >nobody</value>-

Unix Group of processes <!--<value name= "group" >nobody</value>-

Will <! ––> can be removed. As for User/group according to the actual situation changes (WWW). Restart/usr/local/php-5.2.14/sbin#./php-fpm restart was successful.

To install the Redis expansion module:

Unzip Phpredis-master.zip

exportpath=/usr/local/php-5.2.14/bin/: $PATH

Cp-r Phpredis-master php-5.2.14/ext/

CD Php-5.2.14/ext/phpredis-master

Phpize

./configure--with-php-config=/usr/local/php-5.2.14/bin/php-config

Make

Make install

Extension Library Path:/usr/local/php-5.2.14/lib/php/extensions/no-debug-non-zts-20060613/

Under the PHP extension library path, you can find the compiled Redis extension library file redis.so

Open the php.ini file under Path/usr/local/php-5.2.14/lib/php.ini, using the following command:

Vim php.ini

File content Quick Find (press "N" to find the next matching location), use the following command:

:? extension

After locating the specified location, insert the following:

Extension = redis.so

PHP will automatically load the redis.so file into the extension library path

If you do not find the php.ini file, you can search the file in full, using the following command:

Find/-name php.ini

The search results show that the/etc/php5/cli/php.ini file exists under this path and is then copied to/usr/local/php-5.2.14/lib using the following command:

/usr/local/php-5.2.14/lib# Cp/etc/php5/cli/php.ini php.ini

You need to restart PHP-FPM here to take effect, using the following command:

/usr/local/php-5.2.14/sbin#./php-fpmrestart

Part III: Configuring NGINX Virtual Host

Create a new virtual host configuration file directory

/usr/local/nginx-1.2.8# mkdir vhosts

CD vhosts

Touch scott.qq.com.conf

Vim scottshi.qq.com.conf

Enter the following to configure a custom virtual host:

server {

Listen 8001;/* Listening port number */

server_name scott.qq.com;/* domain Name */

access_log/usr/local/nginxweb/htdocs/access.log;/* Site Access Log */

Location/{

root/usr/local/nginxweb/htdocs/;/* Page File directory */

Index index.php index.html index.htm;

}

Error_page 502 503 504/50x.html;/* Server error page */

Location =/50x.html {

root HTML;

}

# Pass the PHP scripts to FastCGI serverlistening on 127.0.0.1:9000

Location ~ \.php$ {

Fastcgi_pass 127.0.0.1:9000; /*nginx Forwarding Request Address */

Fastcgi_index index.php;

Fastcgi_param script_filename/usr/local/nginxweb/htdocs/$fastcgi _script_name;

Include Fastcgi_params;

}

Location ~/\.ht {

Deny all;

}

}

After saving exit, enter Nginx configuration file nginx.conf

/usr/local/nginx-1.2.8/conf# Vim nginx.conf

In parallel to the default server level and within the HTTP hierarchy, add the following to make the custom virtual host effective:

include/usr/local/nginx-1.2.8/vhosts/*;

After saving the exit, restart the Nginx server and reload the configuration file using the following command:

/usr/local/nginx-1.2.8/sbin#./nginx–s Reload

To write a PHP test page:

Enter the directory/usr/local/nginxweb/htdocs/, create a new test.php file, and enter the test.php page content:

<?php

Phpinfo ();

?>

Save exit

Use the browser to access the following address:

scott.qq.com:8001/test.php

This page will show instructions for configuring PHP with various function modules including fastcgi, MySQL, curl, redis, etc.

    • Related articles recommended:
    • Nginx's Configure Chinese description
    • Nginx Reverse proxy Nginx
    • Nginx for simple load balancing
    • This article from: Hobby Linux Technology Network
    • This article links:

Nginx+php-fpm+mysql+redis source code Compilation Installation Guide

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.