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

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

Nginx Installation

Nginx
is one of the robust web server in Linux world. Nginx is a free, open
source, high performance HTTP server and reverse proxy, as weell as an
IMAP/POP3 proxy server. Now, we are 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 way to download and install Nginx is using apt-get command. Here is the command:
$ sudo apt-get install nginx

Just wait until installation is get done on the system.

#2 - Test Nginx

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

Welcome nginx page on Ubuntu Linux

MySQL Installation On Ubuntu

MySQL is one of the most powerful database management system in Linux world. Next, we are going to 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 will ask you to enter MySQL root
password, other wise the installation will not continue. Type the
password you want, 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 will see the mysql prompt.

#3 - Securing access to MySQL

If
we are going to use MySQL as a production database, we may 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 are 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 that no one remote your database as root from another machines, we need to disallow root login remotely.

y

5.Remove test database

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

y

6.Reload privilege tables

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

y

7.Done

PHP Installation For Server Side Scripting

Since
PHP is popular, a lot of websites is built using PHP language. As of
January 2013, PHP was installed on more than 240 millions websites. Now
we are 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 to complete.

Configure Nginx to work with PHP and MySQL Server on Ubuntu

Now
we have all 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 make sure, on Ubuntu 14.04, we cannot use fastcgi_pass
127.0.0.1:9000. So make sure that 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 that you already uncomment this line:
location ~ \.php$ {

#3 - Configure MySQL

After
the configuration section is done, now we need to test them to make
sure that our configuration is working as required. 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 that by default, we can not use short php-tag like this:

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

To enable short php tag, we need to change the value of short_open_tag parameter on php.ini file:

Change 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 will see if the
MySQL support is enabled or not. Scroll down the php configuration
screen on your browser, if you see MySQL block there, then MySQL support
already enabled.

You are now ready to use Nginx, 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.

时间: 2024-08-07 17:08:51

Install LEMP (Linux, Nginx, MySQL and PHP) Stack on Ubuntu Linux 14.04 LTS(转)的相关文章

Install MySQL 5.7.5-m15 on Ubuntu Server 14.04 LTS

Install libaio MySQL depends on the libaio library. If you have not the libaio installed on your system, then install it first. apt-get install libaio1 If the command above prompts that you need insert the disc labled "Ubuntu Server 14.04 LTS ...&quo

Install MySQL 5.7.5-m15 on Ubuntu Server 14.04 LTS from Source

This post documents the steps of installing MySQL from source code, and the resolutions to serveral issues in installing. The steps here are specific to 64-bit Ubuntu 14.04.1 LTS, and MySQL source code is 5.7.5-m15. But I think most of them can also 

How To Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu

About LAMP LAMP stack is a group of open source software used to get web servers up and running. The acronym stands for Linux, Apache, MySQL, and PHP. Since the virtual private server is already running Ubuntu, the linux part is taken care of. Here i

Linux Ubuntu Server 14.04 LTS 处理中文乱码及vi编辑器操作概要

首先在网上搜了一些资料,说是暂时无法解决. 但在安装的时候选择的是中文安装,因此在命令页面显示的是方格的乱码. 既然是Linux 服务版,我想就没必要去安装中文包了吧,决定换回英语显示. ================ 1.使用命令cd etc/default 切换到这个目录下,然后修改locale文件里的内容: 2.要修改locale文件,普通用户的权限是不够的,那怎么办呢,使用sudo 命令,在默认情况下,可以得到5分钟的root权限,即:sudo vi locale: 这样就进入vi编辑

在ubuntu中用apt-get安装LEMP栈(linux+nginx+mysql+php)

在ubuntu上安装lamp大家应该都很熟悉了,但对于现在很流行的lemp栈怎么样用apt-get安装,这样介绍的文章的不多.下面我用Ubuntu 12.04 LTS为例来介绍下如何用apt-get安装这些. 为什么要用apt-get不用编译安装 用包管理除了可以方便统一的管理软件外,他还可以帮你搞定启动脚本,自动更新等一大堆麻烦的问题.其实大多数人用的编译安装,也是使用的默认编译参数,大多数定制化的东西都可以通过配置文件完成.如果你对编译的定制化比较高,甚至可以自己做一个私有源来放你自己编译的

centos6 LNMP的搭建(linux+nginx+mysql+php)

LNMP的搭建(linux+nginx+mysql+php) 简介 LNMP代表的就是:Linux系统下Nginx+MySQL+PHP网站服务器架构. Linux是一类Unix计算机操作系统的统称,是目前最流行的免费操作系统.代表版本有:debian.centos.ubuntu.fedora.gentoo等. Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器. Mysql是一个小型关系型数据库管理系统. PHP是一种在服务器端执行的嵌入HTML文档

LAMP架构演进到LAMPGC,再演进到LNMLGC(linux+nginx+mysql+lua+gearman+C)

LAMP是一个大众的架构了,linux+apache+mysql+php 在我们系统的架构中,做了进一步的演进,linux+apahce+mysql+php+gearman+C php作页面的展示 核心业务逻辑由C语言实现,php通过gearman中间件调用C任务 由于apache在高并发方面不太给力,因此在需要高并发的场景中,我们进一步演进,linux+nginx+mysql+php+lua+gearman+C 页面部分由nginx+fastcgi+php-fpm来展示 高并发的业务调用由ng

centos7安装Lnmp(Linux+Nginx+MySql+Php+phpMyAdmin+Apache)

centos7安装Lnmp(Linux+Nginx+MySql+Php)及Apache Nginx是俄罗斯人编写的十分轻量级的HTTP服务器,Nginx是一个高性能的HTTP和反向代理服务器,Nginx 超越 Apache 的高性能和稳定性,使得国内使用 Nginx 作为 Web 服务器的网站也越来越多, 我们学习PHP,以及搭建我们自己的LNMP环境,不妨先在本机上尝试学习,下面我们一步一步来完成在CentOS7 下安装LNMP(Linux+Nginx+MySQL+PHP)及Apache. 查

linux+nginx+mysql+php

LNMP(linux+nginx+mysql+php)服务器环境配置 一.简介 Nginx是俄罗斯人编写的十分轻量级的HTTP服务器,Nginx,它的发音为 “engine X”, 是一个高性能的HTTP和反向代理服务器,同时也是一个IMAP/POP3/SMTP 代理服务器.Nginx是由俄罗斯人 Igor Sysoev为俄罗斯访问量第二的 Rambler.ru站点开发的,它已经在该站点运行超过三年了.Igor Sysoev在建立的项目时,使用基于BSD许可. 在高并发连接的情况下,Nginx是