1 創建php用戶和用戶組,并在github下載php7源碼
首先創建一個名為php且沒有登錄權限的用戶和一個名為php的用戶組,然后去GitHub下載php7源碼包。
#######新建php用戶和php組
[root@typecodes ~]# groupadd -r php && useradd -r -g php -s /bin/false -d /usr/local/php7 -M php
######從GitHub下載php7安裝包
centos7安裝docker?[root@typecodes ~]# wget -c --no-check-certificate -O php7-src-master.zip https://github.com/php/php-src/archive/master.zip
######開始解壓php7包
[root@typecodes ~]# unzip -q php7-src-master.zip && cd php-src-master
#####安裝編譯php7時需要的依賴包
[root@typecodes php-src-master]# yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel
2 PHP7編譯參數的配置
centos7.8。準備工作做好后,就開始正式配置php7的安裝明細了。注意,操作時一定要先把下面反斜杠“\”后面添加的注釋文字去掉!!!
######開始生成配置文件
[root@typecodes php-src-master]# ./buildconf
buildconf: checking installation...
buildconf: autoconf version 2.69 (ok)
rebuilding aclocal.m4
編譯安裝php7,rebuilding configure
rebuilding main/php_config.h.in
######開始配置
[root@typecodes php-src-master]# ./configure \
--prefix=/usr/local/php7 \ [PHP7安裝的根目錄]
--exec-prefix=/usr/local/php7 \
centos7.0安裝。--bindir=/usr/local/php7/bin \
--sbindir=/usr/local/php7/sbin \
--includedir=/usr/local/php7/include \
--libdir=/usr/local/php7/lib/php \
--mandir=/usr/local/php7/php/man \
--with-config-file-path=/usr/local/php7/etc \ [PHP7的配置目錄]
centos8安裝php、--with-mysql-sock=/var/run/mysql/mysql.sock \ [PHP7的Unix socket通信文件]
--with-mcrypt=/usr/include \
--with-mhash \
--with-openssl \
--with-mysqli=shared,mysqlnd \ [PHP7依賴mysql庫]
--with-pdo-mysql=shared,mysqlnd \ [PHP7依賴mysql庫]
php安裝,--with-gd \
--with-iconv \
--with-zlib \
--enable-zip \
--enable-inline-optimization \
--disable-debug \
centos 7、--disable-rpath \
--enable-shared \
--enable-xml \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
centos7.3,--enable-mbregex \
--enable-mbstring \
--enable-ftp \
--enable-gd-native-ttf \
--enable-pcntl \
--enable-sockets \
centos7源碼編譯安裝、--with-xmlrpc \
--enable-soap \
--without-pear \
--with-gettext \
--enable-session \ [允許php會話session]
--with-curl \ [允許curl擴展]
centos7.8安裝教程、--with-jpeg-dir \
--with-freetype-dir \
--enable-opcache=no \ [使用opcache緩存]
--enable-fpm \
--with-fpm-user=nginx \ [php-fpm的用戶]
--with-fpm-group=nginx \ [php-fpm的用戶組]
centos查看php版本?--without-gdbm \
--disable-fileinfo
直接復制下面的運行
./configure --prefix=/usr/local/php7 --exec-prefix=/usr/local/php7 --bindir=/usr/local/php7/bin --sbindir=/usr/local/php7/sbin --includedir=/usr/local/php7/include --libdir=/usr/local/php7/lib/php --mandir=/usr/local/php7/php/man --with-config-file-path=/usr/local/php7/etc
--with-mysql-sock=/var/run/mysql/mysql.sock --with-mcrypt=/usr/include --with-mhash --with-openssl --with-mysqli=shared,mysqlnd --with-pdo-mysql=shared,mysqlnd --with-gd --with-iconv --with-zlib --enable-zip --enable-inline-optimization --disable-debug --disable-rpath
--enable-shared --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-mbregex --enable-mbstring --enable-ftp --enable-gd-native-ttf --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --without-pear --with-gettext --enable-session --with-curl
yum安裝php7,--with-jpeg-dir --with-freetype-dir --enable-opcache=no --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --without-gdbm --disable-fileinfo
錯誤信息:configure: error: mcrypt.h not found. Please reinstall libmcrypt
解決方法:下載 libmcrypt-2.5.8.tar.gz 然后編譯安裝
下載地址:http://sourceforge.net/projects/mcrypt/files/Libmcrypt/
如果重新編譯了libmcrypt 記住安裝目錄,然后php的編譯項 --with-mcrypt=你的libmcrypt安裝目錄
./configure --prefix=/usr/local/php7 --exec-prefix=/usr/local/php7 --bindir=/usr/local/php7/bin --sbindir=/usr/local/php7/sbin --includedir=/usr/local/php7/include --libdir=/usr/local/php7/lib/php --mandir=/usr/local/php7/php/man --with-config-file-path=/usr/local/php7/etc
centos怎么用、--with-mysql-sock=/var/run/mysql/mysql.sock --with-mcrypt=/usr/local/libmcrytp/ --with-mhash --with-openssl --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-gd --with-iconv --with-zlib --enable-inline-optimization --disable-debug --disable-rpath --enable-shared
--enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-mbregex --enable-mbstring --enable-ftp --enable-gd-native-ttf --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --without-pear --with-gettext --enable-session --with-curl --with-jpeg-dir
--with-freetype-dir --enable-opcache --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --without-gdbm --disable-fileinfo
編譯時遇到問題:Don't know how to define struct flock on this system, set --enable-opcache=no
解決方法:(我最終用這些方法還是沒有解決)
一、yum groupinstall "Development Tools"。
centos編譯安裝ffmpeg。二、編輯 /etc/ld.so.conf 加入/usr/local/lib,在執行ldconfig -v
提示:我在/usr/lib 看到libmysqlclient.so 所以在編輯/etc/ld.so.conf的時候,需要看一下,里面是否存在這個
3 開始編譯和安裝PHP7
相對編譯安裝MySQL的大量CPU和內存消耗,PHP7的編譯安裝輕松多了,整個過程大約1個小時左右。
在編譯的時候,把--enable-opcache=no設為no,去掉了--enable-zip,所在安裝完成之后,需要單獨把這兩個作為擴展安裝
[root@typecodes php-src-master]# make clean && make && make install
阿里云centos安裝php、如果遇到錯誤可參考:http://blog.chinaunix.net/uid-20776139-id-5421615.html
4 選做步驟:執行make test命令進行測試
這是一個非必需的操作步驟,執行make test命令。
有趣的一件事就是:在test期間,會和一個IP地址72.52.91.14建立tcp連接,它對應著php官網http://www.php.net。
5 查看編譯成功后的PHP7安裝目錄
由于需要和MySQL進行通信,所以需要特別查看PHP7安裝后的lib擴展庫目錄(/usr/local/php7/lib/php/extensions/no-debug-non-zts-20141001/)。需要確保至少存在mysqli.so、pdo_mysql.so這兩個動態庫文件。
Linux安裝redis。6 開始設置PHP7的配置文件php.ini、php-fpm.conf、www.conf和php-fpm腳本
可以用編譯后的配置文件復制到PHP7的配置目錄(/usr/local/php7/etc/),推薦使用《PHP7中php.ini、php-fpm和www.conf的配置》文中整理的3個PHP7配置文件和php-fpm服務控制腳本。
#######方法一:直接使用編譯后未經優化處理的配置
[root@typecodes php-src-master]# cp php.ini-production /usr/local/php7/etc/php.ini
[root@typecodes php-src-master]# cp /php-src-master/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@typecodes php-src-master]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
centos 安裝python、[root@typecodes php-src-master]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
#######方法二:使用https://typecodes.com/web/php7configure.html文中的配置
[root@typecodes php-src-master]# mv ~/php.ini /usr/local/php7/etc/php.ini && mv ~/php-fpm /etc/init.d/php-fpm
[root@typecodes php-src-master]# mv ~/php-fpm.conf /usr/local/php7/etc/php-fpm.conf && mv ~/www.conf /usr/local/php7/etc/php-fpm.d/www.conf
7 添加php的環境變量
將php編譯生成的bin目錄添加到當前Linux系統的環境變量中
[root@typecodes ~]# echo -e '\nexport PATH=/usr/local/php7/bin:/usr/local/php7/sbin:$PATH\n' >> /etc/profile && source /etc/profile
8 設置PHP日志目錄和php-fpm進程文件(php-fpm.sock)目錄
其中,設置php-fpm進程目錄的用戶和用戶組為nginx,并創建php會話session目錄。
#######設置PHP日志目錄和php-fpm的運行進程ID文件(php-fpm.sock)目錄
[root@typecodes ~]# mkdir -p /var/log/php-fpm/ && mkdir -p /var/run/php-fpm && cd /var/run/ && chown -R nginx:nginx php-fpm
#######修改session的目錄配置
[root@typecodes etc]# mkdir -p /var/lib/php/session
[root@typecodes etc]# chown -R nginx:nginx /var/lib/php
9 設置PHP開機啟動以及測試配置文件是否正確
######配置開機自啟動,增加到主機sysV服務
[root@typecodes php-src-master]# chmod +x /etc/init.d/php-fpm
[root@typecodes php-src-master]# chkconfig --add php-fpm
[root@typecodes php-src-master]# chkconfig php-fpm on
######測試PHP的配置文件是否正確合法
[root@typecodes sbin]# php-fpm -t
[03-May-2015 17:50:04] NOTICE: configuration file /usr/local/php7/etc/php-fpm.conf test is successful
10 啟動php服務
在完成上面的操作后,就可以正式使用php服務了。啟動php進程服務的命令如下:
[root@typecodes sbin]# service php-fpm start
Starting php-fpm done
11 安裝opcache
教程:http://blog.jjonline.cn/linux/135.html
教程:http://blog.ich8.com/post/4142
教程:http://my.oschina.net/u/919580/blog/406900 實踐證明這個可用
安裝:
Linux
安裝 Zend Opcache(pecl 版本):
刪除 eaccelerator、xcache、apc:
yum remove php-eaccelerator php-xcache php-apcu
沒有使用則跳過。
對系統執行升級:
yum update
安裝 Zend Opcache(pecl 版本)
yum install php-pecl-zendopcache PS:但是在centos7上還是沒有找到 php-pecl-zendopcache擴展,所以下面無法繼續操作
安裝時產生的 opcache 的配置文件位于默認的 /etc/php.d 目錄中:
opcache-default.blacklist
opcache.ini
這個配置文件采用的基本就是 README 中的推薦設置,只有幾個地方需要修改。
vi /etc/php.d/opcache.ini
對照如下推薦配置修改并保存即可:
opcache.memory_c>opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable_cli=1
不需要修改 php.ini 配置,重起 Apache 服務使之生效:
service httpd restart
查詢一下看看是否正確啟動了:
php -v
輸出結果類似于:
PHP 7 (cli) (built: Apr 11 2013 11:04:35)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
with Zend OPcache v7.0.1, Copyright (c) 1999-2013, by Zend Technologies
以上就介紹了CentOS 71編譯安裝PHP7,包括了方面的內容,希望對PHP教程有興趣的朋友有所幫助。
本文原創發布php中文網,轉載請注明出處,感謝您的尊重!
相關文章
相關視頻
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态