新聞中心
CentOS7.3編譯安裝php7.1

創(chuàng)新互聯(lián)建站-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比樂安網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式樂安網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋樂安地區(qū)。費(fèi)用合理售后完善,十余年實(shí)體公司更值得信賴。
- 說明
- 安裝依賴包
- 創(chuàng)建用戶及用戶組
- 下載php71并解壓
- 下載并安裝php依賴
- PHP語法分析器re2c
- 加密支持?jǐn)U展庫libmcrypt
- 加密方式擴(kuò)展庫mhash
- 加密方式擴(kuò)展庫mcrypt
- 編譯php71
- 查看源碼目錄文件具體內(nèi)容
- 生成php源碼目錄下的配置文件 configure
- 生成源碼目錄配置文件 configure 之后的目錄
- 正式編譯php71
- 可能會(huì)出現(xiàn)要求開啟 --enable-opcacheon 的錯(cuò)誤提示
- 運(yùn)行 make test
- 編譯安裝后的php目錄
- 配置php
- 修改php配置文件之添加php配置文件
- 修改php配置文件之修改php擴(kuò)展目錄所在位置
- 修改php配置文件之修改服務(wù)器所在時(shí)區(qū)
- 修改php配置文件之開啟OPcache
- 修改php配置文件之開啟 mysqli 擴(kuò)展
- 添加 php-fpm 管理相關(guān)的配置文件到系統(tǒng)配置目錄 etcinitd
- 添加 php-fpm 配置文件
- 添加 wwwconf 配置文件
- 添加php安裝目錄到系統(tǒng)環(huán)境變量
- 設(shè)置PHP日志目錄和php-fpm運(yùn)行進(jìn)程的ID文件目錄
- 修改session的目錄配置
- 設(shè)置php開機(jī)啟動(dòng)
- 檢測(cè) php-fpm 系統(tǒng)服務(wù)是否啟動(dòng)成功
- 測(cè)試PHP的配置文件是否無誤
- 啟動(dòng)php系統(tǒng)服務(wù)
- 查看php系統(tǒng)服務(wù)狀態(tài)
- CLI查看php版本信息
- 修改nginx配置文件使之使用nginx反向php解釋器
- 瀏覽器訪問
說明
安裝LNMP環(huán)境一般是先安裝mysql/mariadb, 再安裝nginx, 其次是安裝php
安裝依賴包
[root@localhost ~]# yum -y install gcc
[root@localhost ~]# yum -y install gcc++
[root@localhost ~]# yum -y install gcc-c++
[root@localhost ~]# yum -y install wget
[root@localhost ~]# yum -y install make
[root@localhost ~]# yum -y install libxml2
[root@localhost ~]# yum -y install libxml2-devel
[root@localhost ~]# yum -y install openssl
[root@localhost ~]# yum -y install openssl-devel
[root@localhost ~]# yum -y install curl-devel
[root@localhost ~]# yum -y install libjpeg-devel
[root@localhost ~]# yum -y install libpng-devel
[root@localhost ~]# yum -y install freetype-devel
[root@localhost ~]# yum -y install bison
[root@localhost ~]# yum -y install autoconf
創(chuàng)建用戶及用戶組
- 創(chuàng)建php用戶組
> 創(chuàng)建php用戶組(-r選項(xiàng)是創(chuàng)建一個(gè)系統(tǒng)用戶組的意思)
[root@localhost ~]# groupadd -r php
- 創(chuàng)建用戶并加入到php系統(tǒng)用戶組
> 添加新用戶
> -r: 添加系統(tǒng)用戶( 這里指將要被創(chuàng)建的系統(tǒng)用戶php )
> -g: 指定要?jiǎng)?chuàng)建的用戶所屬組( 這里指添加到新系統(tǒng)用戶php到php系統(tǒng)用戶組 )
> -s: 新帳戶的登錄shell( `/sbin/nologin` 這里設(shè)置為將要被創(chuàng)建系統(tǒng)用戶php不能用來登錄系統(tǒng) )
> -d: 新帳戶的主目錄( 這里指定將要被創(chuàng)建的系統(tǒng)用戶php的家目錄為 `/usr/local/php` )
> -M: 不要?jiǎng)?chuàng)建用戶的主目錄( 也就是說將要被創(chuàng)建的系統(tǒng)用戶php不會(huì)在 `/home` 目錄下創(chuàng)建 `php` 家目錄 )
[root@localhost ~]# useradd -r -g php -s /sbin/nologin -d /usr/local/php -M php
下載php7.1并解壓
> 下載
[root@localhost ~]# wget -c https://github.com/php/php-src/archive/php-7.1.6.tar.gz
> 解壓
[root@localhost ~]# tar -zxvf php-7.1.6.tar.gz
下載并安裝php依賴
PHP語法分析器re2c
> 下載
[root@localhost ~]# wget -c https://github.com/skvadrik/re2c/releases/download/0.16/re2c-0.16.tar.gz
> 解壓
[root@localhost ~]# tar -zxvf re2c-0.16.tar.gz
> 進(jìn)入解壓后的源碼目錄編譯并安裝
[root@localhost ~]# cd re2c-0.16
[root@localhost re2c-0.16]# ./configure
[root@localhost re2c-0.16]# make && make install
加密支持?jǐn)U展庫libmcrypt
使用php mcrypt 前必須先安裝Libmcrypt
> 下載
[root@localhost ~]# wget -c https://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
> 解壓
[root@localhost ~]# tar -zxvf libmcrypt-2.5.8.tar.gz
> 進(jìn)入解壓后的源碼目錄編譯并安裝
[root@localhost ~]# cd libmcrypt-2.5.8
[root@localhost libmcrypt-2.5.8]# ./configure
[root@localhost libmcrypt-2.5.8]# # make && make install
加密方式擴(kuò)展庫mhash
> 下載
[root@localhost ~]# wget -c https://downloads.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz
> 解壓
[root@localhost ~]# tar -zxvf mhash-0.9.9.9.tar.gz
> 進(jìn)入解壓后的源碼目錄編譯并安裝
[root@localhost mhash-0.9.9.9]# cd mhash-0.9.9.9
[root@localhost mhash-0.9.9.9]# ./configure
[root@localhost mhash-0.9.9.9]# make && make install
加密方式擴(kuò)展庫mcrypt
> 下載
[root@localhost ~]# wget -c https://sourceforge.net/projects/mcrypt/files/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz
> 解壓
[root@localhost ~]# tar -zxvf mcrypt-2.6.8.tar.gz
> 由于在編譯mcrypt時(shí),會(huì)找不到libmcrypt的鏈接庫,導(dǎo)致無法編譯,因?yàn)長(zhǎng)ibmcrypt的鏈接庫在/usr/local/lib文件夾下
> 所以,在編譯mcrypt時(shí)要加入LD_LIBRARY_PATH=/usr/local/lib導(dǎo)入間接庫
> 進(jìn)入解壓后的源碼目錄編譯并安裝
[root@localhost ~# cd mcrypt-2.6.8
[root@localhost mcrypt-2.6.8]# ./configure LD_LIBRARY_PATH=/usr/local/lib
[root@localhost mcrypt-2.6.8]# make && make install
編譯php7.1
到目錄為止所有的準(zhǔn)備工作已經(jīng)完成, 接下來就是編譯php7.1了!
查看源碼目錄文件具體內(nèi)容
[root@localhost php-src-php-7.1.6]# ll
total 1252
-rw-rw-r--. 1 root root 82506 Jun 7 04:05 acinclude.m4 drwxrwxr-x. 2 root root 78 Jun 7 04:05 appveyor
drwxrwxr-x. 2 root root 4096 Jun 7 04:05 build
-rwxrwxr-x. 1 root root 772 Jun 7 04:05 buildconf -rw-rw-r--. 1 root root 334 Jun 7 04:05 buildconf.bat -rw-rw-r--. 1 root root 11982 Jun 7 04:05 CODING_STANDARDS -rw-rw-r--. 1 root root 42938 Jun 7 04:05 config.guess -rw-rw-r--. 1 root root 35987 Jun 7 04:05 config.sub -rw-rw-r--. 1 root root 46774 Jun 7 04:05 configure.in -rw-rw-r--. 1 root root 3163 Jun 7 04:05 CONTRIBUTING.md -rw-rw-r--. 1 root root 91 Jun 7 04:05 CREDITS drwxrwxr-x. 75 root root 4096 Jun 7 04:05 ext
-rw-rw-r--. 1 root root 20917 Jun 7 04:05 EXTENSIONS -rw-rw-r--. 1 root root 137 Jun 7 04:05 footer -rwxrwxr-x. 1 root root 581 Jun 7 04:05 genfiles -rw-rw-r--. 1 root root 1143 Jun 7 04:05 header -rw-rw-r--. 1 root root 87836 Jun 7 04:05 INSTALL -rw-rw-r--. 1 root root 3218 Jun 7 04:05 LICENSE -rw-rw-r--. 1 root root 199728 Jun 7 04:05 ltmain.sh drwxrwxr-x. 3 root root 4096 Jun 7 04:05 main
-rwxrwxr-x. 1 root root 4129 Jun 7 04:05 makedist -rw-rw-r--. 1 root root 1088 Jun 7 04:05 Makefile.frag -rw-rw-r--. 1 root root 2485 Jun 7 04:05 Makefile.gcov -rw-rw-r--. 1 root root 7236 Jun 7 04:05 Makefile.global -rw-rw-r--. 1 root root 5317 Jun 7 04:05 makerpm drwxrwxr-x. 2 root root 40 Jun 7 04:05 netware
-rw-rw-r--. 1 root root 135093 Jun 7 04:05 NEWS drwxrwxr-x. 2 root root 65 Jun 7 04:05 pear
-rw-rw-r--. 1 root root 1489 Jun 7 04:05 php.spec.in -rw-rw-r--. 1 root root 2523 Jun 7 04:05 php.gif -rw-rw-r--. 1 root root 71064 Jun 7 04:05 php.ini-development -rw-rw-r--. 1 root root 71096 Jun 7 04:05 php.ini-production -rw-rw-r--. 1 root root 7010 Jun 7 04:05 README.EXT_SKEL -rw-rw-r--. 1 root root 5026 Jun 7 04:05 README.GIT-RULES -rw-rw-r--. 1 root root 5417 Jun 7 04:05 README.input_filter -rw-rw-r--. 1 root root 3426 Jun 7 04:05 README.MAILINGLIST_RULES -rw-rw-r--. 1 root root 1608 Jun 7 04:05 README.md -rw-rw-r--. 1 root root 6040 Jun 7 04:05 README.namespaces -rw-rw-r--. 1 root root 5237 Jun 7 04:05 README.NEW-OUTPUT-API -rw-rw-r--. 1 root root 7528 Jun 7 04:05 README.PARAMETER_PARSING_API -rw-rw-r--. 1 root root 19766 Jun 7 04:05 README.REDIST.BINS -rw-rw-r--. 1 root root 12934 Jun 7 04:05 README.RELEASE_PROCESS -rw-rw-r--. 1 root root 5086 Jun 7 04:05 README.SELF-CONTAINED-EXTENSIONS -rw-rw-r--. 1 root root 15355 Jun 7 04:05 README.STREAMS -rw-rw-r--. 1 root root 8126 Jun 7 04:05 README.SUBMITTING_PATCH -rw-rw-r--. 1 root root 6695 Jun 7 04:05 README.TESTING -rw-rw-r--. 1 root root 4958 Jun 7 04:05 README.TESTING2 -rw-rw-r--. 1 root root 4261 Jun 7 04:05 README.UNIX-BUILD-SYSTEM -rw-rw-r--. 1 root root 109 Jun 7 04:05 README.WIN32-BUILD-SYSTEM -rwxrwxr-x. 1 root root 82234 Jun 7 04:05 run-tests.php drwxrwxr-x. 10 root root 4096 Jun 7 04:05 sapi
drwxrwxr-x. 4 root root 99 Jun 7 04:05 scripts
-rwxrwxr-x. 1 root root 2104 Jun 7 04:05 server-tests-config.php -rwxrwxr-x. 1 root root 52726 Jun 7 04:05 server-tests.php -rwxrwxr-x. 1 root root 108 Jun 7 04:05 snapshot -rw-rw-r--. 1 root root 10 Jun 7 04:05 stamp-h.in -rw-rw-r--. 1 root root 1 Jun 7 04:05 stub.c drwxrwxr-x. 10 root root 4096 Jun 7 04:05 tests
drwxrwxr-x. 3 root root 33 Jun 7 04:05 travis
drwxrwxr-x. 3 root root 4096 Jun 7 04:05 TSRM
-rw-rw-r--. 1 root root 23356 Jun 7 04:05 UPGRADING -rw-rw-r--. 1 root root 3418 Jun 7 04:05 UPGRADING.INTERNALS -rwxrwxr-x. 1 root root 159 Jun 7 04:05 vcsclean drwxrwxr-x. 3 root root 4096 Jun 7 04:05 win32
drwxrwxr-x. 4 root root 4096 Jun 7 04:05 Zend
可以發(fā)現(xiàn)目錄中并沒有
configure文件, 但是有一個(gè)名為buildconf的文件,嗯, 是它就是它, 我們要通過運(yùn)行這個(gè)文件生成
configure文件
生成php源碼目錄下的配置文件 configure
> 運(yùn)行 `buildconf` 文件, 生成 `configure` 文件
[root@localhost php-src-php-7.1.6]# ./buildconf
You should not run buildconf in a release package.
use buildconf --force to override this check.
> 很不幸運(yùn), 并沒有成功, 并且提示:
You should not run buildconf in a release package. # 你不應(yīng)該在發(fā)布包運(yùn)行buildconf文件。
use buildconf --force to override this check. # 使用buildconf文件重寫此檢查。
> 那就根據(jù)它的要求加入 `--force` 選項(xiàng)重寫檢查
[root@localhost php-src-php-7.1.6]# ./buildconf --force
Forcing buildconf
Removing configure caches
buildconf: checking installation...
buildconf: autoconf version 2.69 (ok)
rebuilding aclocal.m4
rebuilding configure
rebuilding main/php_config.h.in
> 這次可算是buildconf文件重寫檢查成功了, 看一下源碼目錄有沒有 `configure` 文件
生成源碼目錄配置文件 configure 之后的目錄
[root@localhost php-src-php-7.1.6]# ll
total 4260
-rw-rw-r--. 1 root root 82506 Jun 7 04:05 acinclude.m4 -rw-r--r--. 1 root root 312883 Jun 18 04:43 aclocal.m4 drwxrwxr-x. 2 root root 78 Jun 7 04:05 appveyor
drwxr-xr-x. 2 root root 51 Jun 18 04:43 autom4te.cache
drwxrwxr-x. 2 root root 4096 Jun 7 04:05 build
-rwxrwxr-x. 1 root root 772 Jun 7 04:05 buildconf -rw-rw-r--. 1 root root 334 Jun 7 04:05 buildconf.bat -rw-r--r--. 1 root root 0 Jun 18 04:43 buildmk.stamp -rw-rw-r--. 1 root root 11982 Jun 7 04:05 CODING_STANDARDS -rw-rw-r--. 1 root root 42938 Jun 7 04:05 config.guess -rw-rw-r--. 1 root root 35987 Jun 7 04:05 config.sub -rwxr-xr-x. 1 root root 2758685 Jun 18 04:43 configure -rw-rw-r--. 1 root root 46774 Jun 7 04:05 configure.in -rw-rw-r--. 1 root root 3163 Jun 7 04:05 CONTRIBUTING.md -rw-rw-r--. 1 root root 91 Jun 7 04:05 CREDITS drwxrwxr-x. 75 root root 4096 Jun 7 04:05 ext
-rw-rw-r--. 1 root root 20917 Jun 7 04:05 EXTENSIONS -rw-rw-r--. 1 root root 137 Jun 7 04:05 footer -rw-r--r--. 1 root root 1776 Jun 18 04:43 generated_lists -rwxrwxr-x. 1 root root 581 Jun 7 04:05 genfiles -rw-rw-r--. 1 root root 1143 Jun 7 04:05 header -rw-rw-r--. 1 root root 87836 Jun 7 04:05 INSTALL -rw-r--r--. 1 root root 0 Jun 18 04:43 install-sh -rw-rw-r--. 1 root root 3218 Jun 7 04:05 LICENSE -rw-rw-r--. 1 root root 199728 Jun 7 04:05 ltmain.sh drwxrwxr-x. 3 root root 4096 Jun 18 04:43 main
-rwxrwxr-x. 1 root root 4129 Jun 7 04:05 makedist -rw-rw-r--. 1 root root 1088 Jun 7 04:05 Makefile.frag -rw-rw-r--. 1 root root 2485 Jun 7 04:05 Makefile.gcov -rw-rw-r--. 1 root root 7236 Jun 7 04:05 Makefile.global -rw-rw-r--. 1 root root 5317 Jun 7 04:05 makerpm -rw-r--r--. 1 root root 0 Jun 18 04:43 missing -rw-r--r--. 1 root root 0 Jun 18 04:43 mkinstalldirs drwxrwxr-x. 2 root root 40 Jun 7 04:05 netware
-rw-rw-r--. 1 root root 135093 Jun 7 04:05 NEWS drwxrwxr-x. 2 root root 65 Jun 7 04:05 pear
-rw-rw-r--. 1 root root 1489 Jun 7 04:05 php7.spec.in -rw-rw-r--. 1 root root 2523 Jun 7 04:05 php.gif -rw-rw-r--. 1 root root 71064 Jun 7 04:05 php.ini-development -rw-rw-r--. 1 root root 71096 Jun 7 04:05 php.ini-production -rw-rw-r--. 1 root root 7010 Jun 7 04:05 README.EXT_SKEL -rw-rw-r--. 1 root root 5026 Jun 7 04:05 README.GIT-RULES -rw-rw-r--. 1 root root 5417 Jun 7 04:05 README.input_filter -rw-rw-r--. 1 root root 3426 Jun 7 04:05 README.MAILINGLIST_RULES -rw-rw-r--. 1 root root 1608 Jun 7 04:05 README.md -rw-rw-r--. 1 root root 6040 Jun 7 04:05 README.namespaces -rw-rw-r--. 1 root root 5237 Jun 7 04:05 README.NEW-OUTPUT-API -rw-rw-r--. 1 root root 7528 Jun 7 04:05 README.PARAMETER_PARSING_API -rw-rw-r--. 1 root root 19766 Jun 7 04:05 README.REDIST.BINS -rw-rw-r--. 1 root root 12934 Jun 7 04:05 README.RELEASE_PROCESS -rw-rw-r--. 1 root root 5086 Jun 7 04:05 README.SELF-CONTAINED-EXTENSIONS -rw-rw-r--. 1 root root 15355 Jun 7 04:05 README.STREAMS -rw-rw-r--. 1 root root 8126 Jun 7 04:05 README.SUBMITTING_PATCH -rw-rw-r--. 1 root root 6695 Jun 7 04:05 README.TESTING -rw-rw-r--. 1 root root 4958 Jun 7 04:05 README.TESTING2 -rw-rw-r--. 1 root root 4261 Jun 7 04:05 README.UNIX-BUILD-SYSTEM -rw-rw-r--. 1 root root 109 Jun 7 04:05 README.WIN32-BUILD-SYSTEM -rwxrwxr-x. 1 root root 82234 Jun 7 04:05 run-tests.php drwxrwxr-x. 10 root root 4096 Jun 7 04:05 sapi
drwxrwxr-x. 4 root root 99 Jun 7 04:05 scripts
-rwxrwxr-x. 1 root root 2104 Jun 7 04:05 server-tests-config.php -rwxrwxr-x. 1 root root 52726 Jun 7 04:05 server-tests.php -rwxrwxr-x. 1 root root 108 Jun 7 04:05 snapshot -rw-rw-r--. 1 root root 10 Jun 7 04:05 stamp-h.in -rw-rw-r--. 1 root root 1 Jun 7 04:05 stub.c drwxrwxr-x. 10 root root 4096 Jun 7 04:05 tests
drwxrwxr-x. 3 root root 33 Jun 7 04:05 travis
drwxrwxr-x. 3 root root 4096 Jun 7 04:05 TSRM
-rw-rw-r--. 1 root root 23356 Jun 7 04:05 UPGRADING -rw-rw-r--. 1 root root 3418 Jun 7 04:05 UPGRADING.INTERNALS -rwxrwxr-x. 1 root root 159 Jun 7 04:05 vcsclean drwxrwxr-x. 3 root root 4096 Jun 7 04:05 win32
drwxrwxr-x. 4 root root 4096 Jun 7 04:05 Zend
現(xiàn)在源碼目錄也就存在
configure文件了
正式編譯php7.1
如果使用此編譯選項(xiàng)列表, 請(qǐng)將
\反斜線后面的注釋去除, 并且后面不能有空白字符
[root@localhost php-src-php-7.1.6]# ./configure \
--prefix=/usr/local/php \ [php安裝的根目錄] --exec-prefix=/usr/local/php \ [php執(zhí)行文件所在目錄] --bindir=/usr/local/php/bin \ [php/bin目錄] --sbindir=/usr/local/php/sbin \ [php/sbin目錄] --includedir=/usr/local/php/include \ [php包含文件所在目錄] --libdir=/usr/local/php/lib/php \ [php/lib目錄] --mandir=/usr/local/php/php/man \ [php/man目錄] --with-config-file-path=/usr/local/php/etc \ [php的配置目錄] --with-mysql-sock=/var/run/mysql/mysql.sock \ [php的Unix socket通信文件] --with-mcrypt \ [是php里面重要的加密支持?jǐn)U展庫,linux環(huán)境下該庫在默認(rèn)情況下不開啟] --with-mhash \ [Mhash是基于離散數(shù)學(xué)原理的不可逆向的php加密方式擴(kuò)展庫,其在默認(rèn)情況下不開啟] --with-openssl \ [OpenSSL 是一個(gè)安全套接字層密碼庫] --with-mysqli=shared,mysqlnd \ [php依賴mysql庫] --with-pdo-mysql=shared,mysqlnd \ [php依賴mysql庫] --with-gd \ [gd庫] --with-iconv \ [關(guān)閉iconv函數(shù),種字符集間的轉(zhuǎn)換] --with-zlib \ [zlib是提供數(shù)據(jù)壓縮用的函式庫] --enable-zip \ [打開對(duì)zip的支持] --enable-inline-optimization \ [優(yōu)化線程] --disable-debug \ [關(guān)閉調(diào)試模式] --disable-rpath \ [關(guān)閉額外的運(yùn)行庫文件] --enable-shared \ [啟用動(dòng)態(tài)庫] --enable-xml \ [開啟xml擴(kuò)展] --enable-bcmath \ [打開圖片大小調(diào)整,用到zabbix監(jiān)控的時(shí)候用到了這個(gè)模塊] --enable-shmop \ [共享內(nèi)存] --enable-sysvsem \ [內(nèi)存共享方案] --enable-mbregex \ [開啟多字節(jié)正則表達(dá)式的字符編碼。] --enable-mbstring \ [開啟多字節(jié)字符串函數(shù)] --enable-ftp \ [開啟ftp] --enable-gd-native-ttf \ [開啟gd庫原有字體] --enable-pcntl \ [PHP的進(jìn)程控制支持實(shí)現(xiàn)了Unix方式的多進(jìn)程創(chuàng)建] --enable-sockets \ [開啟套節(jié)字] --with-xmlrpc \ [打開xml-rpc的c語言] --enable-soap \ [開啟簡(jiǎn)單對(duì)象訪問協(xié)議簡(jiǎn)單對(duì)象訪問協(xié)議] --without-pear \ [開啟php擴(kuò)展與應(yīng)用庫] --with-gettext \ [開戶php在當(dāng)前域中查找消息] --enable-session \ [允許php會(huì)話session] --with-curl \ [允許curl擴(kuò)展] --with-jpeg-dir \ [指定jpeg安裝目錄yum安裝過后不用再次指定會(huì)自動(dòng)找到] --with-freetype-dir \ [指定freetype安裝目錄yum安裝過后不用再次指定會(huì)自動(dòng)找到] --enable-opcache \ [開啟使用opcache緩存] --enable-fpm \ [開啟fpm] --with-fpm-user=nginx \ [php-fpm的用戶] --with-fpm-group=nginx \ [php-fpm的用戶組] --without-gdbm \ [數(shù)據(jù)庫函數(shù)使用可擴(kuò)展散列和類似于標(biāo)準(zhǔn)UNIX dbm的工作] --enable-fast-install \ [為快速安裝優(yōu)化] --disable-fileinfo
可能會(huì)出現(xiàn)要求開啟 --enable-opcache=on 的錯(cuò)誤提示
> 錯(cuò)誤提示
configure: error: Don't know how to define struct flock on this system, set --enable-opcache=no
> 解決辦法
編輯/etc/ld.so.conf
加入/usr/local/lib
執(zhí)行l(wèi)dconfig,使其重新加載一次
運(yùn)行 make test
這一步不是必須的, 如果要運(yùn)行可能會(huì)讓你等很長(zhǎng)一段時(shí)間
- 運(yùn)行
[root@localhost php-src-php-7.1.6]# make test
- 結(jié)果
You may have found a problem in PHP.
This report can be automatically sent to the PHP QA team at
http://qa.php.net/reports and http://news.php.net/php.qa.reports
This gives us a better understanding of PHP's behavior.
If you don't want to send the report immediately you can choose
option "s" to save it. You can then email it to qa-reports@lists.php.net later.
Do you want to send this report now? [Yns]: Y
Please enter your email address.
(Your address will be mangled so that it will not go out on any
mailinglist in plain text): warnerwu@126.com
Posting to http://qa.php.net/buildtest-process.php
Thank you for helping to make PHP better.
出現(xiàn)這個(gè)結(jié)果
make test也就完成了!
編譯安裝后的php目錄
[root@localhost php-src-php-7.1.6]# ll /usr/local/php
total 0
drwxr-xr-x. 2 root root 100 Jun 18 05:57 bin
drwxr-xr-x. 3 root root 49 Jun 18 05:57 etc
drwxr-xr-x. 3 root root 16 Jun 18 05:57 include
drwxr-xr-x. 3 root root 16 Jun 18 05:57 lib
drwxr-xr-x. 4 root root 26 Jun 18 05:57 php
drwxr-xr-x. 2 root root 20 Jun 18 05:57 sbin
drwxr-xr-x. 4 root root 26 Jun 18 05:57 var
配置php
修改php配置文件之添加php配置文件
> 將php源碼編譯目錄下的 `php.ini-production` 拷貝到php安裝目錄下的 `etc` 目錄下
[root@localhost php-src-php-7.1.6]# cp php.ini-production /usr/local/php/etc/php.ini
修改php配置文件之修改php擴(kuò)展目錄所在位置
> 修改 `php.ini` 配置文件, 設(shè)置php擴(kuò)展安裝目錄所在位置
[root@localhost php-src-php-7.1.6]# vim /usr/local/php/etc/php.ini
> 找到 `extension_dir` 修改擴(kuò)展目錄位置如下:
extension_dir = "../lib/php/extensions/no-debug-non-zts-20160303/"
> 上面寫的擴(kuò)展目錄位置是使用的 `相對(duì)路徑` 當(dāng)然你也可以使用 `絕對(duì)路徑` 如:
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/"
修改php配置文件之修改服務(wù)器所在時(shí)區(qū)
> 修改 `php.ini` 配置文件, 設(shè)置php所安裝服務(wù)器時(shí)區(qū)
[root@localhost php-src-php-7.1.6]# vim /usr/local/php/etc/php.ini
> 找到 `timezone` 修改時(shí)區(qū)如下:
date.timezone = PRC
> PRC就是英文People's Republic of China, 這個(gè)你應(yīng)該知道的吧! 中華人民共和國
修改php配置文件之開啟OPcache
> 修改 `php.ini` 配置文件, 開啟OPcache
[root@localhost php-src-php-7.1.6]# vim /usr/local/php/etc/php.ini
> 跳轉(zhuǎn)到文件的最后一行(shift+G), 輸入以下內(nèi)容:
zend_extension=opcache.so;
> 保存并退出
:wq!
修改php配置文件之開啟 mysqli 擴(kuò)展
> 修改 `php.ini` 配置文件, 開啟 `mysqli` 擴(kuò)展
[root@localhost php-src-php-7.1.6]# vim /usr/local/php/etc/php.ini
> 找到 `extension` 位置, 輸入以下內(nèi)容
; For UNIX OS open mysqli extension
extension=mysqli.so
extension=pdo_mysql.so
> 保存并退出
:wq!
添加 php-fpm 管理相關(guān)的配置文件到系統(tǒng)配置目錄 /etc/init.d
> 將php源碼編譯目錄下的 `sapi/fpm/init.d.php-fpm` 文件拷貝到系統(tǒng)配置 `/etc/init.d` 目錄下并重命名為 `php-fpm`
[root@localhost php-src-php-7.1.6]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
添加 php-fpm 配置文件
> 將php安裝目錄下的 `/usr/local/php/etc/php-fpm.conf.default` 文件拷貝同目錄下并重命名為 `php-fpm.conf`
[root@localhost php-src-php-7.1.6]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
- 1
- 2
- 3
添加 www.conf 配置文件
> 將php安裝目錄下的 `/usr/local/php/etc/php-fpm.d/www.conf.default` 文件拷貝同目錄下并重命名為 `www.conf`
[root@localhost php-src-php-7.1.6]# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
添加php安裝目錄到系統(tǒng)環(huán)境變量
> 創(chuàng)建并打開文件php.sh
[root@localhost php-src-php-7.1.6]# vim /etc/profile.d/php.sh
> 添加內(nèi)容如下:
export PATH=$PATH:/usr/local/php/bin/:/usr/local/php/sbin/
> 保存并退出
:wq!
> 使用source立即生效剛剛添加的php環(huán)境變量
[root@localhost php-src-php-7.1.6]# source /etc/profile.d/php.sh
設(shè)置PHP日志目錄和php-fpm運(yùn)行進(jìn)程的ID文件目錄
php-fpm運(yùn)行進(jìn)程的ID文件也就是
php-fpm.sock其中設(shè)置php-fpm進(jìn)程目錄的用戶和用戶組為nginx,
有于我在安裝nginx時(shí)已經(jīng)創(chuàng)建, 在這里我就不創(chuàng)建了, 只是列舉
> 添加系統(tǒng)用戶組nginx (如果你沒有創(chuàng)建過系統(tǒng)用戶組nginx請(qǐng)創(chuàng)建)
[root@localhost php-src-php-7.1.6]# groupadd -r nginx
> 創(chuàng)建新的系統(tǒng)用戶nginx, 并添加到系統(tǒng)用戶組nginx, 設(shè)置不允許此用戶名登錄shell (如果你沒有創(chuàng)建過系統(tǒng)用戶nginx請(qǐng)創(chuàng)建)
[root@localhost php-src-php-7.1.6]# useradd -r -g nginx -s /sbin/nologin -d /usr/local/nginx -M nginx
> 說明一下上面創(chuàng)建系統(tǒng)用戶nginx所使用的選項(xiàng)什么意思
-r: 添加系統(tǒng)用戶( 這里指將要被創(chuàng)建的系統(tǒng)用戶nginx )
-g: 指定要?jiǎng)?chuàng)建的用戶所屬組( 這里指添加到新系統(tǒng)用戶nginx到nginx系統(tǒng)用戶組 )
-s: 新帳戶的登錄shell( `/sbin/nologin` 這里設(shè)置為將要被創(chuàng)建系統(tǒng)用戶nginx不能用來登錄系統(tǒng) )
-d: 新帳戶的主目錄( 這里指定將要被創(chuàng)建的系統(tǒng)用戶nginx的家目錄為 `/usr/local/nginx` )
-M: 不要?jiǎng)?chuàng)建用戶的主目錄( 也就是說將要被創(chuàng)建的系統(tǒng)用戶nginx不會(huì)在 `/home` 目錄下創(chuàng)建 `nginx` 家目錄 )
> 創(chuàng)建 `php-fpm` 日志目錄
[root@localhost php-src-php-7.1.6]# mkdir -p /var/log/php-fpm/
> 創(chuàng)建 `php-fpm` 進(jìn)程的ID(php-fpm.sock)文件運(yùn)行目錄
[root@localhost php-src-php-7.1.6]# mkdir -p /var/run/php-fpm
> 修改 `php-fpm` 進(jìn)程的ID(php-fpm.sock)文件運(yùn)行目錄的所屬用戶和組
[root@localhost php-src-php-7.1.6]# chown -R nginx:nginx /var/run/php-fpm/
修改session的目錄配置
> 創(chuàng)建 `session` 存放目錄
[root@localhost php-src-php-7.1.6]# mkdir -p /var/lib/php/session
> 修改 `session` 存放目錄的所屬用戶和組
[root@localhost php-src-php-7.1.6]# chown -R nginx:nginx /var/lib/php
> 再次修改 `php.ini` 文件
[root@localhost php-src-php-7.1.6]# vim /usr/local/php/etc/php.ini
> 找到 `session.save_path` 修改為如下內(nèi)容:
session.save_path = "/var/lib/php/session"
> 保存并退出
:wq!
設(shè)置php開機(jī)啟動(dòng)
> 修改系統(tǒng)配置目錄下的 `php-fpm` 文件可執(zhí)行權(quán)限
[root@localhost php-src-php-7.1.6]# chmod +x /etc/init.d/php-fpm
> 將系統(tǒng)配置目錄下的 `php-fpm` 添加到 `系統(tǒng)服務(wù)`
[root@localhost php-src-php-7.1.6]# chkconfig --add php-fpm
> 設(shè)置 `php-fpm` `系統(tǒng)服務(wù)` 為開機(jī)啟動(dòng)
[root@localhost php-src-php-7.1.6]# chkconfig php-fpm on
檢測(cè) php-fpm 系統(tǒng)服務(wù)是否啟動(dòng)成功
> 用 chkconfig 命令檢測(cè)一下服務(wù)是否運(yùn)行成功
[root@localhost php-src-php-7.1.6]# chkconfig --list | grep php-fpm
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
php-fpm 0:off 1:off 2:on 3:on 4:on 5:on 6:off
> 可見服務(wù)已經(jīng)在 第2 到 第5 運(yùn)行等級(jí)打開
> 同樣你也可以禁用 `php-fpm` 開機(jī)啟動(dòng)
[root@localhost php-src-php-7.1.6]# chkconfig php-fpm off
> 用 chkconfig 命令檢測(cè)一下服務(wù)是否運(yùn)行成功
[root@localhost php-src-php-7.1.6]# chkconfig --list | grep php-fpm
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
php-fpm 0:off 1:off 2:off 3:off 4:off 5:off 6:off
> 可見服務(wù)已經(jīng)在 第2 到 第5 運(yùn)行等級(jí)已經(jīng)關(guān)閉
測(cè)試PHP的配置文件是否無誤
[root@localhost php-src-php-7.1.6]# php-fpm -t
[18-Jun-2017 13:02:33] NOTICE: configuration file /usr/local/php/etc/php-fpm.conf test is successful
- 1
- 2
出現(xiàn)上面的提示也就是測(cè)試配置文件通過沒有問題, 可以正式使用php服務(wù)了
啟動(dòng)php系統(tǒng)服務(wù)
> 使用 `systemctl start` + `服務(wù)名` 啟動(dòng)系統(tǒng)服務(wù)
[root@localhost php-src-php-7.1.6]# systemctl start php-fpm.service
查看php系統(tǒng)服務(wù)狀態(tài)
> 使用 `systemctl status` + `服務(wù)名` 查看系統(tǒng)服務(wù)狀態(tài)
[root@localhost php-src-php-7.1.6]# systemctl status php-fpm.service
● php-fpm.service - LSB: starts php-fpm
Loaded: loaded (/etc/rc.d/init.d/php-fpm; bad; vendor preset: disabled)
Active: active (running) since Sun 2017-06-18 13:05:26 EDT; 2min 46s ago
Docs: man:systemd-sysv-generator(8)
Process: 105210 ExecStart=/etc/rc.d/init.d/php-fpm start (code=exited, status=0/SUCCESS)
Memory: 11.0M
CGroup: /system.slice/php-fpm.service
├─105212 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
├─105213 php-fpm: pool www
├─105214 php-fpm: pool www
└─105215 php-fpm: pool www
Jun 18 13:05:19 localhost.localdomain systemd[1]: Starting LSB: starts php-fpm...
Jun 18 13:05:24 localhost.localdomain php-fpm[105210]: Starting php-fpm done
Jun 18 13:05:26 localhost.localdomain systemd[1]: Started LSB: starts php-fpm.
你可以看到一個(gè)綠色的
active (running)說明系統(tǒng)服務(wù)php-fpm已經(jīng)在工作服務(wù)了,有沒有覺得自從RedHat系統(tǒng)到7以后, 越來越舒心了(哈哈)
CLI查看php版本信息
[root@localhost ~]# php -v
PHP 7.1.6 (cli) (built: Jun 25 2017 13:42:29) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.1.6, Copyright (c) 1999-2017, by Zend Technologies
修改nginx配置文件使之使用nginx反向php解釋器
修改nginx配置文件使之使用nginx反向php解釋器, 也就是php-fpm它其實(shí)就是cgi
> 說明一下我在安裝的nginx是將配置文件放在 `/etc/nginx/` 目錄下
> 修改配置文件如下:
server {
listen 80;
server_name www.nginx.dev;
#charset koi8-r;
access_log logs/nginx.dev.access.log main;
location / {
root /data/www/html;
index index.php index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /data/www/html;
}
location ~ ^/(images|javascript|js|css|flash|media|static)/ {
expires 30d;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
# root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www/html/$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
> 創(chuàng)建文件
[root@localhost php-src-php-7.1.6]# touch /data/www/html/index.php
> 編輯文件
[root@localhost php-src-php-7.1.6]# vim /data/www/html/index.php
> 輸入內(nèi)容
保存退出
:wq!
> 重新加載nginx配置
[root@localhost php-src-php-7.1.6]# systemctl reload nginx.service
瀏覽器訪問
至此PHP7.1也就編譯安裝成功了, 也和nginx建立了關(guān)系
網(wǎng)站名稱:CentOS7.3編譯安裝PHP7.1
文章分享:http://m.5511xx.com/article/copcopj.html


咨詢
建站咨詢
