最近在 Ubuntu 14.04 LTS 安装 LNMP 一键安装包的时候出现了问题,PHP 5 服务没有启动,只好使用 Ubuntu 官方源进行安装:

Nginx (读音 “engine x”)免费、开源、高效的 HTTP 服务。Nginx 是以稳定著称,功能丰富,结构简单,低资源消耗。本教程将演示如何在ubuntu 14.04 服务器中安装 nginx、PHP5(php-fpm)、MySQL。

----------------------------------------分割线----------------------------------------

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

----------------------------------------分割线----------------------------------------

1 安装前提示

本文采用的主机名称: server1.example.com ,IP地址: 192.168.0.100。可能与你的主机有所不同,自行修改。

安装中我们使用root账户,先进行用户切换:

sudo su

2 安装 MySQL 5 数据库

安装 MySQL 运行命令:

apt-get install mysql-server mysql-client

安装过程中会询问建立 Root 账户密码,连续输入两次:

New password for the MySQL “root” user: <– 输入你的密码
Repeat password for the MySQL “root” user: <– 再输入一次

3 安装 Nginx

在安装 Nginx 之前,如果你已经安装 Apache2 先删除在安装 nginx:

service apache2 stop
update-rc.d -f apache2 remove
apt-get remove apache2

apt-get install nginx

启动 nginx 服务:

service nginx start

试试安装是否成功,在浏览器输入IP或主机地址 (e.g. http://192.168.0.100),如下图所示,说明安装成功:

在 Ubuntu 14.04 中默认的根目录为 /usr/share/nginx/html.

4 安装 PHP5

我们必须通过 PHP-FPM 才能让PHP5正常工作,安装命令:

apt-get install php5-fpm

php-fpm是一个守护进程。

5 配置 nginx

使用Vi打开配置文件/etc/nginx/nginx.conf :

vi /etc/nginx/nginx.conf

配置不是很容易明白,可以参考: http://wiki.nginx.org/NginxFullExamplehttp://wiki.nginx.org/NginxFullExample2

我们需要调整工作进程数设置,如下面的值设置:

[...]
worker_processes ;
[...]
keepalive_timeout ;
[...]

默认虚拟主机设置文件 /etc/nginx/sites-available/default 按如下设置:

vi /etc/nginx/sites-available/default

[...]
server {
listen ;
listen [::]: default_server ipv6only=on; root /usr/share/nginx/html;
index index.php index.html index.htm; # Make site accessible from http://localhost/
server_name _; location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a .
try_files $uri $uri/ /index.html;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
} location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
allow ::;
deny all;
} # Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
#location /RequestDenied {
# proxy_pass http://127.0.0.1:8080;
#} #error_page /.html; # redirect server error pages to the static page /50x.html
#
error_page /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:
#
location ~ .php$ {
try_files $uri =;
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:;
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
} # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /.ht {
deny all;
}
}
[...]

取消同时侦听 IPv4 IPv6 的80端口。

server_name _; 默认主机名 (当然你可以修改,例如修改为: www.example.com).

index主页这一行我们加入 index.php。

PHP 重要配置配置 location ~ .php$ {} 这几行我们需要启动,反注释掉。另外再添加一行:try_files $uri =404。

(其他配置查看http://wiki.nginx.org/Pitfalls#Passing_Uncontrolled_Requests_to_PHPhttp://forum.nginx.org/read.php?2,88845,page=3).

保存文件并重新加载 nginx 命令:

service nginx reload

如果加载失败,直接用删除所有配置内容,用上面的信息替换。

打开配置文件 /etc/php5/fpm/php.ini…

vi /etc/php5/fpm/php.ini

… 如下设置 cgi.fix_pathinfo=0:

[...]
; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI. PHP's
; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok
; what PATH_INFO is. For more information on PATH_INFO, see the cgi specs. Setting
; this to will cause PHP CGI to fix its paths to conform to the spec. A setting
; of zero causes PHP to behave as before. Default is . You should fix your scripts
; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.
; http://php.net/cgi.fix-pathinfo
cgi.fix_pathinfo=
[...]

重新加载 PHP-FPM:

service php5-fpm reload

现在创建一个探针文件保存在 /usr/share/nginx/html目录下

vi /usr/share/nginx/html/info.php

<?php
phpinfo();
?>

浏览器下访问探针文件 (e.g. http://192.168.0.100/info.php):

正如你看到的 PHP5 正在运行,并且是通过 FPM/FastCGI,向下滚动,我们看看那些模块已经启动,MySQL是没有列出这意味着我们没有MySQL支持PHP5。

6 下面让 PHP5 支持 MySQL

先搜索一下,看看那些模块支持:

apt-cache search php5

然后使用下面的命令安装:

apt-get install php5-mysql php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl

APC是一个自由和开放的PHP操作码缓存器缓存和优化PHP的中间代码。这是类似于其他PHP操作码cachers,如eAccelerator、XCache。这是强烈建议有一个安装加速你的PHP页面。

使用下面的命令安装 APC:

apt-get install php-apc

有时安装完php模块,不能重启,要

sevice php5-fprm start

现在重新加载 PHP-FPM:

service php5-fpm reload

刷新 http://192.168.0.100/info.php 向下滚动看看模块是否支持:

7 让 PHP-FPM 使用 TCP 连接

默认情况下 PHP-FPM 侦听的是 /var/run/php5-fpm.sock,要让 PHP-FPM 使用 TCP 连接,需要打开编辑配置文件 /etc/php5/fpm/pool.d/www.conf…

vi /etc/php5/fpm/pool.d/www.conf

按照下面的修改信息

[...]
;listen = /var/run/php5-fpm.sock
listen = 127.0.0.1:
[...]

这将使php-fpm侦听端口9000上的IP 127.0.0.1(localhost)。确保你使用的端口不在你的系统上使用。

重新加载 PHP-FPM:

service php5-fpm reload

下面通过配置 nginx 修改主机,更改这一行注释掉 fastcgi_pass unix:/var/run/php5-fpm.sock; 这一行反注释 fastcgi_pass 127.0.0.1:9000;,按照下面的设置:

vi /etc/nginx/sites-available/default

[...]
location ~ .php$ {
try_files $uri =;
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:;
# With php5-fpm:
#fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
[...]

重新加载 nginx:

service nginx reload

8 CGI/Perl Scripts

如果你想 Nginx支持 CGI/Perl 脚本服务,可阅读此教程 Serving CGI Scripts With Nginx On Debian Squeeze/Ubuntu 11.04

推荐的方法是使用fcgiwrap(4章)

9 相关参考链接:

转载自(http://www.linuxidc.com/Linux/2014-05/102351.htm

使用thinkphp3.2開發遇到了如下情況:

Fatal error: Call to undefined function mcrypt_get_block_size()

/etc/php5/mods-available/mcrypt.ini

復制到

/etc/php5/fpm/conf.d/mcrypt.ini

重啓

service php5-fpm restart

service nginx restart

ubuntu apt-get 安装 lnmp的更多相关文章

  1. Ubuntu 14.04 安装LNMP(nginx/1.12.1+php7.1.9+mysql5.7.19)环境

    这篇教程中,我们将讨论怎样在Ubuntu 14.04搭建LNMP环境 1 安装Nginx 首先我们要更新apt源 sudo add-apt-repository ppa:nginx/stable  s ...

  2. ubuntu 16 server 安装lnmp所需依赖

    安装 1.nginx build-essential libc6 libpcre3 libpcre3-dev libssl-dev zliblg zliblg-dev lab-base 依赖库: ap ...

  3. ubuntu 源码安装 lnmp 环境

    准备篇 下载软件包 1.下载nginx http://nginx.org/download/nginx-1.2.0.tar.gz 2.下载pcre  (支持nginx伪静态) ftp://ftp.cs ...

  4. ubuntu 安装lnmp、swoole、redis

    1.安装lnmp (此处也可用于centos) 登陆服务器后  cd /var screen -S lnmp wget http://soft.vpser.net/lnmp/lnmp1.5.tar.g ...

  5. 阿里云Ubuntu安装LNMP环境之PHP7

    在QQ群很多朋友问阿里云服务器怎么安装LNMP环境,怎么把项目放到服务器上面去,在这里,我就从头开始教大家怎么在阿里云服务器安装LNMP环境. 在这之前,我们先要知道什么是LNMP. L: 表示的是L ...

  6. 阿里云Ubuntu安装LNMP环境之Mysql

    在QQ群很多朋友问阿里云服务器怎么安装LNMP环境,怎么把项目放到服务器上面去,在这里,我就从头开始教大家怎么在阿里云服务器安装LNMP环境. 在这之前,我们先要知道什么是LNMP. L: 表示的是L ...

  7. 阿里云Ubuntu安装LNMP环境之Nginx

    在QQ群很多朋友问阿里云服务器怎么安装LNMP环境,怎么把项目放到服务器上面去,在这里,我就从头开始教大家怎么在阿里云服务器安装LNMP环境. 在这之前,我们先要知道什么是LNMP. L: 表示的是L ...

  8. Ubuntu下安装LNMP之独立添加php扩展模块

    使用php的过程中,发现某个扩展没有添加,又不想重新编译php,这个时候我们就需要单独添加需要的扩展模块. 下面以mysqli扩展模块为例,具体介绍安装步骤. 1.安装mysql 具体参考:Ubunt ...

  9. Ubuntu下安装LNMP之php7的安装并配置Nginx支持php及卸载php

    据了解,php7是比之前的版本性能快很多的.http://php.net/get/php-7.2.2.tar.gz/from/a/mirror 安装前也可提前将相关依赖库安装好,或者在安装php时若安 ...

随机推荐

  1. Loadrunner如何遍历一个页面中的url并进行访问?

    最近在网上到一个关于loadrunner遍历一个页面中的url并进行访问的脚本,就把它用我们自己的项目实践了一下,发现有一点不完善. 原始版本: Action(){char temp[64];int ...

  2. SQL语句:语法错误(操作符丢失)在查询表达式中

    所谓操作符丢失,应该是你在拼接SQL语句是少了关键词或者分隔符,导致系统无法识别SQL语句.建议:1.监控SQL语句,看看哪里出现问题:断点看下最后的sql到底是什么样子就知道了,另外你可以把这段sq ...

  3. 复习及总结--.Net线程篇(3)

    不幸的发现,原来多线程的东西还有好多. 不只是一个Thread就能把事情做完的,好吧,孤陋寡闻了 这里总结下  复习及总结--.Net线程篇(2)里的两个概念AppDomain和ThreadPool ...

  4. 说说M451例程讲解之串口

    /**************************************************************************//** * @file main.c * @ve ...

  5. [SDOI2016 Round1] 征途[斜率优化]

    2225. [SDOI2016 Round1] 征途 ★★★☆   输入文件:menci_journey.in   输出文件:menci_journey.out   简单对比时间限制:1 s   内存 ...

  6. Linux上查看和修改字符集

    author :headsen chen date: 2018-05-14  16:20:30 一·查看字符集 字符集在系统中体现形式是一个环境变量,看当前终端使用字符集的有以下几种方式: 1: 1 ...

  7. [转]Mac下cocos2dx-3.2+Xcode环境配置和项目创建

    原文:http://blog.csdn.net/u012200908/article/details/38070885 这是有关环境配置的第二篇教程,第一篇讲的是win8下的环境配置.这里我们使用C+ ...

  8. SQL使用union合并查询结果(转载)

    1.UNION的作用  UNION 指令的目的是将两个 SQL 语句的结果合并起来.从这个角度来看, UNION 跟 JOIN 有些许类似,因为这两个指令都可以由多个表格中撷取资料. UNION 的一 ...

  9. Python全栈day21(作业针对一个文件进行查询修改删除的操作练习)

    需求,有一个配置文件test.conf内容如下 backend www1 server 1 server 2 backend www2 server 3 server 4 add [{'backend ...

  10. mysql 字符集研究

    一.创建一个测试数据库 及一个测试用的表.均使用默认的编码方式. show variables like 'char%': mysql> show variables like 'char%'; ...