## 安装PHP
安装PHP我们使用的Yum源是webtatic.com`https://webtatic.com/`
webtatic以前是可以直接访问的,现在不知道为什么被墙了,所以,要使用 webtatic需要科学上网。
确保你的CentOS已经能够科学上网,然后打开`https://webtatic.com`,
:-: ![](https://box.kancloud.cn/5802209c169521cc4ba57abda4680c31_724x609.jpg)
webtatic.com的首页列出了各个PHP版本的更新,我们选择最新的版本PHP7.2.8这一组,点击`Yum repository`:
:-: ![](https://box.kancloud.cn/4e07049889b8267903fabdf0534bff1b_719x258.jpg)
找到CentOS/RHEL 7.x这一组,执行:
~~~
[root@localhost ~]# yum install epel-release
[root@localhost ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
[root@localhost ~]# yum makecache fast
~~~
这样,webtatic提供的yum源就导入了,然后我们执行:
~~~
[root@localhost ~]# yum search php72
~~~
搜索结果如下:
~~~
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.huaweicloud.com
* epel: mirrors.tongji.edu.cn
* extras: mirrors.huaweicloud.com
* updates: centos.ustc.edu.cn
* webtatic: uk.repo.webtatic.com
=========================================== N/S matched: php72 ============================================
mod_php72w.x86_64 : PHP module for the Apache HTTP Server
php72w-bcmath.x86_64 : A module for PHP applications for using the bcmath library
php72w-cli.x86_64 : Command-line interface for PHP
php72w-common.x86_64 : Common files for PHP
php72w-dba.x86_64 : A database abstraction layer module for PHP applications
php72w-devel.x86_64 : Files needed for building PHP extensions
php72w-embedded.x86_64 : PHP library for embedding in applications
php72w-enchant.x86_64 : Enchant spelling extension for PHP applications
php72w-fpm.x86_64 : PHP FastCGI Process Manager
php72w-gd.x86_64 : A module for PHP applications for using the gd graphics library
php72w-imap.x86_64 : A module for PHP applications that use IMAP
php72w-interbase.x86_64 : A module for PHP applications that use Interbase/Firebird databases
php72w-intl.x86_64 : Internationalization extension for PHP applications
php72w-ldap.x86_64 : A module for PHP applications that use LDAP
php72w-mbstring.x86_64 : A module for PHP applications which need multi-byte string handling
php72w-mysql.x86_64 : A module for PHP applications that use MySQL databases
php72w-mysqlnd.x86_64 : A module for PHP applications that use MySQL databases
php72w-odbc.x86_64 : A module for PHP applications that use ODBC databases
php72w-opcache.x86_64 : An opcode cache Zend extension
php72w-pdo.x86_64 : A database access abstraction module for PHP applications
php72w-pdo_dblib.x86_64 : MSSQL database module for PHP
php72w-pear.noarch : PHP Extension and Application Repository framework
php72w-pecl-apcu.x86_64 : APCu - APC User Cache
php72w-pecl-apcu-devel.x86_64 : APCu developer files (header)
php72w-pecl-geoip.x86_64 : Extension to map IP addresses to geographic places
php72w-pecl-igbinary.x86_64 : Replacement for the standard PHP serializer
php72w-pecl-igbinary-devel.x86_64 : Igbinary developer files (header)
php72w-pecl-imagick.x86_64 : Provides a wrapper to the ImageMagick library
php72w-pecl-imagick-devel.x86_64 : Imagick developer files (header)
php72w-pecl-libsodium.x86_64 : Wrapper for the Sodium cryptographic library
php72w-pecl-memcached.x86_64 : Extension to work with the Memcached caching daemon
php72w-pecl-mongodb.x86_64 : PECL package MongoDB driver
php72w-pecl-redis.x86_64 : Extension for communicating with the Redis key-value store
php72w-pecl-xdebug.x86_64 : PECL package for debugging PHP scripts
php72w-pgsql.x86_64 : A PostgreSQL database module for PHP
php72w-phpdbg.x86_64 : Interactive PHP debugger
php72w-process.x86_64 : Modules for PHP script using system process interfaces
php72w-pspell.x86_64 : A module for PHP applications for using pspell interfaces
php72w-recode.x86_64 : A module for PHP applications for using the recode library
php72w-snmp.x86_64 : A module for PHP applications that query SNMP-managed devices
php72w-soap.x86_64 : A module for PHP applications that use the SOAP protocol
php72w-sodium.x86_64 : Wrapper for the Sodium cryptographic library
php72w-tidy.x86_64 : Standard PHP module provides tidy library support
php72w-xml.x86_64 : A module for PHP applications which use XML
php72w-xmlrpc.x86_64 : A module for PHP applications which use the XML-RPC protocol
Name and summary matches only, use "search all" for everything.
~~~
现在可以通过yum 安装php72w了
~~~
[root@localhost ~]# yum install php72w mod_php72w php72w-cli php72w-common php72w-common php72w-dba php72w-devel php72w-embedded php72w-enchant php72w-fpm php72w-gd php72w-imap php72w-interbase php72w-intl php72w-ldap php72w-mbstring php72w-mysqlnd php72w-odbc php72w-opcache php72w-pdo php72w-pdo_dblib php72w-pear php72w-pecl-apcu php72w-pecl-apcu-devel php72w-pecl-geoip php72w-pecl-igbinary php72w-pecl-igbinary-devel php72w-pecl-imagick php72w-pecl-imagick-devel php72w-pecl-libsodium php72w-pecl-memcached php72w-pecl-mongodb php72w-pecl-redis php72w-pecl-xdebug php72w-pgsql php72w-phpdbg php72w-process php72w-pspell php72w-recode php72w-snmp php72w-soap php72w-sodium php72w-tidy php72w-xml php72w-xmlrpc -y
~~~
根据自己的需要选择扩展。现在不安装以后也可以安装的。很快就安装完了。
查看下php的版本:
~~~
[root@localhost ~]# php -v
~~~
显示:
~~~
PHP 7.2.8 (cli) (built: Jul 20 2018 15:20:01) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.8, Copyright (c) 1999-2018, by Zend Technologies
with Xdebug v2.6.0, Copyright (c) 2002-2018, by Derick Rethans
~~~
版本正确
看看php-fpm服务起来了没
~~~
[root@localhost ~]# systemctl status php-fpm.service
~~~
~~~
● php-fpm.service - The PHP FastCGI Process Manager
Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; disabled; vendor preset: disabled)
Active: inactive (dead)
~~~
好吧,没起来,我们启动php-fpm服务:
~~~
[root@localhost ~]# systemctl enable php-fpm.service
[root@localhost ~]# systemctl start php-fpm.service
[root@localhost ~]# systemctl status php-fpm.service
~~~
输出:
~~~
● php-fpm.service - The PHP FastCGI Process Manager
Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2018-08-15 11:24:55 CST; 8s ago
Main PID: 1964 (php-fpm)
Status: "Ready to handle connections"
CGroup: /system.slice/php-fpm.service
├─1964 php-fpm: master process (/etc/php-fpm.conf)
├─1966 php-fpm: pool www
├─1967 php-fpm: pool www
├─1968 php-fpm: pool www
├─1969 php-fpm: pool www
└─1970 php-fpm: pool www
Aug 15 11:24:55 localhost.localdomain systemd[1]: Starting The PHP FastCGI Process Manager...
Aug 15 11:24:55 localhost.localdomain systemd[1]: Started The PHP FastCGI Process Manager.
~~~
php-fpm服务成功启动了,绿灯贼亮。
PHP安装好了,关机拍个快照吧。