更新yum
yum update --skip-broken
安装相关依赖库
yum -y install php-mcrypt libmcrypt libmcrypt-devel libxml2-devel openssl-devel libcurl-devel libjpeg.x86_64 libpng.x86_64 freetype.x86_64 libjpeg-devel.x86_64 libpng-devel.x86_64 freetype-devel.x86_64 libjpeg-turbo-devel libmcrypt-devel mysql-devel libicu-devel glibc-headers libxslt-devel gcc-c++ pcre-devel
mkdir ~/Soft && cd Soft
wget http://jaist.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make && make install
cd ..
卸载预装PHP
yum remove php
rpm -qa | grep php | xargs rpm -e
编译安装PHP5.6.16
wget http://cn2.php.net/distributions/php-5.6.16.tar.gz
tar zxvf php-5.6.16.tar.gz
cd php-5.6.16
./configure --prefix=/usr/local/php5.6.16 --with-config-file-path=/etc/php --enable-fpm --with-fpm-user=webid --with-fpm-group=webid --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir=/usr/local/freetype --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-intl --enable-pcntl --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --disable-fileinfo --enable-opcache --with-xsl --enable-sysvmsg --with-imap-ssl
make && make install
编译安装PHP7.0.9
wget http://cn2.php.net/distributions/php-7.0.9.tar.gz
tar zxvf php-7.0.9.tar.gz
cd php-7.0.9
./configure --prefix=/usr/local/php7.0.9 --with-config-file-path=/etc/php/7.0.9 --enable-fpm --with-fpm-user=webid --with-fpm-group=webid --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir=/usr/local/freetype --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-intl --enable-pcntl --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --disable-fileinfo --enable-opcache --with-xsl --enable-sysvmsg --with-imap-ssl
make && make install
建立软连接
ln -s /usr/local/php(version)/bin/php /usr/bin/php
mkdir /etc/php/(version)
cp php.ini-production /etc/php/(version)/php.ini
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
groupadd webid
useradd -s /sbin/nologin -g webid webid
cp /usr/local/php(version)/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf (php7独有的操作)
cd ..
切换版本
更改php启动文件
ln -s /usr/local/php(version)/bin/php /usr/bin/php
更改php-fpm启动文件
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
安装redis扩展
wget -c https://github.com/phpredis/phpredis/archive/3.1.1.zip
unzip 3.1.1.zip
cd {dir}/
/usr/local/php/bin/phpize
执行上一步如果出现“Cannot find autoconf”,则需要执行
yum install m4
yum install autoconf
/usr/local/php/bin/phpize
end
./configure --with-php-config=/usr/local/php(version)/bin/php-config
make && make install
cd ..
vim /etc/php/php.ini
extension=redis.so
service php-fpm restart
安装memcache 扩展
安装依赖库 libmemcached
$ wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz
$ tar -zxf libmemcached-1.0.18.tar.gz
$ cd libmemcached-1.0.18/
$ ./configure
$ make && make install
安装memcached扩展
git clone https://github.com/php-memcached-dev/php-memcached.git
$ cd php-memcached/
$ git fetch --all
$ git checkout php7
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php(version)/bin/php-config --disable-memcached-sasl
make && make install
cd ..
vim /etc/php/php.ini
extension=memcached.so
service php-fpm restart
安装memcache扩展
wget -c https://github.com/phpredis/phpredis/archive/zinter-php71-reference.zip
unzip zinter-php71-reference.zip
cd phpredis-zinter-php71-reference/
/opt/php-7.0.14/bin/phpize
./configure --with-php-config=/opt/php-7.0.14/bin/php-config
make && make install
vim /etc/php/php.ini
extension=memcache.so
service php-fpm restart
安装swoole扩展
wget -c https://github.com/swoole/swoole-src/archive/1.8.7-stable.tar.gz
tar zxvf 1.8.7-stable.tar.gz
cd swoole-src-1.8.7-stable/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
cd ..
vim /etc/php/php.ini
extension=swoole.so
service php-fpm restart
安装nginx
wget http://nginx.org/download/nginx-1.10.1.tar.gz
tar zxvf nginx-1.10.1.tar.gz
cd nginx-1.10.1
./configure --user=webid --group=webid --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-ipv6 --with-http_sub_module --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock
make && make install
cd ..
ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx
ln -s /usr/local/nginx/conf /etc/nginx
配置优化
vim /usr/local/php/etc/php-fpm.d/www.conf
listen = /dev/shm/php7.sock
chown webid:webid /dev/shm/php7.sock
开机启动
chmod +x /etc/init.d/php-fpm
chkconfig --add /etc/init.d/php-fpm
chkconfig php-fpm on
创建文件 /etc/init.d/nginx
chmod +x /etc/init.d/nginx
chkconfig --add /etc/init.d/nginx
chkconfig nginx on
mkdir -p /data/logs/www/nginx
mkdir -p /data/webserver
passenger + nginx 安装(Centos 7)
yum install -y epel-release yum-utils
yum-config-manager --enable epel
sudo yum install -y pygpgme curl
sudo curl --fail -sSLo /etc/yum.repos.d/passenger.repo https://oss-binaries.phusionpassenger.com/yum/definitions/el-passenger.repo
yum install -y nginx passenger
systemctl start nginx.