Ubuntu中配置nginx + php + mysql服务器

作者:袖梨 2022-06-30

1.安装php5

 代码如下 复制代码

apt-get install php-pear php5-cli php5-common php5-cgi php5-mysql php5-gd php5-dev

2.安装mysql5

 代码如下 复制代码
apt-get install mysql-server mysql-client libipc-sharedcache-perl

3.安装nginx

 代码如下 复制代码
apt-get install nginx

配置nginx如下

 代码如下 复制代码
sudo vi /etc/nginx/sites-available/default

修改点如下

 代码如下 复制代码
#这行增加index.php为默认文件
index index.php index.html index.htm;

启用fastcgi处理php脚本

 代码如下 复制代码

location ~ .php$ {
fastcgi_split_path_info ^(.+.php)(/.+)$;
#       # NOTE: You should have “cgi.fix_pathinfo = 0;” in php.ini
#       # With php5-cgi alone:
fastcgi_pass 127.0.0.1:9000;
#       # With php5-fpm:
#       fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}

4.创建fastcgi的控制脚本

 代码如下 复制代码
sudo vi /etc/init.d/php-cgi

内容如下

 代码如下 复制代码
#!/bin/bash
BIND=127.0.0.1:9000
USER=www-data
PHP_FCGI_CHILDREN=15
PHP_FCGI_MAX_REQUESTS=1000
PHP_CGI=/usr/bin/php-cgi
PHP_CGI_NAME=`basename $PHP_CGI`
PHP_CGI_ARGS=”- USER=$USER PATH=/usr/bin PHP_FCGI_CHILDREN=$PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS=$PHP_FCGI_MAX_REQUESTS $PHP_CGI -b $BIND”
RETVAL=0
start() {
echo -n “Starting PHP FastCGI: ”
start-stop-daemon –quiet –start –background –chuid “$USER” –exec /usr/bin/env — $PHP_CGI_ARGS
RETVAL=$?
echo “$PHP_CGI_NAME.”
}
stop() {
echo -n “Stopping PHP FastCGI: ”
killall -q -w -u $USER $PHP_CGI
RETVAL=$?
echo “$PHP_CGI_NAME.”
}
case “$1″ in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo “Usage: php-fastcgi {start|stop|restart}”
exit 1
;;
esac
exit $RETVAL

给/etc/init.d/php-cgi加上执行权限

 代码如下 复制代码
sudo chmod +x /etc/init.d/php-cgi

启动php-cgi进程

 代码如下 复制代码
sudo /etc/init.d/php-cgi start

要让php-cgi随系统开机启动,可以通过如下命令

 代码如下 复制代码

sudo update-rc.d php-cgi defaults 25

相关文章

精彩推荐