1. 程式人生 > >CentOS 7解壓安裝PHP7.1.21

CentOS 7解壓安裝PHP7.1.21

sap 依賴 string splay str 動態生成 dev nginx target

下載php

yum install -y wget
wget http://cn2.php.net/distributions/php-7.1.21.tar.gz

解壓

tar -zxvf php-7.1.21.tar.gz
cd php-7.1.21

編譯:

# 安裝epel
yum install -y epel-release
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
# 安裝編譯依賴
yum install -y 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 gcc
# 創建目錄
mkdir
-p /data/service/php/etc ./configure \ --prefix=/data/service/php \ --with-config-file-path=/data/service/php/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
make && make install

增加環境變量

cat <<EOF > /etc/profile.d/php.sh
export PATH=/data/service/php/bin:\$PATH
EOF
# 生效環境變量
. /etc/profile

配置php-fpm

cp php.ini-production /data/service/php/etc/php.ini
cp /data/service/php/etc/php-fpm.conf.default /data/service/php/etc/php-fpm.conf
cp /data/service/php/etc/php-fpm.d/www.conf.default /data/service/php/etc/php-fpm.d/www.conf

配置php-fpm服務

# 註意:這個文件是根據上面C++編譯配置動態生成的文件,裏面寫了上面配置的路徑
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm # 啟動權限 chmod +x /etc/init.d/php-fpm

啟動:

# 增加開機啟動
systemctl enable php-fpm
systemctl start php-fpm

註意:php-fpm需要nginx用戶,當然你可以自行增加,也可以直接安裝nginx。

自動化腳本:

https://github.com/easonjim/centos-shell/blob/master/php/install-php_7.1.21.sh

參考:

https://blog.csdn.net/tojohnonly/article/details/78680633

CentOS 7解壓安裝PHP7.1.21