一、准备工作跟lamp一样
二、安装mysql跟lamp一样
三、安装php
1、创建php用户
useradd -s /sbin/nologin php-fpm
2、下载php程序并上传到/usr/local/src
3、解压
tar -zxvf php-5.4.36.tar.gz
4、配置编译参数
进入php目录
cd php-5.4.36
./configure \ --prefix=/usr/local/php \ --with-config-file-path=/usr/local/php/etc \ --enable-fpm \ --with-fpm-user=php-fpm \ --with-fpm-group=php-fpm \ --with-mysql=/usr/local/mysql \ --with-mysql-sock=/tmp/mysql.sock \ --with-libxml-dir \ --with-gd \ --with-jpeg-dir \ --with-png-dir \ --with-freetype-dir \ --with-iconv-dir \ --with-zlib-dir \ --with-mcrypt \ --enable-soap \ --enable-gd-native-ttf \ --enable-ftp \ --enable-mbstring \ --enable-exif \ --disable-ipv6 \ --with-pear \ --with-curl \ --with-openssl
5、提示报错
mcrypt.h not found. Please reinstall libmcrypt
6、下载rpm 包并安装
rpm -ivh libmcrypt-2.5.8-9.el6.x86_64.rpm libmcrypt-devel-2.5.8-9.el6.x86_64.rpm
7、重新编译参数并编译
make
8、安装
make install
9、拷贝配置文件
cp php.ini-production /usr/local/php/etc/php.ini
10、修改php-fpm.conf配置文件 cd /usr/local/php/etc/ mv php-fpm.conf.default php-fpm.conf 使用/usr/local/php/sbin/php-fpm -t查看配置文件php-fpm.conf有没有错 11、设置启动脚本并启动 cp /usr/local/src/php-5.4.36/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm chmod 755 /etc/init.d/php-fpm chkconfig php-fpm on service php-fpm start
四、安装nginx
1、到官网下载Nginx并上传到src目录
2、解压
tar -zxvf nginx-1.6.3.tar.gz
3、配置编译参数
cd nginx-1.6.3
./configure \
--prefix=/usr/local/nginx \
--with-pcre
注释:--with-pcre是用来处理正则的
4、提示出错the HTTP rewrite module requires the PCRE library.
直接用yum install
yum install -y pcre-devel
5、重新配置编译参数后编译make
6、安装 make install
7、启动 /usr/local/nginx/sbin/nginx
查看启动 ps aux |grep nginx
五、测试php解析nginx
1、进入nginx配置文件开户php相关设置
vim /usr/local/nginx/conf/nginx.conf
找到以下位置
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
改成如下
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
备注:/usr/local/nginx/html网站默认的根目录
2、测试配置是否正确
/usr/local/nginx/sbin/nginx -t
3、在/usr/local/nginx/下创建info.php文件
cd /usr/local/nginx/
vim info.php
<?php
phpinfo();
?>
4、重新加载配置文件
/usr/local/nginx/sbin/nginx -s reload
如果提示错误:invalid PID number "" in "/usr/local/nginx/logs/nginx.pid
使用以下命令:
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
转载于:https://blog.51cto.com/riverxyz/1783978