這篇文章為大家帶來了關於php8.2的相關知識,其中主要介紹了教大家在centos stream 9中怎麼快速安裝php8.2套件?到底有多快呢?下面一起來看一下,希望對大家有幫助。
快如閃電的安裝php8.2套件(centos stream 9)
本文只考慮centos stream 9
#本文寫時間:2023-04-11,文章較新,是我自己仔細測試過的。
centos stream 9 是centos 的社群版,目前我看到的是阿里雲和百度雲有centos stream 9 的直接鏡像選擇,如果是用centos stream 8的話,阿里雲和百度雲和騰訊雲都有centos stream 8 的鏡像,但8 太老了,應該使用centos stream 9 。
另外,從外網看,Rocky Linux, AlmaLinux 這兩個都是centos的複製版本,使用已經都比較廣泛,也都可以用。
如果使用作業系統映像的話,我這樣操作
docker pull dokken/centos-stream-9:latest docker run -tid --name centos_stream_9 --privileged=true dokken/centos-stream-9:latest /usr/sbin/init docker exec -it centos_stream_9 /bin/bash
remi是一個php安裝倉庫。是rpm包。
到底有多快?今天的實測,全部軟體的安裝時間總共約 3 分鐘(不含作業系統)。
本文各軟體版本
CentOS Stream release 9 php 8.2.4 nginx 1.22.1 mysql 8.0.32 redis 6.2.7 git 2.39.1
#首先,安裝阿里的 centos 倉庫。 (centos stream 9)
cd /etc/yum.repos.d cp centos.repo centos.repo.bak cp centos-addons.repo centos-addons.repo.bak 现在修改 centos.repo 把小节[baseos]和小节 [appstream]和小节[crb]下面的 metalink= 。。。 都改成 # metalink= 。。。 然后,把小节[baseos]下面的 # metalink 下面加一行 baseurl=https://mirrors.aliyun.com/centos-stream/9-stream/BaseOS/x86_64/os/ 然后,把小节[appstream]下面的 # metalink 下面加一行 baseurl=https://mirrors.aliyun.com/centos-stream/9-stream/AppStream/x86_64/os/ 然后,把小节[crb]下面的 # metalink 下面加一行 baseurl=https://mirrors.aliyun.com/centos-stream/9-stream/CRB/x86_64/os/ dnf makecache dnf repolist
安裝 epel 倉庫。 (centos stream 9)
dnf install 'dnf-command(config-manager)' dnf --enable config-manager crb dnf install -y epel-release epel-next-release dnf makecache dnf repolist
此時,/etc/yum.repos.d 目錄下,多了epel的倉庫,且源是外國的。
安裝阿里的remi 的倉庫(centos stream 9)
dnf install -y https://mirrors.aliyun.com/remi/enterprise/remi-release-9.rpm sed -i 's/http*:\/\/rpms.remirepo.net/https:\/\/mirrors.aliyun.com\/remi/g' /etc/yum.repos.d/remi* sed -i 's/#baseurl/baseurl/g' /etc/yum.repos.d/remi* sed -i 's|^mirrorlist|#mirrorlist|' /etc/yum.repos.d/remi* dnf makecache dnf repolist dnf -y install yum-utils
安裝php 8.2(centos stream 9)
dnf install -y php82 php82-php-devel php82-php-fpm php82-php-mbstring php82-php-memcache php82-php-memcached php82-php-redis php82-php-mysqlnd php82-php-pdo php82-php-bcmath php82-php-xml php82-php-gd php82-php-gmp php82-php-igbinary php82-php-imagick php82-php-mcrypt php82-php-pdo_mysql php82-php-posix php82-php-simplexml php82-php-opcache php82-php-xsl php82-php-xmlwriter php82-php-xmlreader php82-php-swoole php82-php-zip php82-php-phalcon php82-php-yaml php82-php-yar php82-php-yaf php82-php-uuid
執行上面這個指令,大約1分鐘左右。快如閃電!
安裝阿里的composer 鏡像來源(centos stream 9)
rm /usr/bin/php ln -s /usr/bin/php82 /usr/bin/php curl -o /usr/local/bin/composer https://mirrors.aliyun.com/composer/composer.phar chmod +x /usr/local/bin/composer composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
安裝nginx 並整合php-fpm 服務(centos stream 9)
# 下面这个echo是一句命令,得一起复制 echo $'[nginx-stable] name=nginx stable repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=1 enabled=1 gpgkey=https://nginx.org/keys/nginx_signing.key module_hotfixes=true ' > /etc/yum.repos.d/nginx.repo # 上面是一条echo命令。 dnf makecache dnf install -y nginx systemctl enable nginx systemctl enable php82-php-fpm sed -i 's/user\ =\ apache/user\ =\ nginx/g' /etc/opt/remi/php82/php-fpm.d/www.conf sed -i 's/group\ =\ apache/group\ =\ nginx/g' /etc/opt/remi/php82/php-fpm.d/www.conf sed -i 's/listen\ =\ \/var\/opt\/remi\/php82\/run\/php-fpm\/www.sock/listen=9000/g' /etc/opt/remi/php82/php-fpm.d/www.conf rm -f /etc/nginx/conf.d/default.conf vi /etc/nginx/conf.d/default.conf
/etc/nginx/conf.d/default.conf 檔案內容如下
server { listen 80; server_name localhost; charset utf-8 ; access_log /var/log/nginx/host.access.log main; root /usr/share/nginx/html; index index.php index.html index.htm; error_page 404 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location / { try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; include fastcgi_params; } }
新增一個php 檔案如下:
vi /usr/share/nginx/html/1.php <?php phpinfo();
啟動php-fpm 和nginx並驗證安裝正確
systemctl start nginx systemctl start php82-php-fpm curl localhost/1.php # 如果能看到很多的大量输出,说明php和nginx正确安装了。
安裝mysql 8(centos stream 9)
dnf install -y https://repo.mysql.com/mysql80-community-release-el9-1.noarch.rpm # 下面这句安装mysql服务,时间大概1到3分钟左右。 dnf -y --enablerepo=mysql80-community install mysql-community-server systemctl enable mysqld systemctl start mysqld # 查看初始密码: grep 'temporary password' /var/log/mysqld.log # 用查看到的密码进入mysql 的 shell mysql -uroot -p
下面,整套設定新使用者流程,先改初始,再加新使用者並授權,再刪除舊用戶。
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'tb4Wn3BthR.'; flush privileges; set global validate_password.policy=LOW; create user 'root'@'%' identified by 'root1234'; ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root1234'; GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'; drop user root@localhost; flush privileges;
退出shell,重新進入。
現在就可以直接進入shell
mysql -uroot -proot1234 # 这句话查看用户的加密方式。 select user, host, plugin from mysql.user\G; # plugin: caching_sha2_password 表示老的MySQL客户端无法连接!
安裝redis 6 以及其他常用函式庫(centos stream 9)
dnf --enablerepo=remi install -y redis dnf install -y git wget vim zip unzip p7zip rsync crontabs supervisor net-tools python3 systemctl enable redis systemctl start redis
#總結(centos stream 9)
用了國內鏡像會速度極快,下載包的速度:3MB/秒,驚人的快
另外感謝阿里雲鏡像庫,非常快速和方便。 【推薦學習:《PHP影片教學》】
以上是快速安裝php8.2套件(centos stream 9)的詳細內容。更多資訊請關注PHP中文網其他相關文章!

熱AI工具

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

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

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

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

DVWA
Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中

SublimeText3漢化版
中文版,非常好用

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能