Home > Backend Development > PHP Tutorial > ubuntu下安装php+nginx+mysql

ubuntu下安装php+nginx+mysql

WBOY
Release: 2016-06-23 14:28:58
Original
842 people have browsed it

刚到公司配置ununtu的php环境,首先使用了php+apache,安装很简单,也不需要什么配置。在网上看到nginx不错,发现好多网站都用的nginx。于是乎,把apache撤了,装nginx。那可是装的我心都碎了。

安装nginx,很简单:sudo apt-get install nginx

然后是安装php+mysql,也很简单的:apt-get install php5-cli php5-cgi mysql-server-5.0 php5-mysql

因为把php+nginx联系起来需要fast-cgi才行,所以我们需要安装它.我们只需要安装lighttpd即可,然后把里面的fast-cgi单独提取出来:

sudo apt-get install lighttpd

rconf //这里是开机启动配置,去掉lighttpd的开机自动启动

然后配置nginx的配置文件,新版本在/etc/nginx/conf下,打开nginx.conf:

server_name  xxx.xxx.xx.xxx;//你的主机地址,如果需要改端口在上面改listen

location / {
root   /var/www;//根目录
index  index.php index.html index.htm //支持php文件
}
location ~ \.php$ {
root           /var/www;
fastcgi_pass   127.0.0.1:9000;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME  /var/www$fastcgi_script_name;
include        fastcgi_params;
}

然后重新启动nginx ,一般是sudo /etc/init.d/nginx restart 我安装的新版本MS不行,就用sudo /etc/nginx/sbin/nginx -s reload

启动fast-cgi

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

如何让php fast-cgi重启呢,那么我们需要在/etc/init.d/下 把nginx下的php-cgi复制过来,新版本好像没有 总之修改init.d下的php-cgi:

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/spawn-fcgi
DAEMON_OPTS=”-a 127.0.0.1 -p 9000 -C 10 -u www-data -f /usr/bin/php-cgi”
NAME=php-cgi

stop)
echo -n “Stopping $DESC: ”
pkill -9 php-cgi //主要是kill掉php-cgi的进程
echo “$NAME.”
;;
DESC=php-cgi

然后运行rconf,设置php-cgi开机启动

然后基本上就差不多了。php的配置文件在/etc/php5/cgi下的php.inil里,修改后要重启php-cgi:

sudo /etc/init.d/php-cgi start
sudo /etc/init.d/php-cgi stop

最后输入在浏览器看看成功没~~

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