首頁  >  文章  >  後端開發  >  教你最快速度安裝php8.2套件(ubuntu 20.04 focal)

教你最快速度安裝php8.2套件(ubuntu 20.04 focal)

藏色散人
藏色散人轉載
2023-01-13 10:03:364726瀏覽

這篇文章為大家帶來了關於php8.2的相關知識,其中主要介紹了教大家怎麼快速安裝php8.2套件?到底有多快呢?大概可能20分鐘左右...下面一起來看一下,希望對大家有幫助。

快速安裝php8.2套件(ubuntu 20.04 focal)

到底有多快?我這邊嘗試的結果是總共大約 20 分鐘左右(不含作業系統)。

另外,同樣是我的電腦,同樣阿里雲鏡像庫,裝centos 系統各類軟體含php 就很快,但裝這個ubuntu 就比較慢,原因不太清楚(可能的一個原因是因為ubuntu 用的人太多,阿里限制了來源的下載速率來稍微省點錢。)。

本文各軟體版本

ubuntu 20.04
php 8.2.1
nginx 1.22.1
mysql 8.0.31
redis 7.0.7
git 2.24.4

首先,安裝阿利的倉庫

首先必须 apt update
安装 vim

vim /etc/apt/sources.list
内容如下,就是搞阿里云镜像。但是http的,被我改的。不搞无法更新。
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

然后
apt update

apt install -y --reinstall ca-certificates

现在,再把阿里云镜像库中的 http 改成标准的 https,
vim /etc/apt/sources.list

deb https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse

# deb https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
然后。再次
apt update

已安裝php 8

apt install -y gnupg gosu curl ca-certificates zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python2 dnsutils systemd gnupg2 lsb-release ubuntu-keyring

上面的命令需要选择多个选项。选亚洲 asia。选上海 shanghai

curl -sS 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x14aa40ec0831756756d7f66c4f4ea0aae5267a6c' | gpg --dearmor | tee /usr/share/keyrings/ppa_ondrej_php.gpg > /dev/null

echo "deb [signed-by=/usr/share/keyrings/ppa_ondrej_php.gpg] https://ppa.launchpadcontent.net/ondrej/php/ubuntu focal main" > /etc/apt/sources.list.d/ppa_ondrej_php.list


apt-get update

apt-get install -y php8.2-cli php8.2-dev  php8.2-pgsql php8.2-sqlite3 php8.2-gd  php8.2-curl  php8.2-imap php8.2-mysql php8.2-mbstring  php8.2-xml php8.2-zip php8.2-bcmath php8.2-soap   php8.2-intl php8.2-readline  php8.2-ldap  php8.2-msgpack php8.2-igbinary php8.2-redis php8.2-swoole  php8.2-memcached php8.2-pcov  php8.2-fpm php8.2-gmp php8.2-imagick php8.2-mcrypt php8.2-uuid php8.2-yaml

執行上面這些指令,大約15 分鐘左右,主要耗時就是這裡。

安裝阿里的composer 映像來源

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/

使用root 身分執行composer 指令,會提示輸入yes ,挺麻煩,則

vim /etc/environment

文字

export COMPOSER_ALLOW_SUPERUSER=1

然後

source /etc/environment

安裝nginx 並整合php-fpm 服務

curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor | tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null

gpg --dry-run --quiet --no-keyring --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg

echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/ubuntu `lsb_release -cs` nginx"  | tee /etc/apt/sources.list.d/nginx.list

apt update
apt install nginx

改php-fpm 配置。
sed -i 's/listen\ =\ \/run\/php\/php8.2-fpm.sock/listen\ =\ 127.0.0.1:9000/g' /etc/php/8.2/fpm/pool.d/www.conf


修改 /etc/nginx/nginx.conf
第一行 
user  www-data;

然后,
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 並驗證安裝正確

/etc/init.d/nginx start
/etc/init.d/php8.2-fpm start

curl localhost/1.php
# 如果能看到很多的大量输出,说明php和nginx正确安装了。

安裝mysql 8

apt install mysql-server-8.0 mysql-client-8.0



# 查看初始密码:
grep &#39;temporary password&#39; /var/log/mysqld.log

# 用查看到的密码进入mysql 的 shell
mysql -uroot -p

下面,整套設定新使用者流程,先改初始,再加新使用者並授權,再刪除老用戶。

ALTER USER &#39;root&#39;@&#39;localhost&#39; IDENTIFIED WITH mysql_native_password BY &#39;tb4Wn3BthR.&#39;;
flush privileges;

create user &#39;root&#39;@&#39;%&#39; identified by &#39;root1234&#39;;
ALTER USER &#39;root&#39;@&#39;%&#39; IDENTIFIED WITH mysql_native_password BY &#39;root1234&#39;;
GRANT ALL PRIVILEGES ON *.* TO &#39;root&#39;@&#39;%&#39;;
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 以及其他常用函式庫

說明,安裝redis 7 需要下二進位套件編譯,堅決不編譯,所以沒搞。

curl -fsSL https://packages.redis.io/gpg | gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg

echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/redis.list

apt-get update

apt-get install redis-stack-server

注意和上面版本不同,如想安裝redis5

#如想redis5,啥來源都不需要,直接

apt install redis-server

#總結

感謝阿里雲鏡像庫,但是速度不會太快。

推薦學習:《PHP影片教學

以上是教你最快速度安裝php8.2套件(ubuntu 20.04 focal)的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:learnku.com。如有侵權,請聯絡admin@php.cn刪除