新增的函式庫檔案路徑一定要跟系統平台arch一致,32bit的系統直接加入【/usr/local/lib】即可,64bit系統要填加【/usr/local/lib64.】否則依舊會報錯,本文將詳細介紹centos7下如何安裝PHP7。
一、官網安裝方法:
http://php.net/manual/zh /install.unix.nginx.php
相關學習推薦:PHP 程式設計從入門到精通
二、編譯安裝
1.下載php7
##wget -O php7.tar.gz http://cn2.php.net/get/php-7.1.20.tar.gz/from/this/mirror或直接網頁下載# http://php.net/get/php-7.1.20.tar.gz/from/a/mirror2.解壓縮php7##tar -xvf php7.tar.gz
3.進入php目錄#cd /usr/local/src/php-7.1.20
# 4.安裝依賴套件yum install 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
(如果發生錯誤,基本上都是上一步驟的依賴檔案沒有安裝所致)./configure \
--prefix=/software/php \
--with-config-file-path=/etc \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--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
最實用的解決方法如下:
問題:
1: wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
2: tar zxf libmcrypt-2.5.7.tar.gz
3: ./configure --prefix=/usr/local
4: make && make install
問題:configure: error: Don't know how to define struct flock on this system, set --enable-opcache=no
解決:解決方法:
vim /etc/ld.so.conf.d/local.conf
# 編輯庫檔案
/usr/local/lib
ldconfig -v
注意事項:
這裡新增的庫檔案路徑一定要和你係統平台arch一致,32bit的系統直接加上
/usr/local/lib即可,64bit系統要填加/usr/local/lib64
.否則依舊會報錯,我當時就是添加了/usr/ local/lib
死活編輯不了,後來改成/usr/local/lib64
才可以。
make && make install
7.設定環境變數
vi /etc/profile
PATH=$PATH:/usr/local/php/bin
export PATH
source /etc/profile
#8.設定php-fpm
cp php.ini-production /usr/local/php/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 /usr/local/php/etc/php-fpm
chmod +x /usr/local/php/etc/php-fpm
ln /usr/local/php/etc/php.ini /etc/php.ini
9、建立www使用者
useradd www
10、設定啟動項目參數
vim /usr/local/php/etc/php-fpm.d/www.conf pm.max_children = 500 pm.start_servers = 105 pm.min_spare_servers = 10 pm.max_spare_servers = 200
#11.啟動php-fpm
###/usr/local/php/etc/php-fpm start 设置 php-fpm开机启动 cp /usr/local/src/php-5.5.14/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm #拷贝php-fpm到启动目录 chmod +x /etc/rc.d/init.d/php-fpm #添加执行权限 chkconfig php-fpm on #设置开机启动 service php-fpm start pkill php-fpm 强制关闭
以上是centos7下如何安裝PHP7?的詳細內容。更多資訊請關注PHP中文網其他相關文章!