红联Linux门户
Linux帮助

Ubuntu15.04下搭建LNMP环境

发布时间:2015-07-25 21:23:52来源:blog.sina.com.cn/u/2090614470作者:_Teven

LNMP是Linux+Nginx+MySQL+PHP的简称,是一套完整的PHP网站服务器架构环境。

所用Linux发行版为Ubuntu Gnome 15.04,所有需要的软件均使用Ubuntu自带apt源下载安装。


首先,更新Ubuntu源:
sudo apt-get update

然后,安装Nginx:
sudo apt-get install nginx


等待nginx安装完成后,打开浏览器,在地址栏输入localhost,检测nginx是否开启;若开启成功,则会显示欢迎使用Nginx的界面;若没有,则在终端下输入以下命令即可打开nginx:

sudo /etc/init.d/nginx start


然后安装mysql:

sudo apt-get install mysql-server-5.6 mysql-workbench mysql-client-5.6

安装过程中需要设置root用户的密码,选择自己容易记住的密码即可。


接下来安装php:

sudo apt-get install php5 php5-fpm php5-mysql php-apc

至此所有基本组件已安装完毕,可以根据需要继续安装其它可选组件等。


配置php:

首先:
sudo vim /etc/nginx/sites-available/default

在打开的文档中找到root,将其改为:

root    /home/tevenfeng/coding/php/tjurobocup

此处路径为你的php页面文件的根目录路径,比如我这里就把所有php页面放在tjurobocup文件夹下。​


同时在index一行中添加 index.php。​

然后找到以下代码块并按照下面的修改:

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

#

location ~ \.php$ {

#include snippets/fastcgi-php.conf;

## With php5-cgi alone:

#fastcgi_pass 127.0.0.1:9000;

## With php5-fpm:

fastcgi_pass unix:/var/run/php5-fpm.sock;

include fastcgi_params;

}

然后保存。


接下来修改​fastcgi_params文件:
sudo vim /etc/nginx/fastcgi_params

在该文件的末尾添加如下行:

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

保存退出。


然后修改php.ini文件:
sudo vim /etc/php5/fpm/php.ini

找到:;cgi.fix_pathinfo()=1   (大约在700行附近)

将其修改为cgi.fix_pathinfo()=0​

找到doc_root =   (大约在720行左右)

将其修改为doc_root = /home/tevenfeng/coding/php/tjurobocup  (注意,这里的路径必须与前面修改default文件中root的路径一致)。​

保存并退出。


然后重启nginx和php5-fpm:
sudo /etc/init.d/nginx restart
sudo /etc/init.d/php5-fpm restart

然后在/home/tevenfeng/coding/php/tjurobocup文件夹下新建一个index.php文件,并输入相应的测试内容,打开浏览器输入localhost测试。


Ubuntu 14.04搭建LNMP:http://www.linuxdiyf.com/linux/11900.html

CentOS 6.4用源代码安装LNMP环境:http://www.linuxdiyf.com/linux/11471.html

CentOS 7源码安装最新版LNMP环境:http://www.linuxdiyf.com/linux/10839.html

Ubuntu 14.04 LTS安装LNMP NginxPHP5(PHP-FPM)MySQL:http://www.linuxdiyf.com/linux/10659.html

CentOS 7.0下编译安装LNMP:http://www.linuxdiyf.com/linux/10550.html