0

0

ubuntu14.04 LEMP(linux+nginx+mysql+php5)构建环境,

php中文网

php中文网

发布时间:2016-06-13 08:49:18

|

1174人浏览过

|

来源于php中文网

原创

ubuntu14.04 LEMP(linux+nginx+mysql+php5)构建环境,

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

by VIVEK GITE on DECEMBER 2, 2014

立即学习PHP免费学习笔记(深入)”;

Fish Audio
Fish Audio

为所有人准备的音频 AI

下载
I'm a new Ubuntu Linux user. How do I install the LEMP stack on an Ubuntu Linux 14.04 LTS server using command line options to serve dynamic web apps?
Tutorial details Difficulty Easy (rss) Root privileges Yes Requirements Ubuntu Estimated completion time 15m

立即学习PHP免费学习笔记(深入)”;

What is new in Ubuntu 14.04 (Trusty Tahr) version?

You may see it on cyberciti.biz or visit the Ubuntu home page at ubuntu.com.

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


#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:
Fig.02: Welcome nginx page on Ubuntu Linux

立即学习PHP免费学习笔记(深入)”;

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

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

立即学习PHP免费学习笔记(深入)”;

2.Change the root password

If you want to change it, press Y. Otherwise, press N.
Fig.06: MySQL security

立即学习PHP免费学习笔记(深入)”;

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

立即学习PHP免费学习笔记(深入)”;

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.
Fig.08: MySQL security

立即学习PHP免费学习笔记(深入)”;

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.
Fig.09: MySQL security

立即学习PHP免费学习笔记(深入)”;

6.Reload privilege tables

Then we need to reloading the privilege tables to ensure all changes made so far will take effect immediately.
Fig.10: MySQL security

立即学习PHP免费学习笔记(深入)”;

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 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
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 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 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
$ tail /var/log/nginx/error.log
fastcgi_pass unix:/var/run/php5-fpm.sock

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:

[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)"> "_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 tag, 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 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.

    PHP速学教程(入门到精通)
    PHP速学教程(入门到精通)

    PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

    下载

    本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

    相关专题

    更多
    ip地址修改教程大全
    ip地址修改教程大全

    本专题整合了ip地址修改教程大全,阅读下面的文章自行寻找合适的解决教程。

    33

    2025.12.26

    压缩文件加密教程汇总
    压缩文件加密教程汇总

    本专题整合了压缩文件加密教程,阅读专题下面的文章了解更多详细教程。

    18

    2025.12.26

    wifi无ip分配
    wifi无ip分配

    本专题整合了wifi无ip分配相关教程,阅读专题下面的文章了解更多详细教程。

    46

    2025.12.26

    漫蛙漫画入口网址
    漫蛙漫画入口网址

    本专题整合了漫蛙入口网址大全,阅读下面的文章领取更多入口。

    91

    2025.12.26

    b站看视频入口合集
    b站看视频入口合集

    本专题整合了b站哔哩哔哩相关入口合集,阅读下面的文章查看更多入口。

    283

    2025.12.26

    俄罗斯搜索引擎yandex入口汇总
    俄罗斯搜索引擎yandex入口汇总

    本专题整合了俄罗斯搜索引擎yandex相关入口合集,阅读下面的文章查看更多入口。

    370

    2025.12.26

    虚拟号码教程汇总
    虚拟号码教程汇总

    本专题整合了虚拟号码接收验证码相关教程,阅读下面的文章了解更多详细操作。

    35

    2025.12.25

    错误代码dns_probe_possible
    错误代码dns_probe_possible

    本专题整合了电脑无法打开网页显示错误代码dns_probe_possible解决方法,阅读专题下面的文章了解更多处理方案。

    25

    2025.12.25

    网页undefined啥意思
    网页undefined啥意思

    本专题整合了undefined相关内容,阅读下面的文章了解更多详细内容。后续继续更新。

    72

    2025.12.25

    热门下载

    更多
    网站特效
    /
    网站源码
    /
    网站素材
    /
    前端模板

    精品课程

    更多
    相关推荐
    /
    热门推荐
    /
    最新课程
    SQL优化与排查(MySQL版)
    SQL优化与排查(MySQL版)

    共26课时 | 2.2万人学习

    Linux优化视频教程
    Linux优化视频教程

    共14课时 | 3.1万人学习

    关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
    php中文网:公益在线php培训,帮助PHP学习者快速成长!
    关注服务号 技术交流群
    PHP中文网订阅号
    每天精选资源文章推送

    Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号