Ubuntu安装Nginx+PHP+MySQL

WBOY
Release: 2016-06-23 14:32:31
Original
935 people have browsed it

安装nginx

sudo apt-get install nginx
Copy after login

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
Copy after login

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

[编辑]配置php和mysql
[编辑]安装Php和mysql
安装php和MySQL:

sudo apt-get install php5-cli php5-cgi mysql-server php5-mysql
Copy after login

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

sudo apt-get install spawn-fcgi
Copy after login

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

server_name localhost;
Copy after login

修改index的一行修改为:

index index.php index.html index.htm;
Copy after login

去掉下面部分的注释用于支持 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;             }
Copy after login

重新启动nginx:

/etc/init.d/nginx stop /etc/init.d/nginx start
Copy after login

启动fastcgi php:

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

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

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

替换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."
Copy after login

然后运行rcconf设置php-cgi为开机自启动创建、测试phpinfo:
Copy after login

sudo vi /var/www/nginx-default/info.php
Copy after login

<?php phpinfo(); ?>
Copy after login

打开 http://localhost/info.php 。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template