正文
Windows Subsystem for Linux(简称WSL)是一个在Windows 10上能够运行原生Linux二进制可执行文件(ELF格式)的兼容层。
启用WSL
方式1
在 控制面板\所有控制面板项\程序和功能 中选择 启用或者关闭Windows功能
找到 适用于Linux的Windows子系统 并勾选,然后 确定 选择 立即重新启动
方式2
在开始菜单中点击Windows Powershell进入,或者在开始菜单中磁性贴中点击Windows Powershell进入。
输入Powershell命令,查看确认版本,是否满足WSL安装要求:
Get-ComputerInfo | Select WindowsProductName, WindowsVersion, WindowsInstallationType, OsServerLevel, OsVersion, OsHardwareAbstractionLayer
启用WSL:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
输入y或直接回车,电脑立即重启。重启后即成功启用了WSL。
Windows PowerShell
版权所有 (C) Microsoft Corporation。保留所有权利。
尝试新的跨平台 PowerShell https://aka.ms/pscore6
PS C:\Users\bai> Get-ComputerInfo | Select WindowsProductName, WindowsVersion, WindowsInstallationType, OsServerLevel, OsVersion, OsHardwareAbstractionLayer
WindowsProductName : Windows 10 Pro
WindowsVersion : 1903
WindowsInstallationType : Client
OsServerLevel :
OsVersion : 10.0.18362
OsHardwareAbstractionLayer : 10.0.18362.1
PS C:\Users\bai> Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
是否立即重启计算机以完成此操作?
[Y] Yes [N] No [?] 帮助 (默认值为“Y”):
升级WSL2
见 参考资料
安装CentOS
在 https://github.com/wsldl-pg/CentWSL/tags 下载 Centos包。
解压后放到指定目录下。
在目标目录中看到2个文件:rootfs.tar.gz 和 CentOS.exe。我们需要运行CentOS.exe,以便解压其中的文件并注册到WSL。 右键点击CentOS.exe并以管理员身份运行。
等一段时间,系统将自动进行初始化,完成后会有提示成功的消息,此时可按任意键退出安装。 如果时间过长,可以点击回车试试。
返回目录,看到多出了2个文件夹:rootfs、temp。
右击运行CentOS.exe,即成功登录系统了。
运行CentOS.exe后,查看安装的CentOS版本号:
rpm -q centos-release
输出:centos-release-7-6.1810.2.el7.centos.x86_64
或者:
cat /etc/redhat-release
输出:CentOS Linux release 7.6.1810 (Core)
可以看出,我们用的是 CentOS7.6 版。
在 WSL 系统中可以直接访问 windows 磁盘文件,可将一些安装软件包放在 D:\WslSoftbox
目录下,将网站web程序放在 D:\www
目录中。
而在 WSL 系统中的访问路径分别是 /mnt/d/WslSoftbox
和 /mnt/d/www
。当然 WSL 这样直接访问 windows 磁盘会有很大的性能问题。
后续使用中如果性能的降低超过了可忍受的程度,可以考虑将这两个目录移动到 WSL 的虚拟磁盘。
打开 Windows 安全中心 > 病毒和威胁防护设置 > 管理设置 > 添加或删除排除项 > 添加排除项,将上述两个目录排除, 这样会减少 windows 的系统性能占用。
看一下Linux 系统上的文件系统磁盘使用情况统计:
[root@HIGDQEEMO63U9NR yum.repos.d]# df -h
Filesystem Size Used Avail Use% Mounted on
rootfs 338G 14G 325G 4% /
none 338G 14G 325G 4% /dev
none 338G 14G 325G 4% /run
none 338G 14G 325G 4% /run/lock
none 338G 14G 325G 4% /run/shm
none 338G 14G 325G 4% /run/user
cgroup 338G 14G 325G 4% /sys/fs/cgroup
C:\ 140G 48G 92G 35% /mnt/c
D:\ 338G 14G 325G 4% /mnt/d
卸载CentOS
不想用了,在WSL上卸载CentOS,用 Windows Powershell 切换到安装目录,执行:
./CentOS.exe clean
配置yum源
我们把yum源切换为国内源,如阿里云的。
1.先备份
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
2.下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/
:
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
或者:
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
3.生成缓存
yum makecache
安装Nginx
我们可以编译安装,也可以选择yum方式安装。
yum方式安装
安装yum-utils,管理repository及扩展包的工具,细节参考下面资料。
sudo yum install yum-utils
设置nginx的yum仓库配置:
sudo vi /etc/yum.repos.d/nginx.repo
写入:
[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
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
执行:
sudo yum install nginx
安装完成。
查看版本:
[root@HIGDQEEMO63U9NR ~]# nginx -v
nginx version: nginx/1.20.1
[root@HIGDQEEMO63U9NR ~]#
由于 WSL的这个Centos包中 不能使用 systemd ,使用 service 时会出现错误提示, 这里不注册为 service ,而是使用软链接的方式来省略 nginx 命令的路径前缀。
ln -s /usr/sbin/nginx /usr/bin/nginx # 可以不执行
nginx # 启动服务,访问127.0.0.1可以看到nginx欢迎界面
nginx -s reload # 不停止服务重新载入配置文件
nginx -s stop # 停止服务
配置
看一下 /etc/nginx/nginx.conf
内容:
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
我们可以在最下面include后补充一句:
include /mnt/d/www/vhost/*.conf;
在/etc/nginx/conf.d/
目录下只有 default.conf
一个文件,就是上面Nginx欢迎页的配置,看一下内容:
server {
listen 80;
server_name localhost;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index 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 /usr/share/nginx/html;
}
# 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 /scripts$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;
#}
}
我们可以类似在D:\www\vhost\
中写一个自己的项目的配置文件abc.test.conf
:
server {
listen 80;
server_name abc.test;
location / {
root /mnt/d/www/abc;
index index.html index.htm;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
在D:\www\abc\
中写一个index.html文件,内容自己定义。
在 C:\Windows\System32\drivers\etc\hosts
文件最下面增加一行:
127.0.0.1 abc.test
然后启动Nginx:
nginx
如果已经启动了,那就重启(不停止服务重新载入配置文件):
nginx -s reload
打开浏览器,访问 abc.test ,可以看到效果。
停止服务:
nginx -s stop
安装PHP
我们使用Remi源安装PHP7.4。
安装 EPEL 存储库
yum install epel-release -y
安装Remi存储库
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
查看/etc/yum.repos.d
目录,多了的源配置文件:
[root@HIGDQEEMO63U9NR yum.repos.d]# ls -l
total 88
-rw-r--r-- 1 root root 2523 Aug 24 13:35 CentOS-Base.repo
-rw-r--r-- 1 root root 1664 Nov 23 2018 CentOS-Base.repo.backup
-rw-r--r-- 1 root root 1309 Nov 23 2018 CentOS-CR.repo
-rw-r--r-- 1 root root 649 Nov 23 2018 CentOS-Debuginfo.repo
-rw-r--r-- 1 root root 314 Nov 23 2018 CentOS-fasttrack.repo
-rw-r--r-- 1 root root 630 Nov 23 2018 CentOS-Media.repo
-rw-r--r-- 1 root root 1331 Nov 23 2018 CentOS-Sources.repo
-rw-r--r-- 1 root root 5701 Nov 23 2018 CentOS-Vault.repo
-rw-r--r-- 1 root root 664 Dec 26 2020 epel.repo
-rw-r--r-- 1 root root 664 Aug 25 19:07 epel.repo.backup
-rw-r--r-- 1 root root 1050 Nov 1 2020 epel.repo.rpmnew
-rw-r--r-- 1 root root 1149 Nov 1 2020 epel-testing.repo
-rw-r--r-- 1 root root 398 Aug 24 14:13 nginx.repo
-rw-r--r-- 1 root root 446 Jan 5 2021 remi-glpi91.repo
-rw-r--r-- 1 root root 446 Jan 5 2021 remi-glpi92.repo
-rw-r--r-- 1 root root 446 Jan 5 2021 remi-glpi93.repo
-rw-r--r-- 1 root root 446 Jan 5 2021 remi-glpi94.repo
-rw-r--r-- 1 root root 855 Jan 5 2021 remi-modular.repo
-rw-r--r-- 1 root root 456 Jan 5 2021 remi-php54.repo
-rw-r--r-- 1 root root 1314 Jan 5 2021 remi-php70.repo
-rw-r--r-- 1 root root 1314 Jan 5 2021 remi-php71.repo
-rw-r--r-- 1 root root 1314 Jan 5 2021 remi-php72.repo
-rw-r--r-- 1 root root 1314 Jan 5 2021 remi-php73.repo
-rw-r--r-- 1 root root 1314 Jan 5 2021 remi-php74.repo
-rw-r--r-- 1 root root 1314 Jan 5 2021 remi-php80.repo
-rw-r--r-- 1 root root 2605 Jan 5 2021 remi.repo
-rw-r--r-- 1 root root 750 Jan 5 2021 remi-safe.repo
查看可以安装的 php 版本:
yum list php*
安装 PHP 7.4:
yum --enablerepo=remi-php74 install php
输出:
[root@HIGDQEEMO63U9NR yum.repos.d]# yum --enablerepo=remi-php74 install php
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* remi-php74: mirrors.tuna.tsinghua.edu.cn
* remi-safe: mirrors.tuna.tsinghua.edu.cn
* updates: mirrors.aliyun.com
remi-php74 | 3.0 kB 00:00:00
remi-php74/primary_db | 247 kB 00:00:00
Resolving Dependencies
--> Running transaction check
---> Package php.x86_64 0:7.4.23-1.el7.remi will be installed
--> Processing Dependency: httpd-mmn = 20120211x8664 for package: php-7.4.23-1.el7.remi.x86_64
--> Processing Dependency: php-cli(x86-64) = 7.4.23-1.el7.remi for package: php-7.4.23-1.el7.remi.x86_64
--> Processing Dependency: php-common(x86-64) = 7.4.23-1.el7.remi for package: php-7.4.23-1.el7.remi.x86_64
--> Processing Dependency: php-sodium(x86-64) = 7.4.23-1.el7.remi for package: php-7.4.23-1.el7.remi.x86_64
--> Processing Dependency: httpd for package: php-7.4.23-1.el7.remi.x86_64
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-97.el7.centos will be installed
--> Processing Dependency: httpd-tools = 2.4.6-97.el7.centos for package: httpd-2.4.6-97.el7.centos.x86_64
--> Processing Dependency: system-logos >= 7.92.1-1 for package: httpd-2.4.6-97.el7.centos.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-97.el7.centos.x86_64
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-97.el7.centos.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-97.el7.centos.x86_64
---> Package php-cli.x86_64 0:7.4.23-1.el7.remi will be installed
---> Package php-common.x86_64 0:7.4.23-1.el7.remi will be installed
--> Processing Dependency: php-json(x86-64) = 7.4.23-1.el7.remi for package: php-common-7.4.23-1.el7.remi.x86_64
---> Package php-sodium.x86_64 0:7.4.23-1.el7.remi will be installed
--> Processing Dependency: libsodium.so.23()(64bit) for package: php-sodium-7.4.23-1.el7.remi.x86_64
--> Running transaction check
---> Package apr.x86_64 0:1.4.8-7.el7 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
---> Package centos-logos.noarch 0:70.0.6-3.el7.centos will be installed
---> Package httpd-tools.x86_64 0:2.4.6-97.el7.centos will be installed
---> Package libsodium.x86_64 0:1.0.18-1.el7 will be installed
---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
---> Package php-json.x86_64 0:7.4.23-1.el7.remi will be installed
--> Finished Dependency Resolution
Dependencies Resolved
==================================================================================================================================
Package Arch Version Repository Size
==================================================================================================================================
Installing:
php x86_64 7.4.23-1.el7.remi remi-php74 3.4 M
Installing for dependencies:
apr x86_64 1.4.8-7.el7 base 104 k
apr-util x86_64 1.5.2-6.el7 base 92 k
centos-logos noarch 70.0.6-3.el7.centos base 21 M
httpd x86_64 2.4.6-97.el7.centos updates 2.7 M
httpd-tools x86_64 2.4.6-97.el7.centos updates 93 k
libsodium x86_64 1.0.18-1.el7 epel 147 k
mailcap noarch 2.1.41-2.el7 base 31 k
php-cli x86_64 7.4.23-1.el7.remi remi-php74 5.2 M
php-common x86_64 7.4.23-1.el7.remi remi-php74 1.2 M
php-json x86_64 7.4.23-1.el7.remi remi-php74 72 k
php-sodium x86_64 7.4.23-1.el7.remi remi-php74 84 k
Transaction Summary
==================================================================================================================================
Install 1 Package (+11 Dependent packages)
Total download size: 34 M
Installed size: 73 M
Is this ok [y/d/N]: y
Downloading packages:
(1/12): apr-1.4.8-7.el7.x86_64.rpm | 104 kB 00:00:00
(2/12): apr-util-1.5.2-6.el7.x86_64.rpm | 92 kB 00:00:00
(3/12): mailcap-2.1.41-2.el7.noarch.rpm | 31 kB 00:00:00
(4/12): httpd-tools-2.4.6-97.el7.centos.x86_64.rpm | 93 kB 00:00:00
(5/12): libsodium-1.0.18-1.el7.x86_64.rpm | 147 kB 00:00:00
warning: /var/cache/yum/x86_64/7/remi-php74/packages/php-7.4.23-1.el7.remi.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 00f97f56: NOKEY
Public key for php-7.4.23-1.el7.remi.x86_64.rpm is not installed
(6/12): php-7.4.23-1.el7.remi.x86_64.rpm | 3.4 MB 00:00:01
(7/12): php-common-7.4.23-1.el7.remi.x86_64.rpm | 1.2 MB 00:00:00
(8/12): php-json-7.4.23-1.el7.remi.x86_64.rpm | 72 kB 00:00:00
(9/12): php-sodium-7.4.23-1.el7.remi.x86_64.rpm | 84 kB 00:00:00
(10/12): php-cli-7.4.23-1.el7.remi.x86_64.rpm | 5.2 MB 00:00:03
(11/12): httpd-2.4.6-97.el7.centos.x86_64.rpm | 2.7 MB 00:00:04
(12/12): centos-logos-70.0.6-3.el7.centos.noarch.rpm | 21 MB 00:00:07
----------------------------------------------------------------------------------------------------------------------------------
Total 4.7 MB/s | 34 MB 00:00:07
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
Importing GPG key 0x00F97F56:
Userid : "Remi Collet <RPMS@FamilleCollet.com>"
Fingerprint: 1ee0 4cce 88a4 ae4a a29a 5df5 004e 6f47 00f9 7f56
Package : remi-release-7.9-1.el7.remi.noarch (installed)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-remi
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
Installing : php-json-7.4.23-1.el7.remi.x86_64 1/12
Installing : php-common-7.4.23-1.el7.remi.x86_64 2/12
Installing : apr-1.4.8-7.el7.x86_64 3/12
Installing : apr-util-1.5.2-6.el7.x86_64 4/12
Installing : httpd-tools-2.4.6-97.el7.centos.x86_64 5/12
Installing : php-cli-7.4.23-1.el7.remi.x86_64 6/12
Installing : centos-logos-70.0.6-3.el7.centos.noarch 7/12
Installing : mailcap-2.1.41-2.el7.noarch 8/12
Installing : httpd-2.4.6-97.el7.centos.x86_64 9/12
Installing : libsodium-1.0.18-1.el7.x86_64 10/12
Installing : php-sodium-7.4.23-1.el7.remi.x86_64 11/12
Installing : php-7.4.23-1.el7.remi.x86_64 12/12
Verifying : php-7.4.23-1.el7.remi.x86_64 1/12
Verifying : apr-1.4.8-7.el7.x86_64 2/12
Verifying : libsodium-1.0.18-1.el7.x86_64 3/12
Verifying : php-common-7.4.23-1.el7.remi.x86_64 4/12
Verifying : mailcap-2.1.41-2.el7.noarch 5/12
Verifying : php-sodium-7.4.23-1.el7.remi.x86_64 6/12
Verifying : apr-util-1.5.2-6.el7.x86_64 7/12
Verifying : php-json-7.4.23-1.el7.remi.x86_64 8/12
Verifying : httpd-2.4.6-97.el7.centos.x86_64 9/12
Verifying : httpd-tools-2.4.6-97.el7.centos.x86_64 10/12
Verifying : centos-logos-70.0.6-3.el7.centos.noarch 11/12
Verifying : php-cli-7.4.23-1.el7.remi.x86_64 12/12
Installed:
php.x86_64 0:7.4.23-1.el7.remi
Dependency Installed:
apr.x86_64 0:1.4.8-7.el7 apr-util.x86_64 0:1.5.2-6.el7 centos-logos.noarch 0:70.0.6-3.el7.centos
httpd.x86_64 0:2.4.6-97.el7.centos httpd-tools.x86_64 0:2.4.6-97.el7.centos libsodium.x86_64 0:1.0.18-1.el7
mailcap.noarch 0:2.1.41-2.el7 php-cli.x86_64 0:7.4.23-1.el7.remi php-common.x86_64 0:7.4.23-1.el7.remi
php-json.x86_64 0:7.4.23-1.el7.remi php-sodium.x86_64 0:7.4.23-1.el7.remi
Complete!
[root@HIGDQEEMO63U9NR yum.repos.d]#
查看版本:
[root@HIGDQEEMO63U9NR yum.repos.d]# php -v
PHP 7.4.23 (cli) (built: Aug 24 2021 16:33:30) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
安装拓展(错误)
安装拓展,扩展安装格式 php74-php-扩展模块名 ,缺什么扩展只要按照格式安装相应模块即可(这种方法有问题,具体看下面):
yum install -y php74-php-fpm php74-php-cli php74-php-bcmath php74-php-gd php74-php-json php74-php-mbstring php74-php-mcrypt php74-php-mysqlnd php74-php-opcache php74-php-pdo php74-php-pecl-mcrypt php74-php-xml php74-php-zip
输出:
[root@HIGDQEEMO63U9NR yum.repos.d]# yum install -y php74-php-fpm php74-php-cli php74-php-bcmath php74-php-gd php74-php-json php74-php-mbstring php74-php-mcrypt php74-php-mysqlnd php74-php-opcache php74-php-pdo php74-php-pecl-mcrypt php74-php-xml php74-php-zip
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* remi-safe: mirrors.tuna.tsinghua.edu.cn
* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package php74-php-bcmath.x86_64 0:7.4.23-1.el7.remi will be installed
--> Processing Dependency: php74-php-common(x86-64) = 7.4.23-1.el7.remi for package: php74-php-bcmath-7.4.23-1.el7.remi.x86_64
---> Package php74-php-cli.x86_64 0:7.4.23-1.el7.remi will be installed
---> Package php74-php-fpm.x86_64 0:7.4.23-1.el7.remi will be installed
---> Package php74-php-gd.x86_64 0:7.4.23-1.el7.remi will be installed
---> Package php74-php-json.x86_64 0:7.4.23-1.el7.remi will be installed
---> Package php74-php-mbstring.x86_64 0:7.4.23-1.el7.remi will be installed
---> Package php74-php-mysqlnd.x86_64 0:7.4.23-1.el7.remi will be installed
---> Package php74-php-opcache.x86_64 0:7.4.23-1.el7.remi will be installed
---> Package php74-php-pdo.x86_64 0:7.4.23-1.el7.remi will be installed
---> Package php74-php-pecl-mcrypt.x86_64 0:1.0.4-1.el7.remi will be installed
--> Processing Dependency: php74-runtime for package: php74-php-pecl-mcrypt-1.0.4-1.el7.remi.x86_64
--> Processing Dependency: php74-runtime(remi)(x86-64) for package: php74-php-pecl-mcrypt-1.0.4-1.el7.remi.x86_64
---> Package php74-php-pecl-zip.x86_64 0:1.19.3-2.el7.remi will be installed
---> Package php74-php-xml.x86_64 0:7.4.23-1.el7.remi will be installed
--> Running transaction check
---> Package php74-php-common.x86_64 0:7.4.23-1.el7.remi will be installed
---> Package php74-runtime.x86_64 0:1.0-3.el7.remi will be installed
--> Finished Dependency Resolution
Dependencies Resolved
==================================================================================================================================
Package Arch Version Repository Size
==================================================================================================================================
Installing:
php74-php-bcmath x86_64 7.4.23-1.el7.remi remi-safe 82 k
php74-php-cli x86_64 7.4.23-1.el7.remi remi-safe 3.4 M
php74-php-fpm x86_64 7.4.23-1.el7.remi remi-safe 1.8 M
php74-php-gd x86_64 7.4.23-1.el7.remi remi-safe 87 k
php74-php-json x86_64 7.4.23-1.el7.remi remi-safe 76 k
php74-php-mbstring x86_64 7.4.23-1.el7.remi remi-safe 486 k
php74-php-mysqlnd x86_64 7.4.23-1.el7.remi remi-safe 194 k
php74-php-opcache x86_64 7.4.23-1.el7.remi remi-safe 269 k
php74-php-pdo x86_64 7.4.23-1.el7.remi remi-safe 124 k
php74-php-pecl-mcrypt x86_64 1.0.4-1.el7.remi remi-safe 23 k
php74-php-pecl-zip x86_64 1.19.3-2.el7.remi remi-safe 53 k
php74-php-xml x86_64 7.4.23-1.el7.remi remi-safe 173 k
Installing for dependencies:
php74-php-common x86_64 7.4.23-1.el7.remi remi-safe 695 k
php74-runtime x86_64 1.0-3.el7.remi remi-safe 1.1 M
Transaction Summary
==================================================================================================================================
Install 12 Packages (+2 Dependent packages)
Total download size: 8.6 M
Installed size: 28 M
Downloading packages:
(1/14): php74-php-bcmath-7.4.23-1.el7.remi.x86_64.rpm | 82 kB 00:00:01
(2/14): php74-php-json-7.4.23-1.el7.remi.x86_64.rpm | 76 kB 00:00:00
(3/14): php74-php-common-7.4.23-1.el7.remi.x86_64.rpm | 695 kB 00:00:02
(4/14): php74-php-mysqlnd-7.4.23-1.el7.remi.x86_64.rpm | 194 kB 00:00:00
(5/14): php74-php-gd-7.4.23-1.el7.remi.x86_64.rpm | 87 kB 00:00:02
(6/14): php74-php-mbstring-7.4.23-1.el7.remi.x86_64.rpm | 486 kB 00:00:01
(7/14): php74-php-opcache-7.4.23-1.el7.remi.x86_64.rpm | 269 kB 00:00:00
(8/14): php74-php-pecl-mcrypt-1.0.4-1.el7.remi.x86_64.rpm | 23 kB 00:00:00
(9/14): php74-php-pecl-zip-1.19.3-2.el7.remi.x86_64.rpm | 53 kB 00:00:00
(10/14): php74-php-xml-7.4.23-1.el7.remi.x86_64.rpm | 173 kB 00:00:00
(11/14): php74-php-pdo-7.4.23-1.el7.remi.x86_64.rpm | 124 kB 00:00:00
(12/14): php74-runtime-1.0-3.el7.remi.x86_64.rpm | 1.1 MB 00:00:01
(13/14): php74-php-fpm-7.4.23-1.el7.remi.x86_64.rpm | 1.8 MB 00:00:05
(14/14): php74-php-cli-7.4.23-1.el7.remi.x86_64.rpm | 3.4 MB 00:00:06
----------------------------------------------------------------------------------------------------------------------------------
Total 1.3 MB/s | 8.6 MB 00:00:06
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : php74-runtime-1.0-3.el7.remi.x86_64 1/14
Installing : php74-php-json-7.4.23-1.el7.remi.x86_64 2/14
Installing : php74-php-common-7.4.23-1.el7.remi.x86_64 3/14
Installing : php74-php-pdo-7.4.23-1.el7.remi.x86_64 4/14
Installing : php74-php-mysqlnd-7.4.23-1.el7.remi.x86_64 5/14
Installing : php74-php-pecl-zip-1.19.3-2.el7.remi.x86_64 6/14
Installing : php74-php-mbstring-7.4.23-1.el7.remi.x86_64 7/14
Installing : php74-php-cli-7.4.23-1.el7.remi.x86_64 8/14
Installing : php74-php-pecl-mcrypt-1.0.4-1.el7.remi.x86_64 9/14
Installing : php74-php-bcmath-7.4.23-1.el7.remi.x86_64 10/14
Installing : php74-php-xml-7.4.23-1.el7.remi.x86_64 11/14
Installing : php74-php-opcache-7.4.23-1.el7.remi.x86_64 12/14
Installing : php74-php-gd-7.4.23-1.el7.remi.x86_64 13/14
Installing : php74-php-fpm-7.4.23-1.el7.remi.x86_64 14/14
Verifying : php74-php-pecl-zip-1.19.3-2.el7.remi.x86_64 1/14
Verifying : php74-php-mbstring-7.4.23-1.el7.remi.x86_64 2/14
Verifying : php74-php-cli-7.4.23-1.el7.remi.x86_64 3/14
Verifying : php74-php-pecl-mcrypt-1.0.4-1.el7.remi.x86_64 4/14
Verifying : php74-runtime-1.0-3.el7.remi.x86_64 5/14
Verifying : php74-php-mysqlnd-7.4.23-1.el7.remi.x86_64 6/14
Verifying : php74-php-bcmath-7.4.23-1.el7.remi.x86_64 7/14
Verifying : php74-php-xml-7.4.23-1.el7.remi.x86_64 8/14
Verifying : php74-php-pdo-7.4.23-1.el7.remi.x86_64 9/14
Verifying : php74-php-opcache-7.4.23-1.el7.remi.x86_64 10/14
Verifying : php74-php-json-7.4.23-1.el7.remi.x86_64 11/14
Verifying : php74-php-gd-7.4.23-1.el7.remi.x86_64 12/14
Verifying : php74-php-common-7.4.23-1.el7.remi.x86_64 13/14
Verifying : php74-php-fpm-7.4.23-1.el7.remi.x86_64 14/14
Installed:
php74-php-bcmath.x86_64 0:7.4.23-1.el7.remi php74-php-cli.x86_64 0:7.4.23-1.el7.remi
php74-php-fpm.x86_64 0:7.4.23-1.el7.remi php74-php-gd.x86_64 0:7.4.23-1.el7.remi
php74-php-json.x86_64 0:7.4.23-1.el7.remi php74-php-mbstring.x86_64 0:7.4.23-1.el7.remi
php74-php-mysqlnd.x86_64 0:7.4.23-1.el7.remi php74-php-opcache.x86_64 0:7.4.23-1.el7.remi
php74-php-pdo.x86_64 0:7.4.23-1.el7.remi php74-php-pecl-mcrypt.x86_64 0:1.0.4-1.el7.remi
php74-php-pecl-zip.x86_64 0:1.19.3-2.el7.remi php74-php-xml.x86_64 0:7.4.23-1.el7.remi
Dependency Installed:
php74-php-common.x86_64 0:7.4.23-1.el7.remi php74-runtime.x86_64 0:1.0-3.el7.remi
Complete!
[root@HIGDQEEMO63U9NR yum.repos.d]#
查看拓展:
[root@HIGDQEEMO63U9NR yum.repos.d]# php -m
[PHP Modules]
bz2
calendar
Core
ctype
curl
date
exif
fileinfo
filter
ftp
gettext
hash
iconv
json
libxml
openssl
pcntl
pcre
Phar
readline
Reflection
session
sockets
sodium
SPL
standard
tokenizer
zlib
[Zend Modules]
卸载拓展
发现这样安装php拓展并没有起作用,是没有指定仓库的原因。
先卸载,用yum remove name
会把依赖也卸载掉,导致系统崩溃,我们只卸载指定软件rpm -e --nodeps name
:
[root@HIGDQEEMO63U9NR ~]# yum remove php74-php-xml php74-php-zip
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package php74-php-pecl-zip.x86_64 0:1.19.3-2.el7.remi will be erased
---> Package php74-php-xml.x86_64 0:7.4.23-1.el7.remi will be erased
--> Finished Dependency Resolution
Dependencies Resolved
===============================================================================================
Package Arch Version Repository Size
===============================================================================================
Removing:
php74-php-pecl-zip x86_64 1.19.3-2.el7.remi @remi-safe 133 k
php74-php-xml x86_64 7.4.23-1.el7.remi @remi-safe 383 k
Transaction Summary
===============================================================================================
Remove 2 Packages
Installed size: 517 k
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing : php74-php-xml-7.4.23-1.el7.remi.x86_64 1/2
Erasing : php74-php-pecl-zip-1.19.3-2.el7.remi.x86_64 2/2
Verifying : php74-php-pecl-zip-1.19.3-2.el7.remi.x86_64 1/2
Verifying : php74-php-xml-7.4.23-1.el7.remi.x86_64 2/2
Removed:
php74-php-pecl-zip.x86_64 0:1.19.3-2.el7.remi php74-php-xml.x86_64 0:7.4.23-1.el7.remi
Complete!
[root@HIGDQEEMO63U9NR ~]#
[root@HIGDQEEMO63U9NR ~]# rpm -e --nodeps php74-php-pecl-mcrypt
[root@HIGDQEEMO63U9NR ~]#
[root@HIGDQEEMO63U9NR ~]# rpm -e --nodeps php74-php-mysqlnd php74-php-opcache
[root@HIGDQEEMO63U9NR ~]#
[root@HIGDQEEMO63U9NR ~]# yum remove php74-php-fpm php74-php-cli php74-php-bcmath php74-php-gd php74-php-json php74-php-mbstring
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package php74-php-bcmath.x86_64 0:7.4.23-1.el7.remi will be erased
---> Package php74-php-cli.x86_64 0:7.4.23-1.el7.remi will be erased
---> Package php74-php-fpm.x86_64 0:7.4.23-1.el7.remi will be erased
---> Package php74-php-gd.x86_64 0:7.4.23-1.el7.remi will be erased
---> Package php74-php-json.x86_64 0:7.4.23-1.el7.remi will be erased
--> Processing Dependency: php74-php-json(x86-64) = 7.4.23-1.el7.remi for package: php74-php-common-7.4.23-1.el7.remi.x86_64
---> Package php74-php-mbstring.x86_64 0:7.4.23-1.el7.remi will be erased
--> Running transaction check
---> Package php74-php-common.x86_64 0:7.4.23-1.el7.remi will be erased
--> Processing Dependency: php74-php-common(x86-64) = 7.4.23-1.el7.remi for package: php74-php-pdo-7.4.23-1.el7.remi.x86_64
--> Running transaction check
---> Package php74-php-pdo.x86_64 0:7.4.23-1.el7.remi will be erased
--> Finished Dependency Resolution
Dependencies Resolved
===============================================================================================
Package Arch Version Repository Size
===============================================================================================
Removing:
php74-php-bcmath x86_64 7.4.23-1.el7.remi @remi-safe 62 k
php74-php-cli x86_64 7.4.23-1.el7.remi @remi-safe 12 M
php74-php-fpm x86_64 7.4.23-1.el7.remi @remi-safe 6.2 M
php74-php-gd x86_64 7.4.23-1.el7.remi @remi-safe 110 k
php74-php-json x86_64 7.4.23-1.el7.remi @remi-safe 44 k
php74-php-mbstring x86_64 7.4.23-1.el7.remi @remi-safe 1.0 M
Removing for dependencies:
php74-php-common x86_64 7.4.23-1.el7.remi @remi-safe 6.7 M
php74-php-pdo x86_64 7.4.23-1.el7.remi @remi-safe 195 k
Transaction Summary
===============================================================================================
Remove 6 Packages (+2 Dependent packages)
Installed size: 27 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
Erasing : php74-php-fpm-7.4.23-1.el7.remi.x86_64 1/8
warning: /etc/opt/remi/php74/php-fpm.d/www.conf saved as /etc/opt/remi/php74/php-fpm.d/www.conf.rpmsave
Erasing : php74-php-gd-7.4.23-1.el7.remi.x86_64 2/8
Erasing : php74-php-pdo-7.4.23-1.el7.remi.x86_64 3/8
Erasing : php74-php-bcmath-7.4.23-1.el7.remi.x86_64 4/8
Erasing : php74-php-cli-7.4.23-1.el7.remi.x86_64 5/8
Erasing : php74-php-mbstring-7.4.23-1.el7.remi.x86_64 6/8
Erasing : php74-php-json-7.4.23-1.el7.remi.x86_64 7/8
Erasing : php74-php-common-7.4.23-1.el7.remi.x86_64 8/8
Verifying : php74-php-mbstring-7.4.23-1.el7.remi.x86_64 1/8
Verifying : php74-php-cli-7.4.23-1.el7.remi.x86_64 2/8
Verifying : php74-php-bcmath-7.4.23-1.el7.remi.x86_64 3/8
Verifying : php74-php-pdo-7.4.23-1.el7.remi.x86_64 4/8
Verifying : php74-php-json-7.4.23-1.el7.remi.x86_64 5/8
Verifying : php74-php-gd-7.4.23-1.el7.remi.x86_64 6/8
Verifying : php74-php-common-7.4.23-1.el7.remi.x86_64 7/8
Verifying : php74-php-fpm-7.4.23-1.el7.remi.x86_64 8/8
Removed:
php74-php-bcmath.x86_64 0:7.4.23-1.el7.remi php74-php-cli.x86_64 0:7.4.23-1.el7.remi
php74-php-fpm.x86_64 0:7.4.23-1.el7.remi php74-php-gd.x86_64 0:7.4.23-1.el7.remi
php74-php-json.x86_64 0:7.4.23-1.el7.remi php74-php-mbstring.x86_64 0:7.4.23-1.el7.remi
Dependency Removed:
php74-php-common.x86_64 0:7.4.23-1.el7.remi php74-php-pdo.x86_64 0:7.4.23-1.el7.remi
Complete!
[root@HIGDQEEMO63U9NR ~]#
[root@HIGDQEEMO63U9NR ~]# php -m
[PHP Modules]
bz2
calendar
Core
ctype
curl
date
exif
fileinfo
filter
ftp
gettext
hash
iconv
json
libxml
openssl
pcntl
pcre
PDO
pdo_sqlite
Phar
readline
Reflection
session
sockets
sodium
SPL
sqlite3
standard
tokenizer
zlib
[Zend Modules]
[root@HIGDQEEMO63U9NR ~]#
[root@HIGDQEEMO63U9NR ~]# yum remove php74-php-pdo
Loaded plugins: fastestmirror
No Match for argument: php74-php-pdo
No Packages marked for removal
[root@HIGDQEEMO63U9NR ~]#
[root@HIGDQEEMO63U9NR ~]# php -m
[PHP Modules]
bz2
calendar
Core
ctype
curl
date
exif
fileinfo
filter
ftp
gettext
hash
iconv
json
libxml
openssl
pcntl
pcre
PDO
pdo_sqlite
Phar
readline
Reflection
session
sockets
sodium
SPL
sqlite3
standard
tokenizer
zlib
[Zend Modules]
[root@HIGDQEEMO63U9NR ~]#
安装拓展
指定仓库名,重新安装 php74 拓展,因为已经指定了仓库,不需要带 php74 了:
yum --enablerepo=remi-php74 install -y php-fpm php-cli php-bcmath php-gd php-json php-mbstring php-mcrypt php-mysqlnd php-opcache php-pdo php-pecl-mcrypt php-xml php-zip
输出:
[root@HIGDQEEMO63U9NR ~]# yum --enablerepo=remi-php74 install -y php-fpm php-cli php-bcmath php-gd php-json php-mbstring php-mcrypt php-mysqlnd php-opcache php-pdo php-pecl-mcrypt php-xml php-zip
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* remi-php74: mirrors.tuna.tsinghua.edu.cn
* remi-safe: mirrors.tuna.tsinghua.edu.cn
* updates: mirrors.aliyun.com
Package php-cli-7.4.23-1.el7.remi.x86_64 already installed and latest version
Package php-json-7.4.23-1.el7.remi.x86_64 already installed and latest version
Package php-mcrypt is obsoleted by php-pecl-mcrypt, trying to install php-pecl-mcrypt-1.0.4-1.el7.remi.7.4.x86_64 instead
Package php-pdo-7.4.23-1.el7.remi.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package php-bcmath.x86_64 0:7.4.23-1.el7.remi will be installed
---> Package php-fpm.x86_64 0:7.4.23-1.el7.remi will be installed
---> Package php-gd.x86_64 0:7.4.23-1.el7.remi will be installed
---> Package php-mbstring.x86_64 0:7.4.23-1.el7.remi will be installed
---> Package php-mysqlnd.x86_64 0:7.4.23-1.el7.remi will be installed
---> Package php-opcache.x86_64 0:7.4.23-1.el7.remi will be installed
---> Package php-pecl-mcrypt.x86_64 0:1.0.4-1.el7.remi.7.4 will be installed
---> Package php-pecl-zip.x86_64 0:1.19.4-1.el7.remi.7.4 will be installed
---> Package php-xml.x86_64 0:7.4.23-1.el7.remi will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===============================================================================================
Package Arch Version Repository Size
===============================================================================================
Installing:
php-bcmath x86_64 7.4.23-1.el7.remi remi-php74 79 k
php-fpm x86_64 7.4.23-1.el7.remi remi-php74 1.8 M
php-gd x86_64 7.4.23-1.el7.remi remi-php74 88 k
php-mbstring x86_64 7.4.23-1.el7.remi remi-php74 522 k
php-mysqlnd x86_64 7.4.23-1.el7.remi remi-php74 254 k
php-opcache x86_64 7.4.23-1.el7.remi remi-php74 331 k
php-pecl-mcrypt x86_64 1.0.4-1.el7.remi.7.4 remi-php74 30 k
php-pecl-zip x86_64 1.19.4-1.el7.remi.7.4 remi-php74 62 k
php-xml x86_64 7.4.23-1.el7.remi remi-php74 208 k
Transaction Summary
===============================================================================================
Install 9 Packages
Total download size: 3.3 M
Installed size: 12 M
Downloading packages:
(1/9): php-bcmath-7.4.23-1.el7.remi.x86_64.rpm | 79 kB 00:00:00
(2/9): php-opcache-7.4.23-1.el7.remi.x86_64.rpm | 331 kB 00:00:00
(3/9): php-pecl-mcrypt-1.0.4-1.el7.remi.7.4.x86_64.rpm | 30 kB 00:00:00
(4/9): php-pecl-zip-1.19.4-1.el7.remi.7.4.x86_64.rpm | 62 kB 00:00:00
(5/9): php-xml-7.4.23-1.el7.remi.x86_64.rpm | 208 kB 00:00:00
(6/9): php-gd-7.4.23-1.el7.remi.x86_64.rpm | 88 kB 00:00:01
(7/9): php-mysqlnd-7.4.23-1.el7.remi.x86_64.rpm | 254 kB 00:00:03
(8/9): php-mbstring-7.4.23-1.el7.remi.x86_64.rpm | 522 kB 00:00:04
(9/9): php-fpm-7.4.23-1.el7.remi.x86_64.rpm | 1.8 MB 00:00:14
-----------------------------------------------------------------------------------------------
Total 227 kB/s | 3.3 MB 00:00:15
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : php-xml-7.4.23-1.el7.remi.x86_64 1/9
Installing : php-pecl-zip-1.19.4-1.el7.remi.7.4.x86_64 2/9
Installing : php-fpm-7.4.23-1.el7.remi.x86_64 3/9
Installing : php-bcmath-7.4.23-1.el7.remi.x86_64 4/9
Installing : php-opcache-7.4.23-1.el7.remi.x86_64 5/9
Installing : php-mbstring-7.4.23-1.el7.remi.x86_64 6/9
Installing : php-gd-7.4.23-1.el7.remi.x86_64 7/9
Installing : php-pecl-mcrypt-1.0.4-1.el7.remi.7.4.x86_64 8/9
Installing : php-mysqlnd-7.4.23-1.el7.remi.x86_64 9/9
Verifying : php-mysqlnd-7.4.23-1.el7.remi.x86_64 1/9
Verifying : php-pecl-mcrypt-1.0.4-1.el7.remi.7.4.x86_64 2/9
Verifying : php-gd-7.4.23-1.el7.remi.x86_64 3/9
Verifying : php-mbstring-7.4.23-1.el7.remi.x86_64 4/9
Verifying : php-opcache-7.4.23-1.el7.remi.x86_64 5/9
Verifying : php-bcmath-7.4.23-1.el7.remi.x86_64 6/9
Verifying : php-fpm-7.4.23-1.el7.remi.x86_64 7/9
Verifying : php-pecl-zip-1.19.4-1.el7.remi.7.4.x86_64 8/9
Verifying : php-xml-7.4.23-1.el7.remi.x86_64 9/9
Installed:
php-bcmath.x86_64 0:7.4.23-1.el7.remi php-fpm.x86_64 0:7.4.23-1.el7.remi
php-gd.x86_64 0:7.4.23-1.el7.remi php-mbstring.x86_64 0:7.4.23-1.el7.remi
php-mysqlnd.x86_64 0:7.4.23-1.el7.remi php-opcache.x86_64 0:7.4.23-1.el7.remi
php-pecl-mcrypt.x86_64 0:1.0.4-1.el7.remi.7.4 php-pecl-zip.x86_64 0:1.19.4-1.el7.remi.7.4
php-xml.x86_64 0:7.4.23-1.el7.remi
Complete!
[root@HIGDQEEMO63U9NR ~]#
查看拓展:
[root@HIGDQEEMO63U9NR ~]# php -m
[PHP Modules]
bcmath
bz2
calendar
Core
ctype
curl
date
dom
exif
fileinfo
filter
ftp
gd
gettext
hash
iconv
json
libxml
mbstring
mcrypt
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
readline
Reflection
session
SimpleXML
sockets
sodium
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
xsl
Zend OPcache
zip
zlib
[Zend Modules]
Zend OPcache
[root@HIGDQEEMO63U9NR ~]#
安装完成。
卸载 php7.4
yum remove php74-php*
参考资料
Win+Linux单系统解决方案——WSL(入门篇) https://www.jianshu.com/p/6b02948b3d37
适用于 Linux 的 Windows 子系统安装指南 (Windows 10) https://docs.microsoft.com/zh-cn/windows/wsl/install-win10
Windows Subsystem for Linux Installation Guide for Windows 10 https://docs.microsoft.com/en-us/windows/wsl/install-win10
Win10 升级使用 WSL2 https://zhuanlan.zhihu.com/p/202954384
在Windows 10上使用WSL安装Centos https://zhuanlan.zhihu.com/p/272735470
漫谈在Windows Server 2019中安装使用WSL https://zhuanlan.zhihu.com/p/271927065
适用于 Linux 的 Windows 子系统安装指南 (Windows 10) https://docs.microsoft.com/zh-cn/windows/wsl/install-win10
CentWSL Tags包 https://github.com/wsldl-pg/CentWSL/tags
Win10 WSL安装Centos7 Nginx+PHP+MySQL https://blog.csdn.net/hudeyong926/article/details/101030622
nginx: Linux packages http://nginx.org/en/linux_packages.html
centos yum-utils包详解 https://blog.csdn.net/xixihahalelehehe/article/details/105625710
如何安装和使用’yum-utils’来维护Yum并提高其性能 https://www.howtoing.com/linux-yum-package-management-with-yum-utils/
Yum-utils 剖析 https://blog.csdn.net/xiaoxiao_22/article/details/7044583
WSL2子系统安装CentOS8及源码编译安装Nginx1.18+PHP7.4+MySql8.0开发 https://blog.51cto.com/u_15057852/2567230
阿里云源 https://developer.aliyun.com/mirror/
centos7 php remi,Centos7 安装 PHP7.3 https://blog.csdn.net/weixin_33223705/article/details/116263735?utm_term=centos7%E5%AE%89%E8%A3%85remi
Centos7(Liunx)安装PHP7.4版本 https://www.cnblogs.com/mefj/p/14089314.html
WSL2子系统安装CentOS8及源码编译安装Nginx1.18+PHP7.4+MySql8.0 https://weibo.com/ttarticle/p/show?id=2309404538633183952933
CentOS7 yum安装php7.3 7.4 https://zerlong.com/880.html