Ubuntu 14.04 Installation Nginx+php+mysql

Source: Internet
Author: User
Tags install php

The previous period of tossing, quite a bit of trouble, the process found that many of the online information is older and outdated,
So here also simple to rearrange the process, to win a post to solve the problem.

Build Nginx, PHP, and MySQL environments based on the latest Ubuntu 14.04(September 2014)
All of the following command-line operations:

1, due to the need for a large number of permissions operations, temporary elevation of privileges, using the root account
sudo su

2, install the APT source management tool, add Nginx and PHP installation source
apt-get install python-software-properties
add-apt-repository ppa:nginx/stable
add-apt-repository ppa:ondrej/php5

3, update the system software
apt-get update

4. Install MySQL
apt-get install mysql-server
Note: During the installation process, you will be asked to enter the password for the root account of MySQL.

5. Installation of PHP and support for MySQL
apt-get install php5 php5-fpm php5-mysql php-apc

6, according to the actual needs, the optional installation of various types of PHP functional modules (specifically please Baidu)
apt-get install php-pear php5-dev php5-curl
apt-get install php5-gd php5-intl php5-imagick
apt-get install php5-imap php5-mcrypt php5-memcache
apt-get install php5-ming php5-ps php5-pspell
apt-get install php5-recode php5-snmp php5-sqlite
apt-get install php5-tidy php5-xmlrpc php5-xsl

7. Installing Nginx
apt-get install nginx

8. Configure PHP
vi /etc/php5/fpm/php.ini

Found it:;cgi.fix_pathinfo=1
Switchcgi.fix_pathinfo=0

9. Configure Nginx
mkdir /www
chmod 755 /www
Create a/www directory set to 755 permissions

vi /etc/nginx/sites-enabled/default

Found it:root /usr/share/nginx/html;
Switchroot /www;
Description: Set the Web site root directory to the/www directory, and be careful not to write/www/this format,
This habitual little neat freak brought me an unexpected disturbance, and I went on to elaborate.

Found it:index index.html index.htm;
Switchindex index.php index.html index.htm;
Description: Add index.php to the default index file

Found: location ~ .php$ { * } chunks
Make the following adjustments (changes are commented at the end of the line):

location ~ .php$ {
try_files $uri =404; #增加
fastcgi_split_path_info ^(.+.php)(/.+)$; #反注释
## NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
#
## With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
## With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock; #反注释
fastcgi_index index.php; #反注释
include fastcgi_params; #反注释
}

10, solve the php-fpm and Nginx small bug
Following the above steps, due to a small bug between Nginx and php-fpm, this phenomenon can be caused by:
The static page *.html in the website will be accessed normally, while the *.php file returns a 200 status code,
But the actual output to the browser page content is blank.

In short, the reason is that Nginx does not correctly pass the address of the *.php file to php-fpm to parse,
The equivalent of PHP-FPM received a request, but this request points to a nonexistent file, and returns an empty result.

In order to solve this problem, the Nginx default fastcgi_params configuration file needs to be changed:
vi /etc/nginx/fastcgi_params

Add a line at the end of the file:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

For the contents of this line, say a few words, of which there are two parameters:
$document _root means the root directory of the website, that is, we have just set the root/www in front;
$fastcgi _script_name refers to each *.php file name on the website (in fact, the relative path of the files)
These two together form the complete PHP file path, such as your website has a/test/script.php file,
The full path that Nginx passes to PHP-FPM is:/www/test/script.php

I said in front of the configuration Nginx, written as root/www/; This is not a problem for nginx,
But when it passes PHP file paths to PHP-FPM, it forms:/www//test/script.php
This file address is invalid (not getting the correct php file), so there is a problem with the return blank.
The problem is so hidden that I spend a lot of time looking at log, finding information, and adjusting settings.

11, restart the services
service php5-fpm reload
service nginx reload
Reload the configuration changes.

12. Testing
vi /www/index.php
Content:
<?php echo phpinfo(); ?>

Please open your browser to access: http://localhost If everything works, it will output PHP environment information, such as:

Appendix:
1, some editing and modification work involves the use of VI, if not operate, please visit this link:
http://linux.vbird.org/linux_basic/0310vi.php

2, I refer to all the materials, the most valuable two articles, thanks to the predecessors of the authors:
http://blog.segmentfault.com/ipanda/1190000000477401
Http://imcn.me/html/y2014/20291.html

3,Ubuntu is a good toy, since 06, again recommended:
http://www. ubuntu. com
Note: Don't use the so-called Chinese version that integrates a bunch of junk software.

Limingx.com/2014-09-13

Ubuntu 14.04 Installation Nginx+php+mysql

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.