首頁 後端開發 PHP8 教你從零搭建php8環境

教你從零搭建php8環境

Mar 15, 2021 pm 05:30 PM
php php8

推薦:《PHP8教學

從零建置php環境-php8

一、下載

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.about.php選擇自己需要的選項

./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、額外說明
關於設定檔的一些說明參考:https:// www.cnblogs.com/xiaozong/p/5724984.html
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

以上是教你從零搭建php8環境的詳細內容。更多資訊請關注PHP中文網其他相關文章!

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Stock Market GPT

Stock Market GPT

人工智慧支援投資研究,做出更明智的決策

Clothoff.io

Clothoff.io

AI脫衣器

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

如何在PHP中設置錯誤報告級別? 如何在PHP中設置錯誤報告級別? Aug 31, 2025 am 06:48 AM

USEERERROR_REPORTING()TOSETERRERLELEVELSINPHP,SUSESASE_ALLFORDEMEVERMENTOR0FORPRODUCTION,and controldisplayorLoggingViaini_Set()ToenhancedebuggingandSecurity。

如何使用PHP中的時間戳? 如何使用PHP中的時間戳? Aug 31, 2025 am 08:55 AM

使用time()獲取當前時間戳,date()格式化時間,strtotime()轉換日期字符串為時間戳,複雜操作推薦DateTime類處理時區和日期運算。

如何在PHP中獲取對象的類名稱? 如何在PHP中獲取對象的類名稱? Sep 01, 2025 am 04:48 AM

useget_class($ object)togetTheclassNameAtruntime; 2.UsemyClass :: classForCompile-TimeClassErstrings,尤其是WithNamespaces; 3.InsideAclassMethod,get_class($ this)returnSthecurrentObjectObjectObjectObjectObject'ssclassName。

==和=== PHP中有什麼區別? ==和=== PHP中有什麼區別? Sep 01, 2025 am 07:50 AM

===要求值和類型都相同,==只關心值是否相等。例如5=="5"為true,但5==="5"為false,因類型不同。 ===無類型轉換,更安全嚴格。

如何在PHP中加密和解密數據? 如何在PHP中加密和解密數據? Sep 01, 2025 am 04:11 AM

Useopenssl_encrypt()andopenssl_decrypt()withAES-256-CBCforsecurePHPencryption.GeneratearandomIVperencryption,derivekeyviaSHA-256,andstoreIVwithciphertextusingbase64encoding.Fordecryption,extractIVandregeneratekeytorecoverplaintext.Alwaysvalidatedecry

233樂園網頁版點開即玩不用下載入口 233樂園點開即玩網址 233樂園網頁版點開即玩不用下載入口 233樂園點開即玩網址 Sep 02, 2025 pm 02:03 PM

233樂園網頁版點開即玩的入口是https://www.233leyuan.com,該平台無需下載,支持直接在線暢玩,提供豐富的遊戲類型、流暢的操作體驗及完善的社區互動功能。

動漫共和國在線觀看高清網址 動漫共和國官網在線觀看免費 動漫共和國在線觀看高清網址 動漫共和國官網在線觀看免費 Sep 02, 2025 pm 02:09 PM

動漫共和國在線觀看高清網址是https://www.dmgmhg.com/,該平台資源豐富,涵蓋國內外熱門動漫,支持高清播放、離線緩存和彈幕互動,界面簡潔,觀看體驗流暢。

苗族古歌的非遺形式是哪種 螞蟻新村9月2日答案最新 苗族古歌的非遺形式是哪種 螞蟻新村9月2日答案最新 Sep 02, 2025 pm 02:21 PM

相信有的朋友還不了解苗族古歌的非遺形式是哪種 螞蟻新村9月2日答案最新,下面由php的小編為您帶來這方面的答案,快來看看吧。立即進入“各種好用的網站推薦☜☜☜☜☜點擊進入”;螞

See all articles