您现在的位置是:首页 > 技术教程 正文

CentOS7下yum安装php7

admin 阅读: 2024-03-17
后台-插件-广告管理-内容页头部广告(手机)

1.安装epel-release

EPEL(Extra Packages for Enterprise Linux)存储库提供了标准 Red Hat 和 CentOS 存储库中未包含的其他软件包。EPEL 存储库的创建是因为 Fedora 贡献者希望使用他们在 Red Hat Enterprise Linux(RHEL)及其衍生产品(如CentOS,Oracle Linux和Scientific Linux)上维护的软件包。
启用此存储库后,您可以访问流行的软件包,包括 Nginx等。

命令:

wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

rpm -ivh epel-release-latest-7.noarch.rpm 

  1. [root@centos79-3 ~]# wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
  2. --2023-08-31 15:37:33-- https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
  3. Resolving dl.fedoraproject.org (dl.fedoraproject.org)... 38.145.60.22, 38.145.60.24, 38.145.60.23
  4. Connecting to dl.fedoraproject.org (dl.fedoraproject.org)|38.145.60.22|:443... connected.
  5. HTTP request sent, awaiting response... 200 OK
  6. Length: 15608 (15K) [application/x-rpm]
  7. Saving to: ‘epel-release-latest-7.noarch.rpm’
  8. 100%[================================================================>] 15,608 48.1KB/s in 0.3s
  9. 2023-08-31 15:37:35 (48.1 KB/s) - ‘epel-release-latest-7.noarch.rpm’ saved [15608/15608]
  10. [root@centos79-3 ~]# ls
  11. anaconda-ks.cfg basic_init.sh epel-release-latest-7.noarch.rpm
  12. [root@centos79-3 ~]# rpm -ivh epel-release-latest-7.noarch.rpm
  13. Preparing... ################################# [100%]
  14. package epel-release-7-14.noarch is already installed
  15. [root@centos79-3 ~]# cd /etc/yum.repos.d/
  16. [root@centos79-3 yum.repos.d]# ls
  17. bak epel.repo nginx.repo webtatic.repo
  18. CentOS7.repo epel-testing.repo webtatic-archive.repo webtatic-testing.repo
  19. [root@centos79-3 yum.repos.d]#

通过yum repolist验证epel存储库是否启用,该命令将显示已启用的存储库的 repo ID,名称和程序包数量。输出的信息中如包含 EPEL存储库这一行,说明EPEL库已启用。

命令:

yum repolist

  1. [root@centos79-3 yum.repos.d]# yum repolist
  2. Loaded plugins: fastestmirror
  3. Loading mirror speeds from cached hostfile
  4. * epel: mirrors.bfsu.edu.cn
  5. repo id repo name status
  6. CentOS7 "localserver" 4,070
  7. *epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 13,770
  8. nginx-stable/7/x86_64 nginx stable repo 318
  9. webtatic/x86_64 Webtatic Repository EL7 - x86_64 789
  10. repolist: 18,947
  11. [root@centos79-3 yum.repos.d]#

2.安装php7的rpm源

对于服务器而言,php7的rpm源最为常见的即是提供 web 服务,而对于 web 服务中常用的一些软件,在系统默认的源下,一般版本较低,如若需要使用相对较新的版本(如 PHP),webtatic 源是一个很好的选择。

命令:

wget https://mirror.webtatic.com/yum/el7/webtatic-release.rpm --no-check-certificate

rpm -ivh webtatic-release.rpm

yum list |grep php7

  1. [root@centos79-3 ~]# wget https://mirror.webtatic.com/yum/el7/webtatic-release.rpm --no-check-certificate
  2. --2023-08-31 15:50:44-- https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
  3. Resolving mirror.webtatic.com (mirror.webtatic.com)... 104.21.71.8, 172.67.141.68, 2606:4700:3037::6815:4708, ...
  4. Connecting to mirror.webtatic.com (mirror.webtatic.com)|104.21.71.8|:443... connected.
  5. WARNING: cannot verify mirror.webtatic.com's certificate, issued by ‘/C=US/O=Let's Encrypt/CN=E1’:
  6. Issued certificate has expired.
  7. HTTP request sent, awaiting response... 200 OK
  8. Length: 13152 (13K) [application/x-rpm]
  9. Saving to: ‘webtatic-release.rpm’
  10. 100%[================================================================>] 13,152 40.2KB/s in 0.3s
  11. 2023-08-31 15:50:48 (40.2 KB/s) - ‘webtatic-release.rpm’ saved [13152/13152]
  12. [root@centos79-3 ~]# ls
  13. anaconda-ks.cfg basic_init.sh epel-release-latest-7.noarch.rpm webtatic-release.rpm
  14. [root@centos79-3 ~]# rpm -ivh webtatic-release.rpm
  15. Preparing... ################################# [100%]
  16. package webtatic-release-7-3.noarch is already installed
  17. [root@centos79-3 yum.repos.d]# yum list |grep php7
  18. mod_php71w.x86_64 7.1.33-1.w7 webtatic
  19. mod_php72w.x86_64 7.2.34-1.w7 webtatic
  20. php70w.x86_64 7.0.33-1.w7 webtatic
  21. php70w-bcmath.x86_64 7.0.33-1.w7 webtatic
  22. php70w-cli.x86_64 7.0.33-1.w7 webtatic
  23. php70w-common.x86_64 7.0.33-1.w7 webtatic
  24. php70w-dba.x86_64 7.0.33-1.w7 webtatic
  25. php70w-devel.x86_64 7.0.33-1.w7 webtatic
  26. php70w-embedded.x86_64 7.0.33-1.w7 webtatic
  27. php70w-enchant.x86_64 7.0.33-1.w7 webtatic
  28. php70w-fpm.x86_64 7.0.33-1.w7 webtatic
  29. php70w-gd.x86_64 7.0.33-1.w7 webtatic
  30. php70w-imap.x86_64 7.0.33-1.w7 webtatic
  31. php70w-interbase.x86_64 7.0.33-1.w7 webtatic
  32. php70w-intl.x86_64 7.0.33-1.w7 webtatic
  33. php70w-ldap.x86_64 7.0.33-1.w7 webtatic
  34. php70w-mbstring.x86_64 7.0.33-1.w7 webtatic
  35. php70w-mcrypt.x86_64 7.0.33-1.w7 webtatic
  36. php70w-mysql.x86_64 7.0.33-1.w7 webtatic
  37. php70w-mysqlnd.x86_64 7.0.33-1.w7 webtatic
  38. php70w-odbc.x86_64 7.0.33-1.w7 webtatic
  39. php70w-opcache.x86_64 7.0.33-1.w7 webtatic
  40. php70w-pdo.x86_64 7.0.33-1.w7 webtatic
  41. php70w-pdo_dblib.x86_64 7.0.33-1.w7 webtatic
  42. php70w-pear.noarch 1:1.10.4-1.w7 webtatic
  43. php70w-pecl-apcu.x86_64 5.1.9-1.w7 webtatic
  44. php70w-pecl-apcu-devel.x86_64 5.1.9-1.w7 webtatic
  45. php70w-pecl-geoip.x86_64 1.1.1-1.w7 webtatic
  46. php70w-pecl-igbinary.x86_64 2.0.5-1.w7 webtatic
  47. php70w-pecl-igbinary-devel.x86_64 2.0.5-1.w7 webtatic
  48. php70w-pecl-imagick.x86_64 3.4.3-1.w7 webtatic
  49. php70w-pecl-imagick-devel.x86_64 3.4.3-1.w7 webtatic
  50. php70w-pecl-memcached.x86_64 3.0.4-1.w7 webtatic
  51. php70w-pecl-mongodb.x86_64 1.5.3-1.w7 webtatic
  52. php70w-pecl-redis.x86_64 3.1.6-1.w7 webtatic
  53. php70w-pecl-xdebug.x86_64 2.6.1-1.w7 webtatic
  54. php70w-pgsql.x86_64 7.0.33-1.w7 webtatic
  55. php70w-phpdbg.x86_64 7.0.33-1.w7 webtatic
  56. php70w-process.x86_64 7.0.33-1.w7 webtatic
  57. php70w-pspell.x86_64 7.0.33-1.w7 webtatic
  58. php70w-recode.x86_64 7.0.33-1.w7 webtatic
  59. php70w-snmp.x86_64 7.0.33-1.w7 webtatic
  60. php70w-soap.x86_64 7.0.33-1.w7 webtatic
  61. php70w-tidy.x86_64 7.0.33-1.w7 webtatic
  62. php70w-xml.x86_64 7.0.33-1.w7 webtatic
  63. php70w-xmlrpc.x86_64 7.0.33-1.w7 webtatic
  64. php71w-bcmath.x86_64 7.1.33-1.w7 webtatic
  65. php71w-cli.x86_64 7.1.33-1.w7 webtatic
  66. php71w-common.x86_64 7.1.33-1.w7 webtatic
  67. php71w-dba.x86_64 7.1.33-1.w7 webtatic
  68. php71w-devel.x86_64 7.1.33-1.w7 webtatic
  69. php71w-embedded.x86_64 7.1.33-1.w7 webtatic
  70. php71w-enchant.x86_64 7.1.33-1.w7 webtatic
  71. php71w-fpm.x86_64 7.1.33-1.w7 webtatic
  72. php71w-gd.x86_64 7.1.33-1.w7 webtatic
  73. php71w-imap.x86_64 7.1.33-1.w7 webtatic
  74. php71w-interbase.x86_64 7.1.33-1.w7 webtatic
  75. php71w-intl.x86_64 7.1.33-1.w7 webtatic
  76. php71w-ldap.x86_64 7.1.33-1.w7 webtatic
  77. php71w-mbstring.x86_64 7.1.33-1.w7 webtatic
  78. php71w-mcrypt.x86_64 7.1.33-1.w7 webtatic
  79. php71w-mysql.x86_64 7.1.33-1.w7 webtatic
  80. php71w-mysqlnd.x86_64 7.1.33-1.w7 webtatic
  81. php71w-odbc.x86_64 7.1.33-1.w7 webtatic
  82. php71w-opcache.x86_64 7.1.33-1.w7 webtatic
  83. php71w-pdo.x86_64 7.1.33-1.w7 webtatic
  84. php71w-pdo_dblib.x86_64 7.1.33-1.w7 webtatic
  85. php71w-pear.noarch 1:1.10.4-1.w7 webtatic
  86. php71w-pecl-apcu.x86_64 5.1.9-1.w7 webtatic
  87. php71w-pecl-apcu-devel.x86_64 5.1.9-1.w7 webtatic
  88. php71w-pecl-geoip.x86_64 1.1.1-1.w7 webtatic
  89. php71w-pecl-igbinary.x86_64 2.0.5-1.w7 webtatic
  90. php71w-pecl-igbinary-devel.x86_64 2.0.5-1.w7 webtatic
  91. php71w-pecl-imagick.x86_64 3.4.3-1.w7 webtatic
  92. php71w-pecl-imagick-devel.x86_64 3.4.3-1.w7 webtatic
  93. php71w-pecl-memcached.x86_64 3.0.4-1.w7 webtatic
  94. php71w-pecl-mongodb.x86_64 1.5.3-1.w7 webtatic
  95. php71w-pecl-redis.x86_64 3.1.6-1.w7 webtatic
  96. php71w-pecl-xdebug.x86_64 2.6.1-1.w7 webtatic
  97. php71w-pgsql.x86_64 7.1.33-1.w7 webtatic
  98. php71w-phpdbg.x86_64 7.1.33-1.w7 webtatic
  99. php71w-process.x86_64 7.1.33-1.w7 webtatic
  100. php71w-pspell.x86_64 7.1.33-1.w7 webtatic
  101. php71w-recode.x86_64 7.1.33-1.w7 webtatic
  102. php71w-snmp.x86_64 7.1.33-1.w7 webtatic
  103. php71w-soap.x86_64 7.1.33-1.w7 webtatic
  104. php71w-tidy.x86_64 7.1.33-1.w7 webtatic
  105. php71w-xml.x86_64 7.1.33-1.w7 webtatic
  106. php71w-xmlrpc.x86_64 7.1.33-1.w7 webtatic
  107. php72w-bcmath.x86_64 7.2.34-1.w7 webtatic
  108. php72w-cli.x86_64 7.2.34-1.w7 webtatic
  109. php72w-common.x86_64 7.2.34-1.w7 webtatic
  110. php72w-dba.x86_64 7.2.34-1.w7 webtatic
  111. php72w-devel.x86_64 7.2.34-1.w7 webtatic
  112. php72w-embedded.x86_64 7.2.34-1.w7 webtatic
  113. php72w-enchant.x86_64 7.2.34-1.w7 webtatic
  114. php72w-fpm.x86_64 7.2.34-1.w7 webtatic
  115. php72w-gd.x86_64 7.2.34-1.w7 webtatic
  116. php72w-imap.x86_64 7.2.34-1.w7 webtatic
  117. php72w-interbase.x86_64 7.2.34-1.w7 webtatic
  118. php72w-intl.x86_64 7.2.34-1.w7 webtatic
  119. php72w-ldap.x86_64 7.2.34-1.w7 webtatic
  120. php72w-mbstring.x86_64 7.2.34-1.w7 webtatic
  121. php72w-mysql.x86_64 7.2.34-1.w7 webtatic
  122. php72w-mysqlnd.x86_64 7.2.34-1.w7 webtatic
  123. php72w-odbc.x86_64 7.2.34-1.w7 webtatic
  124. php72w-opcache.x86_64 7.2.34-1.w7 webtatic
  125. php72w-pdo.x86_64 7.2.34-1.w7 webtatic
  126. php72w-pdo_dblib.x86_64 7.2.34-1.w7 webtatic
  127. php72w-pear.noarch 1:1.10.12-1.w7 webtatic
  128. php72w-pecl-apcu.x86_64 5.1.18-1.w7 webtatic
  129. php72w-pecl-apcu-devel.x86_64 5.1.18-1.w7 webtatic
  130. php72w-pecl-geoip.x86_64 1.1.1-1.2.w7 webtatic
  131. php72w-pecl-igbinary.x86_64 3.1.2-1.w7 webtatic
  132. php72w-pecl-igbinary-devel.x86_64 3.1.2-1.w7 webtatic
  133. php72w-pecl-imagick.x86_64 3.4.4-1.2.w7 webtatic
  134. php72w-pecl-imagick-devel.x86_64 3.4.4-1.2.w7 webtatic
  135. php72w-pecl-libsodium.x86_64 1.0.6-1.2.w7 webtatic
  136. php72w-pecl-memcached.x86_64 3.1.5-1.w7 webtatic
  137. php72w-pecl-mongodb.x86_64 1.7.4-1.w7 webtatic
  138. php72w-pecl-redis.x86_64 3.1.6-1.w7 webtatic
  139. php72w-pecl-xdebug.x86_64 2.9.6-1.w7 webtatic
  140. php72w-pgsql.x86_64 7.2.34-1.w7 webtatic
  141. php72w-phpdbg.x86_64 7.2.34-1.w7 webtatic
  142. php72w-process.x86_64 7.2.34-1.w7 webtatic
  143. php72w-pspell.x86_64 7.2.34-1.w7 webtatic
  144. php72w-recode.x86_64 7.2.34-1.w7 webtatic
  145. php72w-snmp.x86_64 7.2.34-1.w7 webtatic
  146. php72w-soap.x86_64 7.2.34-1.w7 webtatic
  147. php72w-sodium.x86_64 7.2.34-1.w7 webtatic
  148. php72w-tidy.x86_64 7.2.34-1.w7 webtatic
  149. php72w-xml.x86_64 7.2.34-1.w7 webtatic
  150. php72w-xmlrpc.x86_64 7.2.34-1.w7 webtatic
  151. [root@centos79-3 yum.repos.d]#

3.安装php7

命令:

yum install -y php72w php72w-cli  php72w-common  php72w-devel php72w-mysql php72w-fpm

rpm -qa | grep php72

  1. [root@centos79-3 yum.repos.d]# yum install -y php72w php72w-cli  php72w-common  php72w-devel php72w-mysql php72w-fpm php72w-devel
  2. Loaded plugins: fastestmirror
  3. Loading mirror speeds from cached hostfile
  4. * epel: mirrors.bfsu.edu.cn
  5. Resolving Dependencies
  6. --> Running transaction check
  7. ---> Package php72w-fpm.x86_64 0:7.2.34-1.w7 will be installed
  8. --> Processing Dependency: php72w-common(x86-64) = 7.2.34-1.w7 for package: php72w-fpm-7.2.34-1.w7.x86_64
  9. ---> Package php72w-mysql.x86_64 0:7.2.34-1.w7 will be installed
  10. --> Processing Dependency: php72w-pdo(x86-64) for package: php72w-mysql-7.2.34-1.w7.x86_64
  11. --> Running transaction check
  12. ---> Package php72w-common.x86_64 0:7.2.34-1.w7 will be installed
  13. ---> Package php72w-pdo.x86_64 0:7.2.34-1.w7 will be installed
  14. --> Finished Dependency Resolution
  15. Dependencies Resolved
  16. =============================================================================================================================================================
  17. Package Arch Version Repository Size
  18. =============================================================================================================================================================
  19. Installing:
  20. php72w-fpm x86_64 7.2.34-1.w7 webtatic 1.6 M
  21. php72w-mysql x86_64 7.2.34-1.w7 webtatic 83 k
  22. Installing for dependencies:
  23. php72w-common x86_64 7.2.34-1.w7 webtatic 1.3 M
  24. php72w-pdo x86_64 7.2.34-1.w7 webtatic 90 k
  25. Transaction Summary
  26. =============================================================================================================================================================
  27. Install 2 Packages (+2 Dependent packages)
  28. Total download size: 3.0 M
  29. Installed size: 18 M
  30. Downloading packages:
  31. (1/4): php72w-common-7.2.34-1.w7.x86_64.rpm | 1.3 MB 00:00:04
  32. (2/4): php72w-mysql-7.2.34-1.w7.x86_64.rpm | 83 kB 00:00:00
  33. (3/4): php72w-pdo-7.2.34-1.w7.x86_64.rpm | 90 kB 00:00:00
  34. (4/4): php72w-fpm-7.2.34-1.w7.x86_64.rpm | 1.6 MB 00:00:04
  35. -------------------------------------------------------------------------------------------------------------------------------------------------------------
  36. Total 624 kB/s | 3.0 MB 00:00:04
  37. Running transaction check
  38. Running transaction test
  39. Transaction test succeeded
  40. Running transaction
  41. Installing : php72w-common-7.2.34-1.w7.x86_64 1/4
  42. Installing : php72w-pdo-7.2.34-1.w7.x86_64 2/4
  43. Installing : php72w-mysql-7.2.34-1.w7.x86_64 3/4
  44. Installing : php72w-fpm-7.2.34-1.w7.x86_64 4/4
  45. Verifying : php72w-mysql-7.2.34-1.w7.x86_64 1/4
  46. Verifying : php72w-fpm-7.2.34-1.w7.x86_64 2/4
  47. Verifying : php72w-pdo-7.2.34-1.w7.x86_64 3/4
  48. Verifying : php72w-common-7.2.34-1.w7.x86_64 4/4
  49. Installed:
  50. php72w-fpm.x86_64 0:7.2.34-1.w7 php72w-mysql.x86_64 0:7.2.34-1.w7
  51. Dependency Installed:
  52. php72w-common.x86_64 0:7.2.34-1.w7 php72w-pdo.x86_64 0:7.2.34-1.w7
  53. Complete!
  54. [root@centos79-3 yum.repos.d]# rpm -qa | grep php72w
  55. php72w-fpm-7.2.34-1.w7.x86_64
  56. php72w-common-7.2.34-1.w7.x86_64
  57. php72w-mysql-7.2.34-1.w7.x86_64
  58. php72w-cli-7.2.34-1.w7.x86_64
  59. php72w-pdo-7.2.34-1.w7.x86_64
  60. php72w-devel-7.2.34-1.w7.x86_64
  61. [root@centos79-3 yum.repos.d]#

4.查看php版本

命令:

php -v

  1. [root@centos79-3 yum.repos.d]# php -v
  2. PHP 7.2.34 (cli) (built: Oct 1 2020 13:37:37) ( NTS )
  3. Copyright (c) 1997-2018 The PHP Group
  4. Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
  5. [root@centos79-3 yum.repos.d]#

另外:

php-fpm启动

命令:

systemctl enable php-fpm

systemctl start php-fpm

systemctl status php-fpm

  1. [root@centos79-3 yum.repos.d]# systemctl enable php-fpm
  2. Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.
  3. [root@centos79-3 yum.repos.d]#
  4. [root@centos79-3 yum.repos.d]# systemctl start php-fpm
  5. [root@centos79-3 yum.repos.d]#
  6. [root@centos79-3 yum.repos.d]# systemctl status php-fpm
  7. ● php-fpm.service - The PHP FastCGI Process Manager
  8. Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vendor preset: disabled)
  9. Active: active (running) since Thu 2023-08-31 16:02:13 CST; 1s ago
  10. Main PID: 20949 (php-fpm)
  11. Status: "Ready to handle connections"
  12. CGroup: /system.slice/php-fpm.service
  13. ├─20949 php-fpm: master process (/etc/php-fpm.conf)
  14. ├─20951 php-fpm: pool www
  15. ├─20952 php-fpm: pool www
  16. ├─20953 php-fpm: pool www
  17. ├─20954 php-fpm: pool www
  18. └─20955 php-fpm: pool www
  19. Aug 31 16:02:13 centos79-3 systemd[1]: Starting The PHP FastCGI Process Manager...
  20. Aug 31 16:02:13 centos79-3 systemd[1]: Started The PHP FastCGI Process Manager.
  21. [root@centos79-3 yum.repos.d]#

标签:
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

在线投稿:投稿 站长QQ:1888636

后台-插件-广告管理-内容页尾部广告(手机)
关注我们

扫一扫关注我们,了解最新精彩内容

搜索
排行榜