Home >Database >Mysql Tutorial >Ubuntu安装Nginx+PHP+MySQL_MySQL

Ubuntu安装Nginx+PHP+MySQL_MySQL

WBOY
WBOYOriginal
2016-06-01 13:10:20968browse

UbuntuNginx

安装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/ , 一切正常!如果不能访问,先不要继续,看看是什么原因,解决之后再继续。

[编辑]配置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 。

Statement:
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