Linux搭建PHP服务
1.安装软件依赖包
yum -y install gd libxml2-devel libjpeg-devel libpng-devel
2.复制php压缩包
rz(php…….tar.gz)
3.解压压缩包
tar xf php-5.3.28.tar.gz -C /usr/src/
4.进入到软件目录
cd /usr/src/php-5.3.28/
5.编译安装PHP
./configure --prefix=/usr/local/php5 --with-gd --with-zlib --with-mysql=/usr/local/mysql --with-config-file-path=/usr/local/php5 --enable-mbstring --enable-fpm --with-jpeg-dir=/usr/lib && make && make install
6.复制文件
cp php.ini-production /usr/local/php5/php.ini
ln -s /usr/local/php5/bin/* /usr/local/bin/
ln -s /usr/local/php5/sbin/* /usr/local/sbin/
7.安装优化模块
cd (回到根目录下)
rz (Zend…….tar.gz)
8.解压压缩包
tar xvf ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz -C /usr/src
9.复制.so文件
cp /usr/src/ZendGuardLoader-php-5.3-linux-glibc23-x86_64/php-5.3.x/ZendGuardLoader.so /usr/local/php5/lib/php/
10.修改主配置文件
vim /usr/local/php5/php.ini
(末行添加):
zend_extension=/usr/local/php5/lib/php/ZendGuardLoader.so
zend_loader.enable=1
11.配置支持环境
cd /usr/local/php5/etc/
12.复制主配置文件
cp php-fpm.conf.default php-fpm.conf
13.创建php用户
useradd -M -s /sbin/nologin php
14.修改主配置文件
vim php-fpm.conf
修改内容:
25行:pid = run/php-fpm.pid
149行:user = php
150行:group = php
246行:pm.start_servers = 20
251行:pm.min_spare_servers = 5
256行:pm.max_spare_servers = 35
241行:pm.max_children = 50
15.启动php服务
/usr/local/sbin/php-fpm
16.查看端口
netstat -anpt |grep php-fpm
17.修改Nginx服务脚本
vim /etc/init.d/nginx
修改内容:
#!/bin/bash
# chkconfig: 2345 99 20
# description: Nginx Server Control Script
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
PROG_FPM="/usr/local/sbin/php-fpm"
PIDF_FPM="/usr/local/php5/var/run/php-fpm.pid"
case "$1" in
start)
$PROG
$PROG_FPM
;;
stop)
kill -s QUIT $(cat $PIDF)
kill -s QUIT $(cat $PIDF_FPM)
;;
restart)
$0 stop
$0 start
;;
reload)
kill -s HUP $(cat $PIDF)
;;
*)
echo "Usage: $0 (start|stop|restart|reload)"
exit 1
esac
exit 0
18.配置Nginx支持PHP解析
vim /usr/local/nginx/conf/nginx.conf
替换内容:
server {
listen 80;
server_name localhost;
charset utf-8;
location / {
root html;
index index.php index.html index.htm;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}
}
19.重新加载nginx服务
killall -HUP nginx
20.创建测试页,PHP能否正常解析
vim /usr/local/nginx/html/php.php
内容:
<?php
phpinfo();
?>
21.编写数据库测试页
vim /usr/local/nginx/html/mysql.php
内容:
<?php
$link=mysqli_connect('localhost','root','设置的mysql密码');
if($link) echo "<h1>恭喜你,连接成功!!</h1>";
mysqli_close();
?>
通过网页进行测试