背景:       

阅读新闻

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

[日期:2014-05-27] 来源:imcn.me  作者:Linux [字体:  ]
 
 

最近在 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/NginxFullExample和 http://wiki.nginx.org/NginxFullExample2

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

[...]
worker_processes 4;
[...]
keepalive_timeout 2;
[...]

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

vi /etc/nginx/sites-available/default

[...]
server {
listen 80;
listen [::]:80 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 404.
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 ::1;
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 404 /404.html; # redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ .php$ {
try_files $uri =404;
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;
} # 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_PHP 和 http://forum.nginx.org/read.php?2,88845,page=3).

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

service nginx reload

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

更多详情见请继续阅读下一页的精彩内容: http://www.linuxidc.com/Linux/2014-05/102351p2.htm

ubuntu系统14.04安装php5的更多相关文章

  1. Ubuntu Kylin 14.04安装

    早听说Ubuntu Kylin对中国本地做了很多定制的工作,想搜狗输入法.WPS,还有中国日历等.昨天没事就下载了一个Kylin试用了下,使用的方法还是使用EasyBCD软件做了个硬盘安装启动,关于E ...

  2. ubuntu kylin 14.04安装搜狗输入法

    1.卸载原有的输入法,fcitx或ibus.如卸载fcitx: sudo apt-get remove fcitx*(如不需保留配置文件用purge) sudo apt-get autoremove( ...

  3. ubuntu kylin 14.04安装配置MongoDB v2.6.1(转)

    1.获取最新版本 https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.6.1.tgz 2.解压并进入bin目录 tar zxvf mongo ...

  4. ubuntu kylin 14.04安装Node.js和Famous

    默认使用软件中心安装node.js,然后参考https://famo.us/install进行安装 1.sudo apt-get install git 2.npm install -g yo gru ...

  5. Ubuntu Kylin 14.04 安装配置 jdk、eclipse、tomcat 通用

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/qq1053781225/article/details/24810107 一.安装jdk       ...

  6. ubuntu kylin 14.04安装配置redis-2.8.9(转)

    1.下载安装文件加压.编译和安装 cd /tmpwget http://download.redis.io/releases/redis-2.8.9.tar.gztar -zxf redis-2.8. ...

  7. ubuntu kylin 14.04编译openjdk-7u40

    1.ubuntu kylin 14.04安装依赖 sudo apt-get install build-essential gawk m4 libasound2-dev libcups2-dev li ...

  8. ubuntu server 14.04 LTS下搭建LAMP环境之最详细笔记之一U盘安装双系统

    前言: 一直在WIN上使用PHP,不喜欢用WAMP,每次都是手动在windows配置环境,偶尔有一次装了小红帽玩了两天,感觉不是很习惯就换了回来,过了没几天见讨论LAMP环境,于是安装了ubuntu的 ...

  9. 在Ubuntu 14.04安装和使用Docker

    Docker是一个开源软件,它可以把一个Linux应用和它所依赖的一切(比如配置文件)都封装到一个容器.然而,Docker与虚拟机不同,它使用了沙箱机制,Docker容器不运行操作系统,它共享主机上的 ...

随机推荐

  1. python爬虫之路——初识基本页面构造原理

    通过chrome浏览器的使用简单介绍网页构成 360浏览器使用右键审查元素,Chrome浏览器使用右键检查,都可查看网页代码. 网页代码有两部分:HTML文件和CSS样式.其中有<script& ...

  2. 【转】iOS开发里的Bundle是个啥玩意?!

    初学iOS开发的同学,不管是自己写的,还是粘贴的代码,或多或少都写过下面的代码 [[NSBundle mainBundle] pathForResource:@"someFileName&q ...

  3. js生成指定范围内随机数

    其现方法的核心是JavaScript的Math对象.代码如下: <!DOCTYPE html> <html lang="en"> <head> ...

  4. 机器学习十大常用算法(CITE 不会停的蜗牛 ) interesting

    算法如下: 决策树 随机森林算法 逻辑回归 SVM 朴素贝叶斯 K最近邻算法 K均值算法 Adaboost 算法 神经网络 马尔可夫 1. 决策树 根据一些 feature 进行分类,每个节点提一个问 ...

  5. shell时间变量拼接问题

    shell时间变量拼接问题 例1 ABC=ABC_`date –date='yesterday' "+%Y%m%d"`

  6. sqlite3 数据库使用

    首先,通过官网下载sqlite3.h和sqlite3.c两个文件,用于调用里面的api函数操作数据库. 这里也提供链接地址下载:http://pan.baidu.com/s/1qWzjqPY 其中里面 ...

  7. C# 获取Google Chrome的书签

    其实这个很简单,就是读取一个在用户目录里面的一个Bookmarks文件就好了. 先建立几个实体类 public class GoogleChrome_bookMark_meta_info { publ ...

  8. JS数据结构与算法--单向链表

    链表结构:链表中每个元素由一个存储元素本身的节点和一个指向下一元素的引用组成.如下所示(手画的,比较丑,懒得用工具画了,嘻嘻) 1.append方法,向链表末尾插入一个节点 2.insert(posi ...

  9. 主题模型LDA及在推荐系统中的应用

    1 关于主题模型 使用LDA做推荐已经有一段时间了,LDA的推导过程反复看过很多遍,今天有点理顺的感觉,就先写一版. 隐含狄利克雷分布简称LDA(latent dirichlet allocation ...

  10. NOIP模拟赛 抓牛

    [题目描述] 农夫约翰被通知,他的一只奶牛逃逸了!所以他决定,马上出发,尽快把那只奶牛抓回来. 他们都站在数轴上.约翰在N(O≤N≤100000)处,奶牛在K(O≤K≤100000)处.约翰有两种办法 ...