创建 /data/soft 目录
mkdir /data/soft -p
cd /data/soft
安装依赖包
yum install gcc libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel m4 autoconf libzip
安装nginx
yum install nginx -y
下载最新版php
wget http://cn2.php.net/distributions/php-7.1.6.tar.gz
解压
tar -xzf php-7.1.6.tar.gz
编译配置
(如果出现错误,基本都是上一步的依赖文件没有安装所致)
嫌麻烦的可以从这一步起参考PHP官方安装说明:
http://php.net/manual/zh/install.unix.nginx.php
cd php-7.1.6/
./configure \
--prefix=/usr/local/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 \
--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 \
--enable-ftp \
--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=no
编译&安装
make && make install
配置环境变量
vi /etc/profile
在末尾追加
PATH=$PATH:/usr/local/php/bin
export PATH
执行命令使得改动立即生效
source /etc/profile
配置php-fpm
cp php.ini-production /etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
启动php-fpm
/etc/init.d/php-fpm start || service php-fpm start
启动nginx
service nginx start
安装redis 扩展
cd /data/soft
wget http://pecl.php.net/get/redis-3.1.2.tgz
tar -xzf redis-3.1.2.tgz
cd redis-3.1.2
phpize
./configure
make && make install
修改php.ini 加入redis.so
vi /etc/php.ini
加入下面的扩展
extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/redis.so
service php-fpm restart
安装 swoole 扩展
cd /data/soft
wget http://pecl.php.net/get/swoole-1.9.14.tgz
tar -xzf swoole-1.9.14.tgz
cd swoole-1.9.14/
phpize
./configure
make && make install
修改php.ini 加入swoole.so
vi /etc/php.ini
加入下面的扩展
extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/swoole.so
创建目录 /data/*
mkdir /data/cert
mkdir /data/log
mkdir /data/log/nginx
chown nginx.nginx /data/log/nginx -R
mkdir /data/web
配置vhost
vi /etc/nginx/conf.d/pre.xx.com.conf
server {
listen 443 ;
ssl on;
ssl_certificate /data/cert/pre.xx.com/1_pre.xx.com_bundle.crt;
ssl_certificate_key /data/cert/pre.xx.com/2_pre.xx.com.key;
server_name pre.xx.com;
root /data/web/pre.xx.com/public/;
include /etc/nginx/default.d/*.conf;
location / {
index index.php index.html;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
break;
}
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
access_log /data/log/nginx/$host.access.log main;
}