一、下載
1、https://www.php.net/distributions/php-8.0.0.tar.gz下載到本地,檔案傳輸上傳到 /usr/local/src/
2、wget -P /usr/local/src/ https://www.php.net/distributions/php-8.0.0.tar.gz
二、解壓、編譯、安裝
1、解壓縮
> cd /usr/local/src/
> tar xzf php-8.0.0.tar.gz
> cd php-8.0.0
登入後複製
2、設定編譯引數,參考https://www.php.net/manual/zh... 選擇自己需要的選項
./configure --prefix=/usr/local/php8 --with-config-file-path=/usr/local/php8/etc --with-fpm-user=www --with-fpm-group=www --with-curl --with-openssl --with-mysqli --with-pdo-mysql --with-iconv --with-mhash --with-zlib --enable-mbstring --enable-gd --enable-gd-jis-conv --enable-sockets --enable-fpm --enable- --enable-xml --enable-pdo --enable-cli --enable-pcntl --enable-soap --enable-opcache --enable-fileinfo --disable-rpath --enable-mysqlnd --with-zip --enable-simplexml --with-libxml --with-sqlite3 --with-pdo-sqlite --enable-phar --enable-tokenizer --enable-cgi
登入後複製
問題1:
configure: error: Package requirements (libxml-2.0 >= 2.9.0) were not met:
Package 'libxml-2.0', required by 'virtual:world', not found
Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.
Alternatively, you may set the environment variables LIBXML_CFLAGS
and LIBXML_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
登入後複製
問題1解決:
> yum install libxml2-devel
登入後複製
問題2:
configure: error: Package requirements (sqlite3 > 3.7.4) were not met:
登入後複製
問題2解決:
> yum install sqlite-devel
登入後複製
問題3:
configure: error: Package requirements (libcurl >= 7.29.0) were not met:
登入後複製
問題3解決:
> yum install libcurl-devel
登入後複製
問題4:
configure: error: Package requirements (libpng) were not met:
登入後複製
問題4解決:
> yum install libpng libpng-devel
登入後複製
問題5:
configure: error: Package requirements (oniguruma) were not met:
登入後複製
問題5解決:
> cd /usr/local/src/
> wget http://ftp.altlinux.org/pub/distributions/ALTLinux/Sisyphus/x86_64/RPMS.classic/liboniguruma5-6.9.6-alt1.x86_64.rpm -O liboniguruma5-6.9.6-alt1.x86_64.rpm
> rpm -ivh liboniguruma5-6.9.6-alt1.x86_64.rpm
> wget http://ftp.altlinux.org/pub/distributions/ALTLinux/Sisyphus/x86_64/RPMS.classic/liboniguruma-devel-6.9.6-alt1.x86_64.rpm -O liboniguruma-devel-6.9.6-alt1.x86_64.rpm
> rpm liboniguruma-devel-6.9.6-alt1.x86_64.rpmcli
登入後複製
問題6:
configure: error: Package requirements (libzip >= 0.11 libzip != 1.3.1 libzip != 1.7.0) were not met:
登入後複製
問題6解決:
> yum install libzip libzip-devel
登入後複製
設定編譯引數成功
+--------------------------------------------------------------------+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+
Thank you for using PHP.
登入後複製
3、編譯原始碼
> make -j2 # 這裡是依賴系統cpu核心數進行編譯,對效能有一定提升,通常利用核心數不要超過一半,
4、安裝
make install
登入後複製
安裝成功
[root@54skyer php-8.0.0]# make install
Installing shared extensions: /usr/local/php8/lib/php/extensions/no-debug-non-zts-20200930/
Installing PHP CLI binary: /usr/local/php8/bin/
Installing PHP CLI man page: /usr/local/php8/php/man/man1/
Installing PHP FPM binary: /usr/local/php8/sbin/
Installing PHP FPM defconfig: /usr/local/php8/etc/
Installing PHP FPM man page: /usr/local/php8/php/man/man8/
Installing PHP FPM status page: /usr/local/php8/php/php/fpm/
Installing phpdbg binary: /usr/local/php8/bin/
Installing phpdbg man page: /usr/local/php8/php/man/man1/
Installing PHP CGI binary: /usr/local/php8/bin/
Installing PHP CGI man page: /usr/local/php8/php/man/man1/
Installing build environment: /usr/local/php8/lib/php/build/
Installing header files: /usr/local/php8/include/php/
Installing helper programs: /usr/local/php8/bin/
program: phpize
program: php-config
Installing man pages: /usr/local/php8/php/man/man1/
page: phpize.1
page: php-config.1
/usr/local/src/php-8.0.0/build/shtool install -c ext/phar/phar.phar /usr/local/php8/bin/phar.phar
ln -s -f phar.phar /usr/local/php8/bin/phar
Installing PDO headers: /usr/local/php8/include/php/ext/pdo/
登入後複製
5、新增環境變數
> vim /etc/profile # 在檔案末尾加入
# PATH=$PATH:/usr/local/php8/bin/
# export PATH
# :wq 儲存並退出
> source /etc/profile # 立刻生效設定
> php -v # 獲得如下資訊
php -v
PHP 8.0.0 (cli) (built: Dec 15 2020 02:46:59) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies
登入後複製
6、獲取預設設定
// 複製php.ini到編譯設定引數指定的目錄。php.ini在解壓的原始碼目錄裡
> cp /usr/local/src/php-8.0.0/php.ini-production /usr/local/php8/etc/php.ini
// 複製一份php-fpm的設定模版檔案到同級目錄 方便備份和修改
> cp /usr/local/php8/etc/php-fpm.conf.default /usr/local/php8/etc/php-fpm.conf
// 複製一份php-fpm的擴充套件設定模板檔案到同級目錄 方便備份和修改
> cp /usr/local/php8/etc/php-fpm.d/www.conf.default /usr/local/php8/etc/php-fpm.d/www.conf
// 複製開啟自起指令碼到系統啟動自動載入指令碼目錄。fpm/init.d.php-fpm在解壓的原始碼目錄裡
> cp /usr/local/src/php-8.0.0/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
登入後複製
7、開機自啟動
設定命令可被執行
> chmod +x /etc/init.d/php-fpm # 新增可執行許可權
登入後複製
檢驗自啟動指令碼
> service php-fpm start # 檢驗服務啟動
> service php-fpm stop # 檢驗服務關閉
// 均正常提示
> chkconfig php-fpm on # 設定開機自動執行php-fpm開機自啟動指令碼
> reboot # 重新啟動,ssh重連
# 重新啟動後
[root@54skyer ~]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1097/nginx: master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1061/sshd
tcp 0 0 0.0.0.0:16379 0.0.0.0:* LISTEN 1090/redis-server 0
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 1083/php-fpm: maste
登入後複製
7、額外說明
關於組態檔的一些說明
php-fpm.conf是PHP-FPM特有的組態檔
php.ini是所有php模式中必須的組態檔
兩者的區別是,php-fpm.conf是PHP-FPM程序管理器的組態檔,php.ini是PHP解析器的組態檔
有的PHP版本的組態檔路徑中還有/fpm.d/www.conf組態檔
這是php-fpm.conf設定的檔案的擴充套件檔案,可以開啟php-fpm.conf檔案檢視
; include=fpm.d/*.conf
登入後複製
我們可以使用php-fpm.conf設定慢紀錄檔
我們是可以開啟慢紀錄檔功能的。
slowlog = /usr/local/var/log/php-fpm.log.slow
request_slowlog_timeout = 5s
登入後複製
php入門到就業線上直播課:
以上就是一步步教你如何搭建php8環境(附常見問題解決辦法)的詳細內容,更多請關注TW511.COM其它相關文章!