ubuntu+nginx+php+mysql安装配置方法命令

精选文章 2015年12月3日 5.35K

1、先更新ubuntu系统

更新命令

sudo apt-get update /*只更新软件列表*/

sudo apt-get upgrade /*会更新整个软件和系统慎用*/

2、更新和安装update and install

sudo apt-get update

sudo apt-get install nginx

3、启动nginx

sudo /etc/init.d/nginx start

4、check version

nginx -v

5、配置php+mysql

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

6、安装FastCgi

sudo apt-get install spawn-fcgi

7、配置nginx

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

server_name localhost;

B、修改index的一行,添加index.php

index index.php index.html index.htm;

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

location ~ .php$ {    include /etc/nginx/fastcgi_params; #需放在第一行,否则会出错    fastcgi_pass 127.0.0.1:9000;    fastcgi_index index.php;    fastcgi_param SCRIPT_FILENAME /var/www/nginx-default$fastcgi_script_name; }

8、 重新启动nginx

/etc/init.d/nginx stop

/etc/init.d/nginx start

9、启动fastcgi php

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

10、nginx提示502 错误

nginx 502 Bad Gateway没有启动,启动命令是:

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

11、设置开机自启动

Ubuntu开机之后会执行/etc/rc.local文件中的脚本

所以我们可以直接在/etc/rc.local中添加启动脚本。

spawn-fcgi -a 127.0.0.1 -p 9000 -C 10 -u www-data -f /usr/bin/php-cgi 添加到语句: exit 0

前面才行

12、no input file specified错误

sudo vi /etc/nginx/sites-available/default

其中这个字段

location ~ \ .php$ {

root html;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME /var/www/nginx-default$fastcgi_script_name;

include fastcgi_params;

}

注意

若是出现 No input file specified 表示下边这个配置不正确将(/var/www/nginx-default改完你网站设置的目录即可,我的目录是:/var/www/html)

fastcgi_param SCRIPT_FILENAME /var/www/nginx-default$fastcgi_script_name;

/var/www/nginx-default 改为你的网站根目录,一般就是改成这个。

server 字段下root 目录和网站根目录保持一致

13、PHP的重启

由于安装了Spawn-FCGI因此要先杀死相对于的PHP进程进而重启PHP

查看PHP进程:ps -ef | grep php

xcar@xcar:/usr/bin$ ps -ef|grep php
xcar     24539  1661  0 17:35 ?        00:00:00 /usr/bin/php-cgi
xcar     24540 24539  0 17:35 ?        00:00:00 /usr/bin/php-cgi
xcar     24541 24539  0 17:35 ?        00:00:00 /usr/bin/php-cgi
xcar     24542 24539  0 17:35 ?        00:00:00 /usr/bin/php-cgi
xcar     24543 24539  0 17:35 ?        00:00:00 /usr/bin/php-cgi
xcar     24544 24539  0 17:35 ?        00:00:00 /usr/bin/php-cgi

xcar     24659 15273  0 17:39 pts/2    00:00:00 grep –color=auto php

spawn重启:

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

参数含义如下:
-f 指定调用FastCGI 的进程的执行程序位置,根据系统上所装的PHP的情况具体设置
-a 绑定到地址addr
-p 绑定到端口port
-s 绑定到unix socket的路径path
-C 指定产生的FastCGI 的进程数,默认为5( 仅用于PHP)
-P 指定产生的进程的PID文件路径

-u 和-g FastCGI 使用什么身份(-u 用户 -g 用户组) 运行,Ubuntu下可以使用www-data,其他的根据情况配置,如nobody、apache

14、PHP.ini  GD库的安装

ubuntu下只需执行这个命令即可:sudo apt-get install php5-gd

 


关注微信公众号『PHP学习网

第一时间了解最新网络动态
关注博主不迷路~

版权声明:转载请注明 PHP学习网 » ubuntu+nginx+php+mysql安装配置方法命令
分享到:
赞(0)

文章评论

您需要之后才可以评论
0点赞 1评论 收藏 QQ分享 微博分享

PHP学习网

PHP学习网