搜索
首页后端开发php教程ubuntu14.04 LEMP(linux+nginx+mysql+php5)构建环境,_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

ubuntu14.04 LEMP(linux+nginx+mysql+php5)构建环境,_PHP教程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

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

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

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 that no one remote your database as root from another machines, we need to disallow root login remotely.
Fig.08: MySQL security

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

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

7.Done

ubuntu14.04 LEMP(linux+nginx+mysql+php5)构建环境,_PHP教程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.
    mysql_php5_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.

    www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1084380.htmlTechArticleubuntu14.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 I 'm a new Ubun...
    声明
    本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
    您如何防止与会议有关的跨站点脚本(XSS)攻击?您如何防止与会议有关的跨站点脚本(XSS)攻击?Apr 23, 2025 am 12:16 AM

    要保护应用免受与会话相关的XSS攻击,需采取以下措施:1.设置HttpOnly和Secure标志保护会话cookie。2.对所有用户输入进行输出编码。3.实施内容安全策略(CSP)限制脚本来源。通过这些策略,可以有效防护会话相关的XSS攻击,确保用户数据安全。

    您如何优化PHP会话性能?您如何优化PHP会话性能?Apr 23, 2025 am 12:13 AM

    优化PHP会话性能的方法包括:1.延迟会话启动,2.使用数据库存储会话,3.压缩会话数据,4.管理会话生命周期,5.实现会话共享。这些策略能显着提升应用在高并发环境下的效率。

    什么是session.gc_maxlifetime配置设置?什么是session.gc_maxlifetime配置设置?Apr 23, 2025 am 12:10 AM

    thesession.gc_maxlifetimesettinginphpdeterminesthelifespanofsessiondata,setInSeconds.1)它'sconfiguredinphp.iniorviaini_set().2)abalanceIsiseededeedeedeedeedeedeedto to to avoidperformance andununununununexpectedLogOgouts.3)

    您如何在PHP中配置会话名?您如何在PHP中配置会话名?Apr 23, 2025 am 12:08 AM

    在PHP中,可以使用session_name()函数配置会话名称。具体步骤如下:1.使用session_name()函数设置会话名称,例如session_name("my_session")。2.在设置会话名称后,调用session_start()启动会话。配置会话名称可以避免多应用间的会话数据冲突,并增强安全性,但需注意会话名称的唯一性、安全性、长度和设置时机。

    您应该多久再生一次会话ID?您应该多久再生一次会话ID?Apr 23, 2025 am 12:03 AM

    会话ID应在登录时、敏感操作前和每30分钟定期重新生成。1.登录时重新生成会话ID可防会话固定攻击。2.敏感操作前重新生成提高安全性。3.定期重新生成降低长期利用风险,但需权衡用户体验。

    如何在PHP中设置会话cookie参数?如何在PHP中设置会话cookie参数?Apr 22, 2025 pm 05:33 PM

    在PHP中设置会话cookie参数可以通过session_set_cookie_params()函数实现。1)使用该函数设置参数,如过期时间、路径、域名、安全标志等;2)调用session_start()使参数生效;3)根据需求动态调整参数,如用户登录状态;4)注意设置secure和httponly标志以提升安全性。

    在PHP中使用会议的主要目的是什么?在PHP中使用会议的主要目的是什么?Apr 22, 2025 pm 05:25 PM

    在PHP中使用会话的主要目的是维护用户在不同页面之间的状态。1)会话通过session_start()函数启动,创建唯一会话ID并存储在用户cookie中。2)会话数据保存在服务器上,允许在不同请求间传递数据,如登录状态和购物车内容。

    您如何在子域中分享会议?您如何在子域中分享会议?Apr 22, 2025 pm 05:21 PM

    如何在子域名间共享会话?通过设置通用域名的会话cookie实现。1.在服务器端设置会话cookie的域为.example.com。2.选择合适的会话存储方式,如内存、数据库或分布式缓存。3.通过cookie传递会话ID,服务器根据ID检索和更新会话数据。

    See all articles

    热AI工具

    Undresser.AI Undress

    Undresser.AI Undress

    人工智能驱动的应用程序,用于创建逼真的裸体照片

    AI Clothes Remover

    AI Clothes Remover

    用于从照片中去除衣服的在线人工智能工具。

    Undress AI Tool

    Undress AI Tool

    免费脱衣服图片

    Clothoff.io

    Clothoff.io

    AI脱衣机

    Video Face Swap

    Video Face Swap

    使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

    热工具

    Atom编辑器mac版下载

    Atom编辑器mac版下载

    最流行的的开源编辑器

    DVWA

    DVWA

    Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中

    SublimeText3 Mac版

    SublimeText3 Mac版

    神级代码编辑软件(SublimeText3)

    记事本++7.3.1

    记事本++7.3.1

    好用且免费的代码编辑器

    SublimeText3 英文版

    SublimeText3 英文版

    推荐:为Win版本,支持代码提示!