Linux environment source installation nginx, and build PHP environment

Source: Internet
Author: User
Tags fpm openssl

This is my first time in the Linux environment source installation nginx, build PHP environment, the process of reference http://www.nginx.cn/install and http://php.net/manual/zh/ install.unix.nginx.php Two official documents to install, or encountered some problems, through this installation, to learn more about PHP and nginx working principle and basic configuration.

Install the Ubuntu Platform compilation Environment

Apt-get Install Build-essential
Apt-get Install Libtool

1. Selected Source Directory
Can be any directory, this article is selected/USR/LOCAL/SRC

Cd/usr/local/src

2. Install Pcre Library
Cd/usr/local/src
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz
TAR-ZXVF pcre-8.39.tar.gz
CD pcre-8.39
./configure
Make
Make install

3. Install Zlib Library
http://zlib.net/zlib-1.2.11.tar.gz Download the latest zlib source package and download the build and install Zlib package using the following command:

Cd/usr/local/src
wget http://zlib.net/zlib-1.2.11.tar.gz
TAR-ZXVF zlib-1.2.11.tar.gz
CD zlib-1.2.11
./configure
Make
Make install

4. Install SSL (some VPS default does not install SSL)

Cd/usr/local/src
wget https://www.openssl.org/source/openssl-1.1.0e.tar.gz
TAR-ZXVF openssl-1.1.0e.tar.gz

5 Installation Nginx

Cd/usr/local/src
wget http://nginx.org/download/nginx-1.4.2.tar.gz
TAR-ZXVF nginx-1.4.2.tar.gz
CD nginx-1.4.2
./configure–with-http_ssl_module \
–with-pcre=/usr/local/src/pcre-8.39 \
–with-zlib=/usr/local/src/zlib-1.2.11 \
–with-openssl=/usr/local/src/openssl-1.1.0e
Make
Make install

6 Ensure the system's 80 ports are not occupied by other programs
Netstat-ano|grep 80

7 Start

Sudo/usr/local/nginx/sbin/nginx start

Sudo/usr/local/nginx/sbin/nginx-s Stop Stops

Open the browser to enter the local Web site, or localhost,127.0.0.1 can access

Nginx installation process without encountering errors, the installation process to see if there are error prompts, updated according to the error, overwrite, or in the installation of the required dependencies.

8.nginx is generally the request to send fastcgi management process processing, FASCGI management process Select the CGI subprocess processing results and return to be nginx. PHP-FPM is a PHP fastcgi manager, just for PHP

wget http://cn.php.net/distributions/php-5.6.30.tar.gz
Tar zvxf php-5.6.30.tar.gz
CD php-5.6.30
/configure–enable-fpm–with-mysql///First install these two modules, later use in Add, just can learn Linux under the PHP expansion,
Make
sudo make install

9 Create the configuration file and copy it to the correct location.

CP Php.ini-development/usr/local/php/php.ini
Cp/usr/local/etc/php-fpm.conf.default/usr/local/etc/php-fpm.conf
CP Sapi/fpm/php-fpm/usr/local/bin

10 The caveat is that if the file does not exist, prevent Nginx from sending the request to the back-end PHP-FPM module to avoid attacks from malicious script injection
Set the configuration item cgi.fix_pathinfo in the php.ini file to 0
Open php.ini:
Vim/usr/local/php/php.ini
Navigate to cgi.fix_pathinfo= and modify it as follows:
Cgi.fix_pathinfo=0

11 Before starting the service, you need to modify the php-fpm.conf configuration file to ensure that the PHP-FPM module runs with the Www-data user and Www-data user group.
Vim/usr/local/etc/php-fpm.conf
Locate and modify the following:
user = Www-data
Group = Www-data

Start the PHP-FPM service:

/usr/local/bin/php-fpm

12 Configure Nginx to support PHP applications:

Vim/usr/local/nginx/conf/nginx.conf
Modify the default location block so that it supports the. php File:

Location/{
root HTML;
Index index.php index.html index.htm;
}
The next configuration is to ensure that requests for. php files are routed to the back-end PHP-FPM module, uncomment the default PHP configuration block, and modify to the following:

Location ~* \.php$ {
Fastcgi_index index.php;
Fastcgi_pass 127.0.0.1:9000;
Include Fastcgi_params;
Fastcgi_param script_filename $document _root$fastcgi_script_name;//I was trapped in this place once, always prompted file not found, to replace the SCRIPT with $ Document_root
Fastcgi_param script_name $fastcgi _script_name; Add this line
}

13 Restart Nginx

Sudo/usr/local/nginx/sbin/nginx-s stop
Sudo/usr/local/nginx/sbin/nginx

14 Create a test file,

<?php phpinfo ();?>

PS: In 12 steps must be nginx parsing PHP comments removed, the script replaced by $document_root,nginx to the PHP file to the back-end of the PHP-FPM module (is a PHP fastcgi manager), The PHP-FPM module handles the request FASTCGI management process, the FASCGI management process chooses the CGI subprocess to process the result and returns to be Nginx, the file not found because the PHP-FPM process cannot find the Script_ FileName is configured to execute the. php file, PHP-FPM returns to the Nginx default 404 error prompt. Pay particular attention to the 12th step, some of the online forums and blogs into an absolute path, pure nonsense, this way can only access the specified directory of PHP files. Be sure to use $document_root. Installation process to pay attention to the error generated, or to rely on the package update, add, delete, and other operations, as a technical maniac, there is a certain cleanliness, always like to download the source from the official website installation.

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.