当前位置: > Ubuntu >

ubuntu下nginx+php+mysql安装配置

时间:2016-04-03 21:37来源:linux.it.net.cn 作者:IT

添加源:

sudo vi /etc/apt/sources.list
lucid(10.04)的源添加如下:
代码:
deb http://archive.ubuntu.com/ubuntu/ lucid main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ lucid-security main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ lucid-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ lucid-backports main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ lucid main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ lucid-security main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ lucid-updates main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ lucid-backports main restricted universe multiverse
deb http://ppa.launchpad.net/nginx/stable/ubuntu lucid main
deb http://ppa.launchpad.net/brianmercer/php/ubuntu lucid main

maverick(10.10)的源:
代码:
deb http://archive.ubuntu.com/ubuntu/ maverick main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ maverick-security main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ maverick-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ maverick-backports main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ maverick main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ maverick-security main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ maverick-updates main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ maverick-backports main restricted universe multiverse
deb http://ppa.launchpad.net/nginx/stable/ubuntu maverick main

最后一行为nginx的ppa源,需要添加key,在终端运行:
代码:
sudo apt-key adv --keyserver keyserver.Ubuntu.com --recv-keys C300EE8C

3、更新
代码:
sudo apt-get update
 

安装nginx

sudo apt-get install nginx

Ubuntu安装之后的文件结构大致为:

  • 所有的配置文件都在/etc/nginx下,并且每个虚拟主机已经安排在了/etc/nginx/sites-available下
  • 程序文件在/usr/sbin/nginx
  • 日志放在了/var/log/nginx中
  • 并已经在/etc/init.d/下创建了启动脚本nginx
  • 默认的虚拟主机的目录设置在了/var/www/nginx-default

[编辑]启动nginx

sudo /etc/init.d/nginx start

然后就可以访问了,http://localhost/ , 一切正常!如果不能访问,先不要继续,看看是什么原因,解决之后再继续。

nginx默认页面

[编辑]配置php和mysql

[编辑]安装Php和mysql

安装php和MySQL:

sudo apt-get install php5-cli php5-cgi mysql-server php5-mysql

[编辑]安装FastCgi

/usr/bin/spawn-fcgi这个文件来管理 FastCgi,它原属于lighttpd这个包里面,但 9.10 后,spawn-fcgi 被分离出来单独成包:

sudo apt-get install spawn-fcgi

[编辑]配置 nginx

修改nginx的配置文件:/etc/nginx/sites-available/default 修改主机名:

server_name localhost;

修改index的一行修改为:

index index.php index.html index.htm;

去掉下面部分的注释用于支持 php 脚本:

location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/nginx-default$fastcgi_script_name; include /etc/nginx/fastcgi_params; }

重新启动nginx:

/etc/init.d/nginx stop /etc/init.d/nginx start

启动fastcgi php:

spawn-fcgi -a 127.0.0.1 -p 9000 -C 10 -u www-data -f /usr/bin/php-cgi

为了让php-cgi开机自启动:

cd /etc/init.d cp nginx php-cgi vim php-cgi

替换nginx为php-cgi


并修改相应部分为:

DAEMON=/usr/bin/spawn-fcgi DAEMON_OPTS="-a 127.0.0.1 -p 9000 -C 10 -u www-data -f /usr/bin/php-cgi" ... stop) echo -n "Stopping $DESC: " pkill -9 php-cgi echo "$NAME."

然后运行rcconf设置php-cgi为开机自启动

创建、测试phpinfo:

sudo vi /var/www/nginx-default/info.php
<?php phpinfo(); ?>

打开 http://localhost/info.php 

 
Nginx phpinfo页面



(责任编辑:IT)
------分隔线----------------------------
栏目列表
推荐内容