如何在运行Amazon Linux Distro的EC2 t2.micro实例上安装PHP 7
我想在AWS EC2 T2.Micro实例上安装最新的PHP 7.0.到目前为止,我已经阅读到当前AWS不支持PHP7.但是,这只是一个云中的虚拟服务器,我可以完全控制其配置,因此必须有某种方法可以使PHP 7在此之上运行一个.
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.
我的盒子如下
$ 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) )
您现在可以使用官方的php7软件包.这是一个易于遵循的指南.
You can now use the official php7 packages. Here an easy to follow guide.
1.在Amazon Linux AMI上安装Apache 2.4和PHP 7.0
# 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.修改DirectoryIndex以包括index.php
sudo nano /etc/httpd/conf/httpd.conf
找到这个:
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
并对其进行修改,使其看起来像这样:
and modify it to look like this:
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
如果目录包含index.html和index.php,则服务器将使用此设置来提供index.html.如果您不希望发生这种情况,则可以使用以下选项:
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:
颠倒顺序,因此当两个文件都存在时将提供 index.php :
Reverse the order, so index.php is served when both files exist:
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
仅将index.php用作DirectoryIndex:
Only use index.php as the DirectoryIndex:
<IfModule dir_module>
DirectoryIndex index.php
</IfModule>
3.启动Apache Web服务器
sudo service httpd start
4.将Apache Web服务器配置为在每次系统启动时启动
sudo chkconfig httpd on
5.测试您的安装
创建phpinfo.php:
Create phpinfo.php:
echo '<?php print phpinfo();' | sudo tee --append /var/www/html/phpinfo.php
打开浏览器,然后在地址栏中输入您实例的公共IP,然后是/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
注意:请不要忘记在实例的安全组中允许HTTP(端口80)的传入连接,否则您的请求将超时.
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.