ubuntu 安装LNMP

How To Install Linux, nginx, MySQL, PHP (LEMP) stack on Ubuntu 12.04

PostedJune 13, 2012 802.8kviews LEMP NGINX MYSQL PHP UBUNTU

This tutorial is for Ubuntu 12.04

Is your server also running Ubuntu 12.04? This tutorial may also be available for Ubuntu 14.04 and 16.04

12.04 (this tutorial)

Go to 14.04Go to 16.04

About Lemp

LEMP stack is a group of open source software to get web servers up and running. The acronym stands for Linux, nginx (pronounced Engine x), MySQL, and PHP. Since the server is already running Ubuntu, the linux part is taken care of. Here is how to install the rest.

Setup

The steps in this tutorial require the user to have root privileges. You can see how to set that up in the Initial Server Setup Tutorial in steps 3 and 4.

Step One—Update Apt-Get

Throughout this tutorial we will be using apt-get as an installer for all the server programs. On May 8th, 2012, a serious php vulnerability was discovered, and it is important that we download all of the latest patched software to protect the virtual private server.

Let‘s do a thorough update.

sudo apt-get update

Step Two—Install MySQL

MySQL is a powerful database management system used for organizing and retrieving data

To install MySQL, open terminal and type in these commands:

sudo apt-get install mysql-server php5-mysql

During the installation, MySQL will ask you to set a root password. If you miss the chance to set the password while the program is installing, it is very easy to set the password later from within the MySQL shell.

Once you have installed MySQL, we should activate it with this command:

sudo mysql_install_db

Finish up by running the MySQL set up script:

sudo /usr/bin/mysql_secure_installation

The prompt will ask you for your current root password.

Type it in.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Then the prompt will ask you if you want to change the root password. Go ahead and choose N and move on to the next steps.

It’s easiest just to say Yes to all the options. At the end, MySQL will reload and implement the new changes.

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from ‘localhost‘.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
... Success!

By default, MySQL comes with a database named ‘test‘ that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

Once you‘re done with that you can finish up by installing PHP.

Step Three—Install nginx

Once MySQL is all set up, we can move on to installing nginx on the VPS.

echo "deb http://ppa.launchpad.net/nginx/stable/ubuntu $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/nginx-stable.list
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C300EE8C
sudo apt-get update
sudo apt-get install nginx

nginx does not start on its own. To get nginx running, type:

sudo service nginx start

You can confirm that nginx has installed an your web server by directing your browser to your IP address.

You can run the following command to reveal your VPS‘s IP address.

ifconfig eth0 | grep inet | awk ‘{ print $2 }‘

Step Four—Install PHP

To install PHP-FPM, open terminal and type in these commands. We will configure the details of nginx and php details in the next step:

sudo apt-get install php5-fpm

Step Five—Configure php

We need to make one small change in the php configuration.Open up php.ini:

 sudo nano /etc/php5/fpm/php.ini

Find the line, cgi.fix_pathinfo=1, and change the 1 to 0.

cgi.fix_pathinfo=0

If this number is kept as 1, the php interpreter will do its best to process the file that is as near to the requested file as possible. This is a possible security risk. If this number is set to 0, conversely, the interpreter will only process the exact file path—a much safer alternative. Save and Exit. We need to make another small change in the php5-fpm configuration.Open up www.conf:

 sudo nano /etc/php5/fpm/pool.d/www.conf

Find the line, listen = 127.0.0.1:9000, and change the 127.0.0.1:9000 to /var/run/php5-fpm.sock.

listen = /var/run/php5-fpm.sock

Save and Exit.

Restart php-fpm:

sudo service php5-fpm restart

Step Six—Configure nginx

Open up the default virtual host file.

sudo nano /etc/nginx/sites-available/default

The configuration should include the changes below (the details of the changes are under the config information):

UPDATE: Newer Ubuntu versions create a directory called ‘html‘ instead of ‘www‘ by default. If /usr/share/nginx/www does not exist, it‘s probably called html. Make sure you update your configuration appropriately.

 [...]
server {
        listen   80;

        root /usr/share/nginx/www;
        index index.php index.html index.htm;

        server_name example.com;

        location / {
                try_files $uri $uri/ /index.html;
        }

        error_page 404 /404.html;

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
              root /usr/share/nginx/www;
        }

        # pass the PHP scripts to FastCGI server listening on the php-fpm socket
        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;

        }

}
[...]

Here are the details of the changes:

  • Add index.php to the index line.
  • Change the server_name from local host to your domain name or IP address (replace the example.com in the configuration)
  • Change the correct lines in “location ~ \.php$ {“ section

Save and Exit

Step Seven—Create a php Info Page

We can quickly see all of the details of the new php configuration.

To set this up, first create a new file:

sudo nano /usr/share/nginx/www/info.php

Add in the following line:

<?php
phpinfo();
?>

Then Save and Exit.

Restart nginx

sudo service nginx restart

You can see the nginx and php-fpm configuration details by visiting http://youripaddress/info.php

Your LEMP stack is now set up and configured on your virtual private server.

See More

After installing LEMP, you can Install WordPress, go on to do more with MySQL (A Basic MySQL Tutorial) or Install phpMyAdminCreate an SSL Certificate, or Install an FTP Server.

时间: 2024-10-25 19:06:32

ubuntu 安装LNMP的相关文章

ubuntu安装 LNMP

注意事项: 1.访问PHP文件,提示502 编辑 /etc/php5/fpm/pool.d/www.conf  将 listen = /var/run/php5-fpm.sock 修改为:listen = 127.0.0.1:9000

Ubuntu 14.04 LTS 安装 LNMP Nginx\PHP5 (PHP-FPM)\MySQL

之前在Ubuntu12.04上搭建过PHP开发环境,按照这里http://budongzhenren.blog.51cto.com/2288320/991365安装的.但是系统换成14.04后,再用这个方法安装一直不成功,让我很郁闷,折腾了好久,后来才发现在12.04上安装Nginx,默认的网站根目录在 /usr/share/nginx/www,而在14.04上,默认的网站根目录是 /usr/share/nginx/html. 在Ubuntu14.04上搭建PHP环境的步骤参考这里:http:/

Ubuntu系统LNMP环境下安装配置zabbix3.0

Ubuntu 14.04(LNMP)安装配置Zabbix 3.0,LNMP安装你可以参考我上一篇博文<ubuntu安装配置LNMP> 添加zabbix3.0的源 可以根据自己工作需求选择zabbix版本 # wget http://repo.zabbix.com/zabbix/3.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_3.0-1+trusty_all.deb # dpkg -i zabbix-release_3.0-1+trust

Mac下安装LNMP(Nginx+PHP5.6)环境

Mac下安装LNMP(Nginx+PHP5.6)环境 安装Homebrew 最近工作环境切换到Mac,所以以OS X Yosemite(10.10.1)为例,记录一下从零开始安装Mac下LNMP环境的过程 确保系统已经安装xcode,然后使用一行命令安装依赖管理工具Homebrew ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 之后就可以使用 brew

ubuntu14.04 安装LNMP

通常我们使用centos来组建LNMP,但是我们开发时多使用ubuntu的桌面版本来调试,下面将详细介绍如何在ubuntu上安装一套LNMP. 一.下载并安装最新的ubuntu14.04桌面版本 二.安装mysql 1. 下载mysql的最新版本,例如: wget http://dl.mysql.cn/mysql5/5.5/mysql-5.5.25.tar.gz 2. 解压缩: tar -xvf mysql-5.5.25.tar.gz 3. 进入mysql文件目录: cd mysql-5.5.2

ubuntu安装wordpress中文版

环境:ubuntu lnmp 下载中文版本wordpress cd /usr/local/nginx/html wget http://cn.wordpress.org/wordpress-3.9-zh_CN.zip unzip wordpress-3.9-zh_CN.zip '若未安装zip,先安装zip,apt-get install zip 在浏览器中安装 前提是已经建立好了数据库. 在浏览器中输入 localhost/wordpress(解压后的文件名)/wp-admin/install

ubuntu12.04 apt-get安装 lnmp环境(转)

1.安装mysql [sql] view plaincopy sudo apt-get install mysql-server mysql-client 安装过程中要输入root用户的密码. 我在安装中出错,是原来的mysql-cilent mysql-workbench 未完全卸载,将mysql组件完全卸载的方法: 删除mysql前 先删除一下 /var/lib/mysql 还有 /etc/mysql [sql] view plaincopy sudo rm /var/lib/mysql/ 

安装lnmp前请先运行screen

安装lnmp前请先运行screen 虽然之前vps侦探已经发表过screen命令的使用方法,并结合lnmp一键安装包进行了简单的说明,但是还是有些小白会问当通过putty或者SecureCRT安装lnmp时,网络突然掉线或者不小心putty被关掉等等原因,造成lnmp安装过程被中断怎么办,其实防止这种现象很简单,只要在安装lnmp前执行screen命令就可以了. licess也在vps侦探上说过screen命令的使用方法,下面结合lnmp的安装过程再说一下. 1.screen安装方法就不说了,看

Ubuntu 安装 JDK 7 / JDK8 的两种方式

ubuntu 安装jdk 的两种方式: 1:通过ppa(源) 方式安装. 2:通过官网下载安装包安装. 这里推荐第1种,因为可以通过 apt-get upgrade 方式方便获得jdk的升级 使用ppa/源方式安装 1.添加ppa sudo add-apt-repository ppa:webupd8team/java sudo apt-get update 2.安装oracle-java-installer jdk7 sudo apt-get install oracle-java7-inst