如何在运行 Amazon Linux Distro 的 EC2 t2.micro 实例上安装 PHP 7 [英] How to install PHP 7 on EC2 t2.micro Instance running Amazon Linux Distro

查看:14
本文介绍了如何在运行 Amazon Linux Distro 的 EC2 t2.micro 实例上安装 PHP 7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 AWS EC2 T2.Micro 实例上安装最新的 PHP 7.0.到目前为止,我已经读到当前 AWS 不支持 PHP 7.但是嘿.. 这只是云中的一个虚拟服务器,我可以完全控制它的配置,所以必须有某种方法让 PHP 7 在这个上运行一个.

非常感谢任何帮助.

我的盒子如下

$ cat/etc/*-release-------------------------------NAME="亚马逊 Linux AMI"版本="2015.09"ID="amzn"ID_LIKE="rhel fedora"VERSION_ID="2015.09"PRETTY_NAME="亚马逊 Linux AMI 2015.09"ANSI_COLOR="0;33"CPE_NAME="[*不重要*]"HOME_URL="http://aws.amazon.com/amazon-linux-ami/"亚马逊 Linux AMI 发布 2015.09$ uname -a-------------------------------Linux ip-xxx-xxx-xxx-xxx 4.1.13-18.26.amzn1.x86_64 #1 [日期] x86_64 x86_64 x86_64 GNU/Linux$ uname -mrs-------------------------------Linux 4.1.13-18.26.amzn1.x86_64 x86_64$猫/过程/版本-------------------------------Linux 版本 4.1.13-18.26.amzn1.x86_64 (mockbuild@gobi-build-64010) (gcc 版本 4.8.3 20140911 (Red Hat 4.8.3-9) (GCC) )

解决方案

您现在可以使用官方的 php7 包了.这是一个易于遵循的指南.

1.在 Amazon Linux AMI 上安装 Apache 2.4 和 PHP 7.0

# 删除当前的apache &phpsudo yum 删除 httpd* php*# 安装 Apache 2.4须藤 yum 安装 httpd24# 安装 PHP 7.0# 自动包含 php70-cli php70-common php70-json php70-process php70-xml须藤 yum 安装 php70# 安装额外的常用php包须藤 yum 安装 php70-gd须藤 yum 安装 php70-imap须藤 yum 安装 php70-mbstring须藤 yum 安装 php70-mysqlnd须藤 yum 安装 php70-opcache须藤 yum 安装 php70-pdo须藤 yum 安装 php70-pecl-apcu

2.修改 DirectoryIndex 以包含 index.php

sudo nano/etc/httpd/conf/httpd.conf

找到这个:

目录索引 index.html</IfModule>

并将其修改为如下所示:

DirectoryIndex index.html index.php</IfModule>

如果一个目录包含一个 index.html 和一个 index.php,服务器将使用此设置提供 index.html.如果您不希望这种情况发生,您有以下选择:

颠倒顺序,所以 index.php 在两个文件都存在时提供:

 DirectoryIndex index.php index.html</IfModule>

仅使用 index.php 作为 DirectoryIndex:

目录索引 index.php</IfModule>

3.启动 Apache 网络服务器

sudo service httpd start

4.将 Apache Web 服务器配置为在每次系统启动时启动

sudo chkconfig httpd on

5.测试您的安装

创建phpinfo.php:

echo '

打开浏览器并在地址栏中输入实例的公共 IP,然后输入/phpinfo.php

示例:http://xxx.xxx.xxx.xxx/phpinfo.php

注意:不要忘记在您的实例的安全组中允许 HTTP(端口 80)的传入连接,否则您的请求将超时.>

I want to install the latest PHP 7.0 on an AWS EC2 T2.Micro Instance. So far I have read that currently AWS do not support PHP 7. But hey.. This is just a virtual server in the cloud with me having the full control over its configuration, so there must be some way to get PHP 7 running on this one.

Any help much appreciated.

My box is as below

$ cat /etc/*-release
---------------------------------------
NAME="Amazon Linux AMI"
VERSION="2015.09"
ID="amzn"
ID_LIKE="rhel fedora"
VERSION_ID="2015.09"
PRETTY_NAME="Amazon Linux AMI 2015.09"
ANSI_COLOR="0;33"
CPE_NAME="[*not significant*]"
HOME_URL="http://aws.amazon.com/amazon-linux-ami/"
Amazon Linux AMI release 2015.09

$ uname -a
---------------------------------------
Linux ip-xxx-xxx-xxx-xxx 4.1.13-18.26.amzn1.x86_64 #1 [date] x86_64 x86_64 x86_64 GNU/Linux

$ uname -mrs
---------------------------------------
Linux 4.1.13-18.26.amzn1.x86_64 x86_64

$ cat /proc/version
---------------------------------------
Linux version 4.1.13-18.26.amzn1.x86_64 (mockbuild@gobi-build-64010) (gcc version 4.8.3 20140911 (Red Hat 4.8.3-9) (GCC) )

解决方案

You can now use the official php7 packages. Here an easy to follow guide.

1. Install Apache 2.4 and PHP 7.0 on Amazon Linux AMI

# Remove current apache & php 
sudo yum remove httpd* php*

# Install Apache 2.4
sudo yum install httpd24

# Install PHP 7.0 
# automatically includes php70-cli php70-common php70-json php70-process php70-xml
sudo yum install php70

# Install additional commonly used php packages
sudo yum install php70-gd
sudo yum install php70-imap
sudo yum install php70-mbstring
sudo yum install php70-mysqlnd
sudo yum install php70-opcache
sudo yum install php70-pdo
sudo yum install php70-pecl-apcu

2. Modify DirectoryIndex to include index.php

sudo nano /etc/httpd/conf/httpd.conf

find this:

<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>

and modify it to look like this:

<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>

If a directory contains an index.html and an index.php, the server will serve the index.html with this setup. If you do not want that to happen, you have the following options:

Reverse the order, so index.php is served when both files exist:

 <IfModule dir_module>
    DirectoryIndex index.php index.html
 </IfModule>

Only use index.php as the DirectoryIndex:

<IfModule dir_module>
    DirectoryIndex index.php
</IfModule>

3. Start the Apache web server

sudo service httpd start

4. Configure the Apache web server to start at each system boot

sudo chkconfig httpd on

5. Test your installation

Create phpinfo.php:

echo '<?php print phpinfo();' | sudo tee --append /var/www/html/phpinfo.php

Open your browser and enter your instance's public IP in the address bar followed by /phpinfo.php

Example: http://xxx.xxx.xxx.xxx/phpinfo.php

Note: Don't forget to allow incoming connections for HTTP (port 80) in the Security Groups of your instance, else your request will time out.

这篇关于如何在运行 Amazon Linux Distro 的 EC2 t2.micro 实例上安装 PHP 7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆