阿里云的主机yum源php为5.3,但是现在很多项目均在5.4以上。虽然可以使用remi源来进行yum安装,但是安装之后,程序启动等均需要加上php54等这样的字样,让人使用观感奇特,所以在centos6上面使用编译来搭建lanmp环境
nginx的编译
基础环境包的安装
yum -y install pcre-devel openssl-devel apr-devel apr-util-devel libevent-devel
yum -y groupinstall Development Tools
下载tar包wget http://nginx.org/download/nginx-1.10.3.tar.gz
tar xvf nginx-1.10.3.tar.gz -C /usr/local
cd /usr/local/nginx-1.10.3/
相关编译参数如下
./configure --prefix=/usr/local/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--http-client-body-temp-path=/var/tmp/nginx/client_body \
--http-proxy-temp-path=/var/tmp/nginx/proxy \
--http-fastcgi-temp-path=/var/tmp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/lock/nginx \
--user=nginx --group=nginx --with-file-aio \
--with-http_ssl_module --with-http_realip_module \
--with-http_sub_module --with-http_gzip_static_module \
--with-http_stub_status_module --with-pcre
然后使用make && make install
编译安装
vim /usr/local/nginx/nginx.conf
在server
段加入以下内容
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
useradd -s /sbin/nologin -M nginx 新建nginx用户
mkdir -pv /var/tmp/nginx/client_body
chown -R nginx.nginx /var/tmp/nginx/client_body
/usr/local/nginx/sbin/nginx -t 检查语法
语法ok后使用/usr/local/nginx/sbin/nginx 启动nginx
ss -tnlp | grep 80 看nginx是否起来
php5.4的安装
官网下载php5.4的tar安装包
yum install libxml2-devel gd-devel freetype-devel libmcrypt-devel curl curl-devel
tar xvf php-5.4.44.tar.gz -C /usr/local
cd /usr/local/php-5.4.44/
./configure --prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-iconv-dir=/usr/local --with-freetype-dir\
--with-jpeg-dir --with-png-dir --with-zlib \
--with-libxml-dir=/usr --enable-xml \
--enable-bcmath --enable-shmop --enable-sysvsem \
--enable-inline-optimization --with-curl --with-curlwrappers \
--enable-mbregex --enable-fpm --enable-mbstring \
--with-mcrypt --with-gd --enable-gd-native-ttf \
--with-openssl --with-mhash --enable-pcntl \
--enable-sockets --with-ldap-sasl --with-xmlrpc \
--enable-zip --enable-soap --without-pear --with-zlib \
--enable-pdo --with-pdo-mysql --with-mysql
make && make install
cd /usr/local/php/etc
cp php-fpm.conf.default php-fpm.conf
/usr/local/php/sbin/php-fpm
ss -tnlp | grep php-fpm 查看php-fpm是否启动
验证php
在/usr/local/nginx/html中新建一个test.php测试页
vim /usr/local/nginx/html/test.php
<?php
phpinfo();
?>
访问IP/test.php 即可以查看到phpinfo信息