在新的ECS centos7.6上安装PHP环境

双十一,在阿里云上又买了一台ECS,Centos7.6

首先ssh登陆centos.

yum update

yum install git

yum install nginx

本次准备安装PHP7.1的最新版7.1.33, 安装方式采用rpm。

https://centos.pkgs.org/7/ius-x86_64/php71u-fpm-nginx-7.1.28-1.ius.centos7.noarch.rpm.html

在上面的地址下载rpm包

cd /var

mkdir download

cd download

wget https://centos7.iuscommunity.org/ius-release.rpm

等下载

--2019-11-12 12:04:31--  https://centos7.iuscommunity.org/ius-release.rpm
正在解析主机 centos7.iuscommunity.org (centos7.iuscommunity.org)... 104.130.246.49, 2001:4800:7819:103:be76:4eff:fe04:89a8
正在连接 centos7.iuscommunity.org (centos7.iuscommunity.org)|104.130.246.49|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 301 Moved Permanently
位置:https://repo.ius.io/ius-release-el7.rpm [跟随至新的 URL]
--2019-11-12 12:04:33--  https://repo.ius.io/ius-release-el7.rpm
正在解析主机 repo.ius.io (repo.ius.io)... 104.127.192.181, 2600:1417:b000:484::3898, 2600:1417:b000:4bf::3898
正在连接 repo.ius.io (repo.ius.io)|104.127.192.181|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:8412 (8.2K) [application/octet-stream]
正在保存至: “ius-release.rpm”

100%[=================================================================>] 8,412       --.-K/s 用时 0s      

2019-11-12 12:04:34 (214 MB/s) - 已保存 “ius-release.rpm” [8412/8412])

安装ius-release rpm:

rpm -Uvh ius-release.rpm 
警告:ius-release.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 4b274df2: NOKEY
错误:依赖检测失败:
    epel-release = 7 被 ius-release-2-1.el7.ius.noarch 需要
[root@iZwz9g3h4a24fonhsk25zyZ download]# yum install epel-release
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 epel-release.noarch.0.7-12 将被 安装
--> 解决依赖关系完成

依赖关系解决

===========================================================================================================
 Package                       架构                    版本                    源                     大小
===========================================================================================================
正在安装:
 epel-release                  noarch                  7-12                    epel                   15 k

事务概要
===========================================================================================================
安装  1 软件包

总下载量:15 k
安装大小:24 k
Is this ok [y/d/N]: y
Downloading packages:
epel-release-7-12.noarch.rpm                                                        |  15 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : epel-release-7-12.noarch                                                               1/1 
警告:/etc/yum.repos.d/epel.repo 已建立为 /etc/yum.repos.d/epel.repo.rpmnew 
  验证中      : epel-release-7-12.noarch                                                               1/1 

已安装:
  epel-release.noarch 0:7-12                                                                               

完毕!

通过yum安装php

yum install php71u-fpm-nginx

等待安装完成, 启动试一下

systemctl start php-fpm

或者看一下php-fpm版本

php-fpm -v
PHP 7.1.33 (fpm-fcgi) (built: Oct 25 2019 01:57:13)
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies

启动nginx

nginx

去nginx默认根目录创建一个phpinfo.php

cd /usr/share/nginx/html

vi phpinfo.php

phpinfo.php

<?php

phpinfo();

保存到,在流览器中输入服务器公网IP访问。可能访问不到。需要登陆阿里云后台,进入ECS管理后台,安全组设置,添加规则,设置允许HTTP:80端口访问。设置完后,再刷新浏器。

看到输出的PHP安装信息。

但是此时PHP还缺少很我常用的扩展,比如redis,memcached,gd,mysql等等

安装gd扩展

yum install php71u-gd php71u-json php71u-mbstring php71u-mcrypt php71u-mysqlnd php71u-pdo php71u-xml

yum install php71u-pecl-igbinary php71u-pecl-igbinary-devel php71u-pecl-geoip php71u-pecl-imagick php71u-pecl-memcached php71u-pecl-redis php71u-pecl-yaml php71u-pecl-mongodb 

systemctl restart php-fpm

刷新phpinfo页面,成功显示gd扩展。

大部分扩展可以在下面这个网址上搜到,直接使用yum安装。

https://pkgs.org/download/php71u