ubuntu14.04配置lnmp

看到了一片讲解ubuntu下安装lnmp的文章,跟着一步步的来,竟然很顺利的成功了,将文章复制如下,原著勿怪

一、操作步骤

1.安装Nginx

sudo apt-get install update
sudo apt-get install nginx
2.测试Nginx,如果显示如下图则代表安装成功

ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//' #查看本机IP地址
curl http://127.0.0.1 或者 curl http://本机ip
curl nginx

3.安装MySQL

sudo apt-get install mysql-server
# 连续输入两次相同的密码
4.安装PHP

sudo apt-get install php5-fpm php5-mysql
5.配置PHP,修改php.ini文件

# 备份php.ini文件
cp /etc/php5/fpm/php.ini /etc/php5/fpm/php.ini.back
# 取消有安全隐患的pathinfo模式
vim /etc/php5/fpm/php.ini
# 将cgi.fix_pathinfo=1 设置为 cgi.fix_pathinfo=0
cgi.fix_pathinfo=0
#启动php-fpm
sudo service php5-fpm restart
6.配置Nginx让其使用php-fpm进程

#备份/etc/nginx/sites-available/default文件
cp /etc/nginx/sites-available/default /etc/nginx/sites-available/default.back
#修改defalut文件内容如下
server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

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

    server_name server_domain_name_or_IP;

    location / {
        try_files $uri $uri/ =404;
    }

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }
	
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}
7.重启nginx服务器

sudo service nginx restart
8.在/usr/share/nginx/html/里面建立info.php写入如下内容

<?php
	phpinfo();
?>
浏览器输入: http://ip/info.php
phpinfo显示

二、写在最后

这篇文章只是简单的介绍了Nginx+php-fpm的安装。如果你对Linux有更深入的研究,完全可以使用手动安装源码包的方式进行安装和配置。当然,你看到这篇文章的时候应该已经知道了Nginx的优秀之处了,后续文章会继续剖析Nginx的经典配置和Nginx与Apahce的异同。

Ubuntu 14.04 LTS 安装 LNMP Nginx\PHP5 (PHP-FPM)\MySQL  http://www.linuxidc.com/Linux/2014-05/102351.htm

Ubuntu 13.04 安装 LAMP\Vsftpd\Webmin\phpMyAdmin 服务及设置 http://www.linuxidc.com/Linux/2013-06/86250.htm

CentOS 6.4 下的LNMP 生产环境搭建及安装脚本 http://www.linuxidc.com/Linux/2013-11/92428.htm

生产环境实用之LNMP架构的编译安装+SSL加密实现 http://www.linuxidc.com/Linux/2013-05/85099.htm

LNMP 全功能编译安装 for CentOS 6.3笔记 http://www.linuxidc.com/Linux/2013-05/83788.htm

CentOS 6.3 安装LNMP (PHP 5.4,MyySQL5.6) http://www.linuxidc.com/Linux/2013-04/82069.htm

在部署LNMP的时候遇到Nginx启动失败的2个问题 http://www.linuxidc.com/Linux/2013-03/81120.htm

Ubuntu安装Nginx php5-fpm MySQL(LNMP环境搭建) http://www.linuxidc.com/Linux/2012-10/72458.htm

  最后在执行composer时候遇到问题,报错找不到mcrypt,一顿Google,终于找到解决办法,也粘贴如下

Try this:

sudo updatedb 
locate mcrypt.ini
Should show it located at /etc/php5/mods-available

locate mcrypt.so
Edit mcrypt.ini and change extension to match the path to mcrypt.so, example:

extension=/usr/lib/php5/20121212/mcrypt.so
Now this:

php5enmod mcrypt - (optional since its already enabled during phpmyadmin setup)
Verify that new files exists here (they should be auto created from the issue above)

ls -al /etc/php5/cli/conf.d/20-mcrypt.ini
ls -al /etc/php5/apache2/conf.d/20-mcrypt.ini
Otherwise do the following

Create symbol links now

ln -s /etc/php5/mods-available/mcrypt.ini /etc/php5/cli/conf.d/20-mcrypt.ini
ln -s /etc/php5/mods-available/mcrypt.ini /etc/php5/apache2/conf.d/20-mcrypt.ini
Restart Apacahe

service apache2 restart

终于解决!  

posted @ 2015-11-26 16:38  lizcao  阅读(247)  评论(0编辑  收藏  举报