Install LEMP (Linux, Nginx, MySQL and PHP) Stack on Ubuntu Linux 14.04 LTS (RPM)

Source: Internet
Author: User
Tags fpm php language php and mysql phpinfo


Install LEMP (Linux, Nginx, MySQL and PHP) Stack on Ubuntu Linux 14.04 LTS




Nginx Installation


Nginx is one of the robust Web servers in Linux world. Nginx is a free, open source, high performance HTTP server and reverse proxies, as weell as an IMAP/POP3 proxy server. Now, we is going to install Nginx Web server.



First, make sure system is upto date:
$ sudo apt-get update
$ sudo apt-get upgrade


#1-download and Install Nginx


The easiest-download and install Nginx is using the Apt-get command. This is the command:
$ sudo apt-get install nginx



Just wait until installation is get do on the system.


#2-test Nginx


Once it get done, you can open your browser and type URLs http://localhost or http://your_ip_address to test it. If everything goes normal, you'll see Nginx Welcome page:



Welcome nginx page on Ubuntu Linux


MySQL installation on Ubuntu


MySQL is one of the most powerful database management system on Linux world. Next, we is going to the install it with PHP support.


#1-install MySQL and PHP support


Type the following command:
$ sudo apt-get install mysql-server php5-mysql




During the installation, MySQL would ask you to enter MySQL root password, and other wise the installation would not continue. Type the password you want and then press OK to continue the installation.


#2-test MySQL


Once MySQL installation finished, we can test it. Open your console and type the following command:
$ mysql -u root -p





If you type your password correctly, the "you'll see the MySQL prompt.


#3-securing access to MySQL


If we are going to the use of MySQL as a production database, we may be want to secure it. MySQL provides a shell script to help us securing it. Just Type the following command on your console:
$ sudo mysql_secure_installation
Here is the steps to do it.


1. Enter Your root password


Enter your current root password to continue to the next step.


2.Change the root password


If you want to change it, press Y. Otherwise, press N.


3.Remove Anonymous User


It is recommended to remove anonymous user to mitigate risk who can log in into your database.



Y


4.Disallow Root Login remotely


To make sure this no one remote your database as root from another machines and we need to disallow root login remotely.


y5.Remove Test Database


Sometimes some MySQL installation would create a database namedëtestífor testing purpose. We can remove it if we donít use it.


y6.Reload Privilege Tables


Then we need to reloading the privilege tables to ensure all changes made so far would take effect immediately.


y7.Done PHP installation for Server Side Scripting


Since PHP is popular, a lot of websites is built using PHP language. As of January, PHP was installed on more than millions websites. Now we is going to install PHP on Ubuntu 14.04


#1-download and install PHP


As usual, we can download and install PHP using Apt-get command. Just Type the following command on your Ubuntu console or over the SSH based session:
$ sudo apt-get install php5-fpm




And wait for the installation.


Configure Nginx to work with PHP and MySQL Server on Ubuntu


Now we have all the components installed. The next step is we need to configure Nginx with PHP and MySQL. Let's start to configure them.


#1-configure PHP5-FPM


PHP5-FPM configuration file is located at/etc/php5/fpm/php.ini. Open it with your text editor
$ sudo vi /etc/php5/fpm/php.ini
Change this parameter, from:
cgi.fix_pathinfo=1
To:
cgi.fix_pathinfo=0
Save and close the file and then restart PHP5-FPM service, type:
$ sudo service php5-fpm restart


#2-configure Nginx


Nginx configuration file is located at/etc/nginx/nginx.conf. But basically, we don ' t need to touch it. The configuration of Nginx website is located in/etc/nginx/sites-available/default file.
Open it, and uncomment lines:


 location ~ \.php$ {
         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;
 }

Then restart the services.
$ sudo service nginx restart
Please do sure, on Ubuntu 14.04, we cannot use Fastcgi_pass 127.0.0.1:9000. So make sure, that's the line is commented. Otherwise, on my machine, I got this error:
$ tail /var/log/nginx/error.log
2014/11/04 16:57:04 [emerg] 3216#0: "fastcgi_pass" directive is not allowed here in /etc/nginx/sites-enabled/default:59
2014/11/04 16:58:21 [emerg] 3256#0: "fastcgi_pass" directive is not allowed here in /etc/nginx/sites-enabled/default:59

On Ubuntu 14.04, I use the following line:
fastcgi_pass unix:/var/run/php5-fpm.sock
When I restart the Nginx and I still got the following error message:

2014/11/04 17:02:05 [emerg] 3295#0: "fastcgi_pass" directive is not allowed here in /etc/nginx/sites-enabled/default:61
2014/11/04 17:04:58 [emerg] 3410#0: "fastcgi_pass" directive is not allowed here in /etc/nginx/sites-enabled/default:61

Please make sure the already uncomment this line:
location ~ \.php$ {

#3-configure MySQL


After the configuration sections is do, now we need to test them to make sure, we are configuration is working as Requir Ed. On Ubuntu 14.04, the root document folder is located in/usr/share/nginx/html. So create a file called/usr/share/nginx/html/phpinfo.php with the following code:


 
<? phpinfo(); ?>
 


After restarting PHP-FPM and Nginx, open the browser and browse to the PHP file, we got only a blank screen. No error message on the screen. No error message on PHP-FPM and Nginx log file.

Then we changed/usr/share/nginx/html/phpinfo.php file code on the root document of Nginx, as follows:


 
<?php phpinfo(); ?>


And then open the browser again and type URL http://your_ip_address/phpinfo.php

It seem-by-default, we can not use the short php-tag as this:


 
<? ... your code ... ?>


To enable short PHP tags, we need to change the value of Short_open_tag parameter on php.ini file:

The change of the value from Off to ON. Then restart your PHP5-FPM:
sudo service php5-fpm restart
Then try again to test your phpinfo file. Next, we'll see if the MySQL support was enabled or not. Scroll down the PHP configuration screens on your browser if you see MySQL block there and then MySQL support already enabled .

PHP5 and MySQL on Ubuntu server. I Hope this quick article help anyone who wish to install Linux, Nginx, PHP and MySQL on Ubuntu 14.04.



Install LEMP (Linux, Nginx, MySQL and PHP) Stack on Ubuntu Linux 14.04 LTS (RPM)


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.