准备工作:
使用yum安装可能需要的软件:
yum install openssl openssl-devel readline readline-devel libxslt-devel libxml2 libxml2-devel bzip2 bzip2-devel libcurl libcurl-devel libxslt libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel pcre-devel
yum -y install gcc-c++
=======================================================
1 进入php下载页: http://php.net/downloads.php
2 选择要下载的版本。
3 进入自定义目录,使用wget下载
wget -O php7.tar.gz http://cn2.php.net/get/php-7.0.31.tar.gz/from/this/mirror
4 解压获取源代码
tar -xvf php7.tar.gz
5 进入解压后的目录: cd php-7.0.31,并执行配置命令(如果是重新编译先执行 make clean):
[第二行 /apps/php 是指定您要安装php的路径]
./configure \
--prefix=/apps/php \
--with-config-file-path=/etc \
--enable-fpm \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--enable-pcntl \
--with-libxml-dir \
--with-xmlrpc \
--with-openssl \
--with-mcrypt \
--with-mhash \
--with-pcre-regex \
--with-sqlite3 \
--with-zlib \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--with-cdb \
--enable-dom \
--enable-exif \
--enable-fileinfo \
--enable-filter \
--with-pcre-dir \
--with-gd \
--with-openssl-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-freetype-dir \
--enable-gd-native-ttf \
--enable-gd-jis-conv \
--with-gettext \
--with-gmp \
--with-mhash \
--enable-json \
--enable-mbstring \
--enable-mbregex \
--enable-mbregex-backtrack \
--with-libmbfl \
--with-onig \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-zlib-dir \
--with-pdo-sqlite \
--with-readline \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx \
--with-libxml-dir \
--with-xsl \
--enable-zip \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-opcache \
--enable-maintainer-zts
6 执行命令
make && make install
7 如果出现类似以下错误:
undefined reference to `libiconv_open'
ld returned 1 exit status
make: *** [sapi/cli/php] Error 1
执行
ln -s /usr/local/lib/libiconv.so.2 /usr/lib64/
make ZEND_EXTRA_LIBS='-liconv'
8 配置环境变量
vi /etc/profile
在文件末尾追加:
PATH=$PATH:/apps/php/bin
export PATH
执行 source /etc/profile 使配置生效。
输入 php -v ,如果安装成功将出现版本信息。
9
进入php源码包,执行
cp php.ini-production /etc/php.ini
进入 php安装路径,复制配置文件
cd /apps/php/etc
cp php-fpm.conf.default php-fpm.conf
cd php-fpm.d/
cp www.conf.default www.conf
10 查看www.conf,如果默认配置项为
user = nginx
group = nginx
,则 创建用户与用户组并授权nginx文件夹
groupadd nginx
useradd -g nginx nginx
chown -R nginx:nginx /apps/nginx
11 启动php-fpm
进入php源码包,执行
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
/etc/init.d/php-fpm start
输入 ps -ef|grep php-fpm 查看php-fpm进程。
=================================================
nginx安装
1 进入 http://nginx.org/download/,选择合适的nginx版本
2 下载源码 wget http://nginx.org/download/nginx-1.6.3.tar.gz
3 解压 tar -zxvf nginx-1.6.3.tar.gz
4 进入解压只有的目录,执行命令:
./configure --prefix=/apps/nginx \
--with-http_ssl_module --with-http_spdy_module --with-http_stub_status_module --with-pcre
[/apps/nginx是nginx的自定义安装路径]
5 执行 make && make install
6 进入nginx安装目录下的sbin目录,执行./nginx -t
如果报错提示缺失权限,给 /apps/nginx赋权限,
执行 chmod -R 777 /apps/nginx,然后重新进入sbin目录下执行
./nginx -t,出现成功的提示即可。
====================================================
nginx 配置php
1 修改nginx/conf/nginx.conf
server配置项参考:
server {
server_name localhost;
listen 80;
root /apps/www/;
index index.php;
try_files $uri $uri/ /index.php?s=$uri&$args;
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}
2 重启nginx /apps/nginx/sbin/nginx -s reload
3 如果设置开机自启动:
1 /etc/init.d/目录下创建nignx和php-fpm对应的脚本
2 chkconfig --add /etc/init.d/nginx
3 chkconfig --add /etc/init.d/php-fpm