Centos7安裝PHP7


 

 

安裝依賴

yum update
yum
install gcc-c++ 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=/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

make
make install

 

出現 configure: error: mcrypt.h not found. Please reinstall libmcrypt時

cd /usr/local/src
wget http://softlayer.dl.sourceforge.net/sourceforge/mcrypt/libmcrypt-2.5.8.tar.gz
tar -zxvf libmcrypt-2.5.8.tar.gz
cd /usr/local/src/libmcrypt-2.5.8
./configure --prefix=/usr/local
make
make install

出現 Don't know how to define struct flock on this system, set --enable-opcache=no

[root@localhost php-7.1.0]# vi /etc/ld.so.conf  
include ld.so.conf.d/*.conf
# 添加這行
/usr/local/lib
~
#保存后使之生效
ldconfig -v

安裝完之后, 可以直接運行PHP內建的web server,

# 使用/var/www/html/ 作為root目錄, 使用php.ini作為環境配置
php -S 0.0.0.0:80 -t /var/www/html -c php.ini
# 后台運行, 且不保留任何輸出
nohup php -S 0.0.0.0:80 -t /var/www/html >/dev/null 2>&1 &
# 后台運行, 將日志輸出到當前路徑下的phpd.log
nohup php -S 0.0.0.0:80 -t /var/www/html >phpd.log 2>&1 &
# 后台運行, 將日志輸出到當前路徑下的phpd.log, 使用bar.php作為路由腳本
nohup php -S 0.0.0.0:80 -t /var/www/html bar.php >phpd.log 2>&1 &

路由腳本: 每次請求都會先執行這個腳本。如果這個腳本返回 FALSE ,那么直接返回請求的文件(例如請求靜態文件不作任何處理)。否則會把輸出返回到瀏覽器

 

配置php和php-fpm

# 將默認的產品配置文件復制到配置目錄
cp /usr/src/php-7.1.0/php.ini-production /usr/local/php/etc/php.ini
# 復制默認的php-fpm配置文件
cd /usr/local/php/etc/
mv php-fpm.conf.default php-fpm.conf
mv php-fpm.d/www.conf.default php-fpm.d/www.conf
# 將php-fpm添加到服務
cd /usr/src/php-7.1.0/sapi/fpm/
cp init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm 
chkconfig --add php-fpm
chkconfig php-fpm on
systemctl start php-fpm
# 檢查是否正常運行
ps aux|grep php-fpm

修改nginx配置文件支持PHP

vi /opt/nginx/conf/nginx.conf

# 把前面的#注釋符號去掉,把script改為$document_root最終如下:
location ~ \.php$ {
    root           html;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  /$document_root$fastcgi_script_name;
    include        fastcgi_params;
}

然后重新載入nginx配置, 安裝就完成了

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM