Reference: https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-12-04#
About Lemp
LEMP Stack is a group of open source software to get Web servers up and running. The acronym stands for Linux, nginx (pronounced Engine x), MySQL, and PHP. Since the server is already running Ubuntu, the Linux part was taken care of. Here's how to install the rest.
Setup
The steps tutorial require the user to has root privileges. You can see how to set the-in-Initial Server Setup Tutorial in steps 3 and 4.
Step one-update Apt-get
Throughout this tutorial we'll be using Apt-get as a installer for all the server programs. On could 8th, a serious PHP vulnerability was discovered, and it's important that we download all of the latest patch Ed software to protect the virtual private server.
Let's do a thorough update.
sudo apt-get update
Step Two-install MySQL
MySQL is a powerful database management system used for organizing and retrieving data
To install MySQL, open terminal and type in these commands:
sudo apt-get install mysql-server php5-mysql
During the installation, MySQL would ask you to set a root password. If you miss the chance to set the password and the program is installing, it's very easy-to-set the password later from Within the MySQL shell.
Once you has installed MySQL, we should activate it with the This command:
sudo mysql_install_db
Finish up by running the MySQL set up script:
Sudo/usr/bin/mysql_secure_installation
The prompt would ask you to your current root password.
Type it in.
Enter current password to root (enter for none): OK, successfully used password, moving on ...
Then the prompt would ask if you want the root password. Go ahead and choose N and move on to the next steps.
It ' s easiest just to say Yes to the options. At the end, MySQL would reload and implement the new changes.
By default, a MySQL installation had an anonymous user, allowing Anyoneto logs into MySQL without had to had a user ACC Ount created Forthem. This was intended only for testing, and the Installationgo a bit smoother. You should remove them before moving into aproduction environment. Remove anonymous users? [y/n] Y ... success! Normally, Root should only is allowed to connect from ' localhost '. Thisensures that someone cannot guess at the root of password from the network. Disallow Root login remotely? [y/n] Y ... success! By default, MySQL comes with a database named ' test ' that anyone canaccess. This was also intended only for testing, and should was removedbefore moving into a production environment. Remove test database and access to it? [y/n] y-dropping Test Database ... success! -Removing privileges on test database ... success! Reloading the privilege tables would ensure that all changes made so farwill take effect immediately. REload privilege tables now? [y/n] Y ... success! Cleaning up ...
Once you ' re do with that can finish up by installing PHP.
Step Three-install Nginx
Once MySQL is all set up and we can move on to installing Nginx on the VPS.
sudo apt-get install Nginx
Nginx does not-start on its own. To get Nginx running, type:
sudo service nginx start
You can confirm this nginx has installed a your Web server by directing your browser to your IP address.
You can run the following command to reveal your VPS ' s IP address.
Ifconfig eth0 | grep inet | awk ' {print $} '
Step Four-install PHP
To install the PHP-FPM, open terminal and type in these commands. We'll configure the details of Nginx and PHP details in the next step:
sudo apt-get install PHP5-FPM
Step five-configure PHP
We need to make one small change in the PHP configuration. Open up php.ini:
sudo nano/etc/php5/fpm/php.ini
Find the line, cgi.fix_pathinfo=1, and change the 1 to 0.
Cgi.fix_pathinfo=0
If This number is kept as 1, the PHP interpreter would do it best to process the file, which is as near to the requested Fil e as possible. This is a possible security risk. If This number was set to 0, conversely, the interpreter would only process the exact file path-a much safer alternative. Save and Exit. We need to make another small change in the PHP5-FPM configuration. Open up www.conf:
sudo nano/etc/php5/fpm/pool.d/www.conf
Find the line, listen = 127.0.0.1:9000, and change the 127.0.0.1:9000 to/var/run/php5-fpm.sock.
Listen =/var/run/php5-fpm.sock
Save and Exit.
Restart PHP-FPM:
sudo service php5-fpm restart
Step six-configure Nginx
Open up the default virtual host file.
sudo nano/etc/nginx/sites-available/default
The configuration should include the changes below (the details of the changes are under the config information):
UPDATE: Newer Ubuntu versions create a directory called ' HTML ' instead of ' www ' by default. If/usr/share/nginx/www does not exist, it ' s probably called HTML. Make sure update your configuration appropriately.
[...] server { listen ; root/usr/share/nginx/www; Index index.php index.html index.htm; server_name example.com; Location/{ try_files $uri $uri//index.html; } Error_page 404/404.html; Error_page 502 503 504/50x.html; Location =/50x.html { root/usr/share/nginx/www; } # Pass the PHP scripts to FastCGI server listening on the PHP-FPM socket location ~ \.php$ { try_files $uri =404 ; Fastcgi_pass Unix:/var/run/php5-fpm.sock; Fastcgi_index index.php; Fastcgi_param script_filename $document _root$fastcgi_script_name; Include Fastcgi_params; }} [...]
Here is the details of the changes:
- ADD index.php to the index line.
- Change the server_name from local host to your domain name or IP address (replace the example.com in the configuration)
- Change the correct lines in ' location ~ \.php$ {' section
Save and Exit
Step seven-create a php Info Page
We can quickly see all of the details of the new PHP configuration.
To set the this up, first create a new file:
sudo nano/usr/share/nginx/www/info.php
ADD in the following line:
<?phpphpinfo ();? >
Then Save and Exit.
Restart Nginx
sudo service nginx restart
You can see the Nginx and PHP-FPM configuration details by visiting http://youripaddress/info.php
Your LEMP Stack is now set up and configured on Your virtual Private server.
2. After installing the installation steps described in the above article, access the PHP file via the browser to get 502 pages: The page you were looking for istemporarily unavailable.
Check nginx error.log file: Found error: Connect to Php5-fpm.sock failed (Permission denied),
Reference: Http://stackoverflow.com/questions/23443398/nginx-error-connect-to-php5-fpm-sock-failed-13-permission-denied