ubuntu14.04 LEMP (LINUX+NGINX+MYSQL+PHP5) build environment, _php tutorials

Source: Internet
Author: User
Tags php and mysql

ubuntu14.04 LEMP (LINUX+NGINX+MYSQL+PHP5) build the environment,


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

by VIVEK gite on December 2,

I' m a new Ubuntu Linux user. How does I install the LEMP stack on a Ubuntu Linux 14.04 LTS server using command line options to serve Dynamic Web apps?
Tutorial DetailsDifficultyEasy (RSS)Root PrivilegesYesRequirementsUbuntuEstimated completion time15m

What's new in Ubuntu 14.04 (trusty Tahr) version?

Cyberciti.biz or visit the Ubuntu home page at ubuntu.com.

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
#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
Fig.01:download and Install Nginx on Ubuntu Linux


#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:
Fig.02: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
Fig.03:ubuntu Linux Install MySQL to Manage Site Data with PHP


#2-test MySQL

Once MySQL installation finished, we can test it. Open your console and type the following command:
$ mysql-u Root-p
Fig.04:ubuntu Test Mysql Installation


#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
1. Enter Your root password

Enter your current root password to continue to the next step.
Fig.05:mysql Enter your root db password

2.Change the root password

If you want to change it, press Y. Otherwise, press N.
Fig.06:mysql Security

3.Remove Anonymous User

It is recommended to remove anonymous user to mitigate risk who can log in into your database.
Fig.07:mysql Security

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.
Fig.08:mysql Security

5.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.
Fig.09:mysql Security

6.Reload Privilege Tables

Then we need to reloading the privilege tables to ensure all changes made so far would take effect immediately.
Fig.10:mysql Security

7.Done

Fig.11:mysql Security

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
Fig.12:install PHP for Server Side processing on Ubuntu


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
Cgi.fix_pathinfo=1
Cgi.fix_pathinfo=0
$ 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.
Location ~ \.php$ {fastcgi_split_path_info ^ (. +\.php) (/.+) $; # # note:you should has "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
$ tail/var/log/nginx/error.log
Fastcgi_pass Unix:/var/run/php5-fpm.sock

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:

[PHP]View Plaincopy

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.

  • "margin:0px; padding:0px; Word-wrap:break-word; Color:rgb (0,0,0) " " !--? php "_blank" href= "Http://www.php.net/phpinfo" style= "margin:0px; padding:0px; Word-wrap:break-word; Color:rgb (128,128,128); Text-decoration:none " > " margin:0px; padding:0px; Word-wrap:break-word; Color:rgb (0,0,102) " >phpinfo " margin:0px; padding:0px; Word-wrap:break-word; Color:rgb (102,204,102) " > ( " margin:0px; padding:0px; Word-wrap:break-word; Color:rgb (102,204,102) " >) ; "margin:0px; padding:0px; Word-wrap:break-word; Color:rgb (0,0,0) " ; ;
  • And then open the browser again and type URL http://your_ip_address/phpinfo.php

  • "margin:0px; padding:0px; Word-wrap:break-word; Color:rgb (0,0,0) "> ... your code ... "margin:0px; padding:0px; Word-wrap:break-word; Color:rgb (0,0,0) ">?>
  • To enable short PHP tags, we need to change the value of Short_open_tag parameter on php.ini file:
    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.

    http://www.bkjia.com/PHPjc/1084380.html www.bkjia.com true http://www.bkjia.com/PHPjc/1084380.html techarticle ubuntu14.04 LEMP (LINUX+NGINX+MYSQL+PHP5) build environment, Install LEMP (Linux, Nginx, MySQL and PHP) Stack on Ubuntu Linux 14.04 L TS by VIVEK Gite on December 2, I ' m a new ubun ...

  • 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.