如何在EC2 t2上安装PHP 7。运行Amazon Linux发行版的微实例

时间:2023-01-26 12:55:52

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.

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

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) )

12 个解决方案

#1


48  

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

您现在可以使用正式的php7包。这里有一个简单的指南。

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

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. Modify DirectoryIndex to include index.php

2。修改DirectoryIndex以包含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:

如果一个目录包含一个索引。html和索引。php,服务器将服务于索引。与这个设置html。如果你不希望这种情况发生,你有以下选择:

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

反转顺序,索引。当两个文件同时存在时,将提供php:

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

Only use index.php as the DirectoryIndex:

只使用索引。php DirectoryIndex:

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

3. Start the Apache web server

3所示。启动Apache web服务器

sudo service httpd start

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

4所示。将Apache web服务器配置为在每次系统引导时启动

sudo chkconfig httpd on

5. Test your installation

5。测试你的安装

Create phpinfo.php:

到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

打开您的浏览器并在地址栏中输入您的实例的公共IP,然后是/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.

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

#2


33  

I got this running on my instance. You need http2.2 for it to work with the webtatic repo. I had so many repos there were a bunch of different version incompatibilities. I didn't keep great notes but looking at my history I basically did this:

我在实例中运行了这个。需要http2.2来处理webtatic repo。我有很多回购,有很多不同版本的不兼容。我没有做很好的笔记,但回顾我的历史,我基本上是这样做的:

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

# Remove any third party repos that aren't relevant
sudo yum repolist
sudo yum remove remi-safe

# Install Standard Apache for Amazon AMI
sudo yum install httpd   #specify http22 if you get a different version

# Download webtatic
mkdir -p /tmp/php7
cd /tmp/php7
wget https://mirror.webtatic.com/yum/el6/latest.rpm

# Install webtatic repo
sudo yum install latest.rpm
sudo vi /etc/yum.repos.d/webtatic.repo  'set repo enables
sudo yum clean all

# Install base php7
sudo yum install --enablerepo=webtatic php70w
php -v   #Should say something like  PHP 7.0.2 (cli) (built: Jan  9 2016 16:09:32) ( NTS )
sudo yum install php70w-opcache
sudo yum install php70w-xml
sudo yum install php70w-pdo
sudo yum install php70w-mysqlnd
sudo yum install php70w-gd
sudo yum install php70w-apcu
sudo yum install php70w-pecl-apcu
sudo yum install php70w-mbstring
sudo yum install php70w-imap

# Restart apache
sudo service httpd restart

#3


13  

There are now official php7 packages for aws linux as of July 14, 2016. See the announcement at https://forums.aws.amazon.com/ann.jspa?annID=3902

截止2016年7月14日,aws linux的正式php7包已经发布。参见https://forums.aws.amazon.com/ann.jspa?

To list available packages, run yum list php70*

要列出可用的包,运行yum列表php70*

#4


9  

I was installing PHP 7.0 on a production box that already has apache 2.4 and PHP 5.5. I wanted to install PHP 7.0 alongside it in a way that would have no Server outage. This is what I did.

我在一个已经有apache 2.4和PHP 5.5的产品框上安装了PHP 7.0。我想在它旁边安装PHP 7.0,这样就不会出现服务器中断。这就是我所做的。

# 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-pecl-apcu

This happily installed PHP 7 alongside PHP 5.5. The trick was to tell apache to use 7.0. I'm not sure if this was the best way, but I achieved this by changing these 2 permalinks:

这很好地安装了PHP 7和PHP 5.5。诀窍是告诉apache使用7.0。我不确定这是否是最好的方法,但我通过改变这两个permalinks实现了这一点:

ln -sf /etc/httpd/conf.d/php-conf.7.0 /etc/alternatives/php.conf
ln -sf /etc/httpd/conf.modules.d/15-php-conf.7.0 /etc/alternatives/10-php.conf

At this point apache is still happily running 5.5. Then when you restart apache it should be working with 7.0 (maybe 7.0.1). This is the no downtime way. I'd still recommend doing what I did, which is to rebuild PROD on another instance (create a TEST server) and test it all once before actually doing it on PROD. Good luck!

此时,apache仍在愉快地运行5.5。然后,当您重新启动apache时,它应该使用7.0(可能是7.0.1)。这是不停机的方式。我仍然建议做我所做的事情,即在另一个实例上重新构建PROD(创建一个测试服务器),并在实际使用PROD之前对它进行一次测试。

Oh, and right now the php command will still run 5.5. You can either change any scripts or CRON jobs to point to php7 or change the default version by running

噢,现在php命令仍然会运行5。5。您可以更改任何脚本或CRON作业以指向php7,或者通过运行更改默认版本

alternatives --config php

#5


7  

The other answers seem to only work with Apache 2.2 but not 2.4.

其他答案似乎只适用于Apache 2.2,而不适用于2.4。

Here's how I installed php7 on Amazon Linux running Apache 2.4:

下面是我如何在运行Apache 2.4的Amazon Linux上安装php7:

First, if php is already installed, then remove it:

首先,如果php已经安装,那么删除它:

sudo yum remove php5*

Take note of the php5 packages that are being removed as you'll need to install the php7 versions of them. The php7 package names have a fairly direct and unambiguous mapping from their php5 counterparts as you'll see below. The rest of the instructions cover a classic LAMP stack and may be sufficient for your use-case.

注意要删除的php5包,因为需要安装php7版本的php7包。php7包名与php5包名具有相当直接和明确的映射,如下所示。其余的说明包含了一个经典的LAMP堆栈,对于您的用例来说可能已经足够了。

Using instructions from http://www.spidersoft.com.au/2015/php-7-on-ami-linux-ec2/

使用http://www.spidersoft.com.au/2015/php-7-on-ami-linux-ec2/的指示

wget http://mirrors.mediatemple.net/remi/enterprise/remi-release-6.rpm
sudo yum install remi-release-6.rpm

edit /etc/yum.repos.d/epel.repo and set enabled=1

编辑/etc/yum.repos.d / epel。回购并设置启用= 1

sudo yum upgrade -y
sudo yum install php70 php70-php-fpm php70-php-xml php70-php-pdo php70-php-mysqlnd php70-php-gd php70-php-pecl-apcu php70-php-mbstring php70-php-mcrypt php70-php-opcache

Now you should have php70-php-fpm installed, which you can use in conjunction with apache:

现在应该安装php70-php-fpm,可以与apache结合使用:

Start the fpm daemon:

开始fpm守护进程:

sudo service php70-php-fpm start

Switch Apache from prefork to mpm event worker (this is required because mod_php isn't thread safe) in /etc/httpd/conf.modules.d/00-mpm.conf:

从prefork切换到mpm事件处理程序(这是必需的,因为mod_php不是线程安全的),在/etc/httpd/conf.modules.d/00-mpm.conf:

LoadModule mpm_event_module modules/mod_mpm_event.so

Instruct apache to pass all php requests to php-fpm by adding the following lines in /etc/httpd/conf/httpd.conf

通过在/etc/httpd/conf中添加以下行,指示apache将所有php请求传递给php-fpm

<FilesMatch \.php$>
         SetHandler "proxy:fcgi://127.0.0.1:9000"
</FilesMatch>
DirectoryIndex /index.php index.php

Restart apache using sudo service httpd restart. If everything went ok you should be able to verify the installation by requesting a php file containing phpinfo().

使用sudo服务重新启动apache。如果一切顺利,您应该能够通过请求包含phpinfo()的php文件来验证安装。

If you have existing shell scripts that use php's cli interpreter and thus start with #!/usr/bin/php, you have to set up a symlink to /usr/bin/php since the binary is now named /usr/bin/php70. You can do this as follows:

如果您有使用php的cli解释器的shell脚本,那么从#开始!/usr/bin/php,您必须设置一个到/usr/bin/php的符号链接,因为二进制现在被命名为/usr/bin/php70。你可以这样做:

sudo ln -s /usr/bin/php70 /usr/bin/php

For more info on how to configure php-fpm see https://wiki.apache.org/httpd/PHP-FPM

有关如何配置php-fpm的更多信息,请参见https://wiki.apache.org/httpd/PHP-FPM。

#6


3  

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/install-LAMP.html

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/install-LAMP.html

can follow this step-by-step guide for LAMP installation

可以按照这个步骤安装灯吗

sudo yum update -y

sudo yum install -y httpd24 php70 mysql56-server php70-mysqlnd

sudo service httpd start

#7


1  

If you want a quick copy-paste install:

如果你想要一个快速复制粘贴安装:

wget http://mirrors.mediatemple.net/remi/enterprise/remi-release-6.rpm
sudo yum install -y remi-release-6.rpm
sudo yum update -y
sudo yum install -y --enablerepo=epel php70

Test with:

测试:

php70 -v

And if you want the executable to be php:

如果你希望可执行文件是php:

ln -s /usr/bin/php70 /usr/local/bin/php 
php -v

#8


1  

This thread helped me get close enough to finish it off, I'm sharing the commands and output that worked for me.

这个线程帮助我足够接近完成它,我正在共享对我有用的命令和输出。

On Amazon Lightsail with Amazon Linux (amzn1.x86_64), the following command list helped me rid the system of Apache 2.2 and PHP 5.3 to get to Apache 2.4 and PHP:

使用Amazon Linux的Amazon Lightsail (amzn1.x86_64),下面的命令列表帮助我清除了Apache 2.2和PHP 5.3的系统,以获得Apache 2.4和PHP:

  1. Remove the current version of php and related tools:
  2. 删除当前版本的php和相关工具:

sudo yum remove php*

sudo百胜删除php *

==============================================================================================================================================
Package                           Arch                        Version                                  Repository                       Size
==============================================================================================================================================
Removing:
 php                               x86_64                      5.3.29-1.8.amzn1                         @amzn-main                      7.4 M
 php-cli                           x86_64                      5.3.29-1.8.amzn1                         @amzn-main                      6.4 M
 php-common                        x86_64                      5.3.29-1.8.amzn1                         @amzn-main                      6.3 M
 php-devel                         x86_64                      5.3.29-1.8.amzn1                         @amzn-main                      9.9 M
 php-gd                            x86_64                      5.3.29-1.8.amzn1                         @amzn-main                      669 k
 php-mbstring                      x86_64                      5.3.29-1.8.amzn1                         @amzn-main                      4.1 M
 php-mcrypt                        x86_64                      5.3.29-1.8.amzn1                         @amzn-main                       92 k
 php-mysql                         x86_64                      5.3.29-1.8.amzn1                         @amzn-main                      445 k
 php-pdo                           x86_64                      5.3.29-1.8.amzn1                         @amzn-main                      381 k
 php-xml                           x86_64                      5.3.29-1.8.amzn1                         @amzn-main                      625 k

Transaction Summary
==============================================================================================================================================
Remove  10 Packages
  1. Remove the current version of Apache (note you should backup your conf and conf.d folder before doing this, imho; in my case, it was a new system setup so there was nothing of interest there):
  2. 删除当前版本的Apache(注意,在此之前应该备份conf和conf.d文件夹,imho;在我的例子中,这是一个新的系统设置,所以没有什么有趣的):

sudo yum remove http*

sudo百胜删除http *

==============================================================================================================================================
 Package                           Arch                         Version                                Repository                        Size
==============================================================================================================================================
Removing:
 httpd                             x86_64                       2.2.31-1.8.amzn1                       @amzn-main                       3.0 M
 httpd-devel                       x86_64                       2.2.31-1.8.amzn1                       @amzn-main                       534 k
 httpd-tools                       x86_64                       2.2.31-1.8.amzn1                       @amzn-main                       135 k

Transaction Summary
==============================================================================================================================================
Remove  3 Packages
  1. Install Apache 2.4 (and start Apache)
  2. 安装Apache 2.4(并启动Apache)

sudo yum install httpd24.x86_64

sudo yum安装httpd24.x86_64

sudo service httpd start

sudo服务httpd start

  1. Install PHP 7
  2. 安装PHP 7

sudo yum install php70

sudo yum安装php70

==============================================================================================================================================
 Package                           Arch                       Version                                  Repository                        Size
==============================================================================================================================================
Installing:
 php70                             x86_64                     7.0.13-1.19.amzn1                        amzn-updates                     3.3 M
Installing for dependencies:
 php70-cli                         x86_64                     7.0.13-1.19.amzn1                        amzn-updates                     4.7 M
 php70-common                      x86_64                     7.0.13-1.19.amzn1                        amzn-updates                     1.2 M
 php70-json                        x86_64                     7.0.13-1.19.amzn1                        amzn-updates                      65 k
 php70-process                     x86_64                     7.0.13-1.19.amzn1                        amzn-updates                      79 k
 php70-xml                         x86_64                     7.0.13-1.19.amzn1                        amzn-updates                     309 k

Transaction Summary
==============================================================================================================================================
Install  1 Package (+5 Dependent packages)

Total download size: 9.6 M
Installed size: 31 M
Is this ok [y/d/N]: y
Downloading packages:
(1/6): php70-7.0.13-1.19.amzn1.x86_64.rpm                                                                              | 3.3 MB     00:00
(2/6): php70-cli-7.0.13-1.19.amzn1.x86_64.rpm                                                                          | 4.7 MB     00:00
(3/6): php70-common-7.0.13-1.19.amzn1.x86_64.rpm                                                                       | 1.2 MB     00:00
(4/6): php70-json-7.0.13-1.19.amzn1.x86_64.rpm                                                                         |  65 kB     00:00
(5/6): php70-process-7.0.13-1.19.amzn1.x86_64.rpm                                                                      |  79 kB     00:00
(6/6): php70-xml-7.0.13-1.19.amzn1.x86_64.rpm                                                                          | 309 kB     00:00
----------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                          14 MB/s | 9.6 MB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : php70-json-7.0.13-1.19.amzn1.x86_64                                                                                        1/6
  Installing : php70-process-7.0.13-1.19.amzn1.x86_64                                                                                     2/6
  Installing : php70-xml-7.0.13-1.19.amzn1.x86_64                                                                                         3/6
  Installing : php70-cli-7.0.13-1.19.amzn1.x86_64                                                                                         4/6
  Installing : php70-common-7.0.13-1.19.amzn1.x86_64                                                                                      5/6
  Installing : php70-7.0.13-1.19.amzn1.x86_64                                                                                             6/6
  Verifying  : php70-7.0.13-1.19.amzn1.x86_64                                                                                             1/6
  Verifying  : php70-common-7.0.13-1.19.amzn1.x86_64                                                                                      2/6
  Verifying  : php70-json-7.0.13-1.19.amzn1.x86_64                                                                                        3/6
  Verifying  : php70-process-7.0.13-1.19.amzn1.x86_64                                                                                     4/6
  Verifying  : php70-xml-7.0.13-1.19.amzn1.x86_64                                                                                         5/6
  Verifying  : php70-cli-7.0.13-1.19.amzn1.x86_64                                                                                         6/6

Installed:
  php70.x86_64 0:7.0.13-1.19.amzn1

Dependency Installed:
  php70-cli.x86_64 0:7.0.13-1.19.amzn1            php70-common.x86_64 0:7.0.13-1.19.amzn1        php70-json.x86_64 0:7.0.13-1.19.amzn1
  php70-process.x86_64 0:7.0.13-1.19.amzn1        php70-xml.x86_64 0:7.0.13-1.19.amzn1

Complete!

#9


0  

The php 7 package name is php70w. So what you can do is, install a Webtatic repo on you linux machine and install it from there.

php7包名是php70w。所以你可以做的是,在你的linux机器上安装一个Webtatic的repo,然后在那里安装它。

rpm -ivh https://mirror.webtatic.com/yum/el6/latest.rpm
yum clean all
yum install --enablerepo=webtatic php70w

#10


0  

Several answers should work here; however, when I was installing mine, it would not render pages and would display text instead of rendered PHP.

这里应该有几个答案;但是,当我安装我的程序时,它不会显示页面,而是显示文本而不是呈现的PHP。

To fix that, I ran

为了解决这个问题,我跑了

sudo yum install php70-php-fpm

sudo yum安装php70-php-fpm

After that, everything started working.

从那以后,一切都开始运转了。

#11


0  

Here is how I installed PHP 7.1 on Amazon Linux:

下面是我如何在Amazon Linux上安装PHP 7.1:

wget http://rpms.remirepo.net/enterprise/remi-release-6.rpm
rpm -Uvh remi-release-6.rpm epel-release-latest-6.noarch.rpm
yum-config-manager --enable remi-php71

wget ftp://195.220.108.108/linux/epel/6/x86_64/Packages/s/scl-utils-20120229-1.el6.x86_64.rpm
rpm -Uvh scl-utils-20120229-1.el6.x86_64.rpm 

yum install php71

https://gist.github.com/ihor/581d169886c29e7e17d01b0041167b01

https://gist.github.com/ihor/581d169886c29e7e17d01b0041167b01

#12


0  

Late answer, but worth knowing since this is a bit simpler / php7 isn't available in the standard repos for LTS AMI, and this didn't come up until I searched a bit harder:

很晚的回答,但是值得知道的是,因为这更简单一点/ php7在LTS AMI的标准repos中没有,直到我搜索得更深入一点之后才出现:

amazon-linux-extras install php7.2

Version of extras can be checked with a list command if v7.2 is no longer current:

如果v7.2不再是当前版本,可以使用列表命令检查额外的版本:

amazon-linux-extras list

#1


48  

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

您现在可以使用正式的php7包。这里有一个简单的指南。

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

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. Modify DirectoryIndex to include index.php

2。修改DirectoryIndex以包含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:

如果一个目录包含一个索引。html和索引。php,服务器将服务于索引。与这个设置html。如果你不希望这种情况发生,你有以下选择:

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

反转顺序,索引。当两个文件同时存在时,将提供php:

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

Only use index.php as the DirectoryIndex:

只使用索引。php DirectoryIndex:

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

3. Start the Apache web server

3所示。启动Apache web服务器

sudo service httpd start

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

4所示。将Apache web服务器配置为在每次系统引导时启动

sudo chkconfig httpd on

5. Test your installation

5。测试你的安装

Create phpinfo.php:

到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

打开您的浏览器并在地址栏中输入您的实例的公共IP,然后是/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.

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

#2


33  

I got this running on my instance. You need http2.2 for it to work with the webtatic repo. I had so many repos there were a bunch of different version incompatibilities. I didn't keep great notes but looking at my history I basically did this:

我在实例中运行了这个。需要http2.2来处理webtatic repo。我有很多回购,有很多不同版本的不兼容。我没有做很好的笔记,但回顾我的历史,我基本上是这样做的:

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

# Remove any third party repos that aren't relevant
sudo yum repolist
sudo yum remove remi-safe

# Install Standard Apache for Amazon AMI
sudo yum install httpd   #specify http22 if you get a different version

# Download webtatic
mkdir -p /tmp/php7
cd /tmp/php7
wget https://mirror.webtatic.com/yum/el6/latest.rpm

# Install webtatic repo
sudo yum install latest.rpm
sudo vi /etc/yum.repos.d/webtatic.repo  'set repo enables
sudo yum clean all

# Install base php7
sudo yum install --enablerepo=webtatic php70w
php -v   #Should say something like  PHP 7.0.2 (cli) (built: Jan  9 2016 16:09:32) ( NTS )
sudo yum install php70w-opcache
sudo yum install php70w-xml
sudo yum install php70w-pdo
sudo yum install php70w-mysqlnd
sudo yum install php70w-gd
sudo yum install php70w-apcu
sudo yum install php70w-pecl-apcu
sudo yum install php70w-mbstring
sudo yum install php70w-imap

# Restart apache
sudo service httpd restart

#3


13  

There are now official php7 packages for aws linux as of July 14, 2016. See the announcement at https://forums.aws.amazon.com/ann.jspa?annID=3902

截止2016年7月14日,aws linux的正式php7包已经发布。参见https://forums.aws.amazon.com/ann.jspa?

To list available packages, run yum list php70*

要列出可用的包,运行yum列表php70*

#4


9  

I was installing PHP 7.0 on a production box that already has apache 2.4 and PHP 5.5. I wanted to install PHP 7.0 alongside it in a way that would have no Server outage. This is what I did.

我在一个已经有apache 2.4和PHP 5.5的产品框上安装了PHP 7.0。我想在它旁边安装PHP 7.0,这样就不会出现服务器中断。这就是我所做的。

# 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-pecl-apcu

This happily installed PHP 7 alongside PHP 5.5. The trick was to tell apache to use 7.0. I'm not sure if this was the best way, but I achieved this by changing these 2 permalinks:

这很好地安装了PHP 7和PHP 5.5。诀窍是告诉apache使用7.0。我不确定这是否是最好的方法,但我通过改变这两个permalinks实现了这一点:

ln -sf /etc/httpd/conf.d/php-conf.7.0 /etc/alternatives/php.conf
ln -sf /etc/httpd/conf.modules.d/15-php-conf.7.0 /etc/alternatives/10-php.conf

At this point apache is still happily running 5.5. Then when you restart apache it should be working with 7.0 (maybe 7.0.1). This is the no downtime way. I'd still recommend doing what I did, which is to rebuild PROD on another instance (create a TEST server) and test it all once before actually doing it on PROD. Good luck!

此时,apache仍在愉快地运行5.5。然后,当您重新启动apache时,它应该使用7.0(可能是7.0.1)。这是不停机的方式。我仍然建议做我所做的事情,即在另一个实例上重新构建PROD(创建一个测试服务器),并在实际使用PROD之前对它进行一次测试。

Oh, and right now the php command will still run 5.5. You can either change any scripts or CRON jobs to point to php7 or change the default version by running

噢,现在php命令仍然会运行5。5。您可以更改任何脚本或CRON作业以指向php7,或者通过运行更改默认版本

alternatives --config php

#5


7  

The other answers seem to only work with Apache 2.2 but not 2.4.

其他答案似乎只适用于Apache 2.2,而不适用于2.4。

Here's how I installed php7 on Amazon Linux running Apache 2.4:

下面是我如何在运行Apache 2.4的Amazon Linux上安装php7:

First, if php is already installed, then remove it:

首先,如果php已经安装,那么删除它:

sudo yum remove php5*

Take note of the php5 packages that are being removed as you'll need to install the php7 versions of them. The php7 package names have a fairly direct and unambiguous mapping from their php5 counterparts as you'll see below. The rest of the instructions cover a classic LAMP stack and may be sufficient for your use-case.

注意要删除的php5包,因为需要安装php7版本的php7包。php7包名与php5包名具有相当直接和明确的映射,如下所示。其余的说明包含了一个经典的LAMP堆栈,对于您的用例来说可能已经足够了。

Using instructions from http://www.spidersoft.com.au/2015/php-7-on-ami-linux-ec2/

使用http://www.spidersoft.com.au/2015/php-7-on-ami-linux-ec2/的指示

wget http://mirrors.mediatemple.net/remi/enterprise/remi-release-6.rpm
sudo yum install remi-release-6.rpm

edit /etc/yum.repos.d/epel.repo and set enabled=1

编辑/etc/yum.repos.d / epel。回购并设置启用= 1

sudo yum upgrade -y
sudo yum install php70 php70-php-fpm php70-php-xml php70-php-pdo php70-php-mysqlnd php70-php-gd php70-php-pecl-apcu php70-php-mbstring php70-php-mcrypt php70-php-opcache

Now you should have php70-php-fpm installed, which you can use in conjunction with apache:

现在应该安装php70-php-fpm,可以与apache结合使用:

Start the fpm daemon:

开始fpm守护进程:

sudo service php70-php-fpm start

Switch Apache from prefork to mpm event worker (this is required because mod_php isn't thread safe) in /etc/httpd/conf.modules.d/00-mpm.conf:

从prefork切换到mpm事件处理程序(这是必需的,因为mod_php不是线程安全的),在/etc/httpd/conf.modules.d/00-mpm.conf:

LoadModule mpm_event_module modules/mod_mpm_event.so

Instruct apache to pass all php requests to php-fpm by adding the following lines in /etc/httpd/conf/httpd.conf

通过在/etc/httpd/conf中添加以下行,指示apache将所有php请求传递给php-fpm

<FilesMatch \.php$>
         SetHandler "proxy:fcgi://127.0.0.1:9000"
</FilesMatch>
DirectoryIndex /index.php index.php

Restart apache using sudo service httpd restart. If everything went ok you should be able to verify the installation by requesting a php file containing phpinfo().

使用sudo服务重新启动apache。如果一切顺利,您应该能够通过请求包含phpinfo()的php文件来验证安装。

If you have existing shell scripts that use php's cli interpreter and thus start with #!/usr/bin/php, you have to set up a symlink to /usr/bin/php since the binary is now named /usr/bin/php70. You can do this as follows:

如果您有使用php的cli解释器的shell脚本,那么从#开始!/usr/bin/php,您必须设置一个到/usr/bin/php的符号链接,因为二进制现在被命名为/usr/bin/php70。你可以这样做:

sudo ln -s /usr/bin/php70 /usr/bin/php

For more info on how to configure php-fpm see https://wiki.apache.org/httpd/PHP-FPM

有关如何配置php-fpm的更多信息,请参见https://wiki.apache.org/httpd/PHP-FPM。

#6


3  

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/install-LAMP.html

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/install-LAMP.html

can follow this step-by-step guide for LAMP installation

可以按照这个步骤安装灯吗

sudo yum update -y

sudo yum install -y httpd24 php70 mysql56-server php70-mysqlnd

sudo service httpd start

#7


1  

If you want a quick copy-paste install:

如果你想要一个快速复制粘贴安装:

wget http://mirrors.mediatemple.net/remi/enterprise/remi-release-6.rpm
sudo yum install -y remi-release-6.rpm
sudo yum update -y
sudo yum install -y --enablerepo=epel php70

Test with:

测试:

php70 -v

And if you want the executable to be php:

如果你希望可执行文件是php:

ln -s /usr/bin/php70 /usr/local/bin/php 
php -v

#8


1  

This thread helped me get close enough to finish it off, I'm sharing the commands and output that worked for me.

这个线程帮助我足够接近完成它,我正在共享对我有用的命令和输出。

On Amazon Lightsail with Amazon Linux (amzn1.x86_64), the following command list helped me rid the system of Apache 2.2 and PHP 5.3 to get to Apache 2.4 and PHP:

使用Amazon Linux的Amazon Lightsail (amzn1.x86_64),下面的命令列表帮助我清除了Apache 2.2和PHP 5.3的系统,以获得Apache 2.4和PHP:

  1. Remove the current version of php and related tools:
  2. 删除当前版本的php和相关工具:

sudo yum remove php*

sudo百胜删除php *

==============================================================================================================================================
Package                           Arch                        Version                                  Repository                       Size
==============================================================================================================================================
Removing:
 php                               x86_64                      5.3.29-1.8.amzn1                         @amzn-main                      7.4 M
 php-cli                           x86_64                      5.3.29-1.8.amzn1                         @amzn-main                      6.4 M
 php-common                        x86_64                      5.3.29-1.8.amzn1                         @amzn-main                      6.3 M
 php-devel                         x86_64                      5.3.29-1.8.amzn1                         @amzn-main                      9.9 M
 php-gd                            x86_64                      5.3.29-1.8.amzn1                         @amzn-main                      669 k
 php-mbstring                      x86_64                      5.3.29-1.8.amzn1                         @amzn-main                      4.1 M
 php-mcrypt                        x86_64                      5.3.29-1.8.amzn1                         @amzn-main                       92 k
 php-mysql                         x86_64                      5.3.29-1.8.amzn1                         @amzn-main                      445 k
 php-pdo                           x86_64                      5.3.29-1.8.amzn1                         @amzn-main                      381 k
 php-xml                           x86_64                      5.3.29-1.8.amzn1                         @amzn-main                      625 k

Transaction Summary
==============================================================================================================================================
Remove  10 Packages
  1. Remove the current version of Apache (note you should backup your conf and conf.d folder before doing this, imho; in my case, it was a new system setup so there was nothing of interest there):
  2. 删除当前版本的Apache(注意,在此之前应该备份conf和conf.d文件夹,imho;在我的例子中,这是一个新的系统设置,所以没有什么有趣的):

sudo yum remove http*

sudo百胜删除http *

==============================================================================================================================================
 Package                           Arch                         Version                                Repository                        Size
==============================================================================================================================================
Removing:
 httpd                             x86_64                       2.2.31-1.8.amzn1                       @amzn-main                       3.0 M
 httpd-devel                       x86_64                       2.2.31-1.8.amzn1                       @amzn-main                       534 k
 httpd-tools                       x86_64                       2.2.31-1.8.amzn1                       @amzn-main                       135 k

Transaction Summary
==============================================================================================================================================
Remove  3 Packages
  1. Install Apache 2.4 (and start Apache)
  2. 安装Apache 2.4(并启动Apache)

sudo yum install httpd24.x86_64

sudo yum安装httpd24.x86_64

sudo service httpd start

sudo服务httpd start

  1. Install PHP 7
  2. 安装PHP 7

sudo yum install php70

sudo yum安装php70

==============================================================================================================================================
 Package                           Arch                       Version                                  Repository                        Size
==============================================================================================================================================
Installing:
 php70                             x86_64                     7.0.13-1.19.amzn1                        amzn-updates                     3.3 M
Installing for dependencies:
 php70-cli                         x86_64                     7.0.13-1.19.amzn1                        amzn-updates                     4.7 M
 php70-common                      x86_64                     7.0.13-1.19.amzn1                        amzn-updates                     1.2 M
 php70-json                        x86_64                     7.0.13-1.19.amzn1                        amzn-updates                      65 k
 php70-process                     x86_64                     7.0.13-1.19.amzn1                        amzn-updates                      79 k
 php70-xml                         x86_64                     7.0.13-1.19.amzn1                        amzn-updates                     309 k

Transaction Summary
==============================================================================================================================================
Install  1 Package (+5 Dependent packages)

Total download size: 9.6 M
Installed size: 31 M
Is this ok [y/d/N]: y
Downloading packages:
(1/6): php70-7.0.13-1.19.amzn1.x86_64.rpm                                                                              | 3.3 MB     00:00
(2/6): php70-cli-7.0.13-1.19.amzn1.x86_64.rpm                                                                          | 4.7 MB     00:00
(3/6): php70-common-7.0.13-1.19.amzn1.x86_64.rpm                                                                       | 1.2 MB     00:00
(4/6): php70-json-7.0.13-1.19.amzn1.x86_64.rpm                                                                         |  65 kB     00:00
(5/6): php70-process-7.0.13-1.19.amzn1.x86_64.rpm                                                                      |  79 kB     00:00
(6/6): php70-xml-7.0.13-1.19.amzn1.x86_64.rpm                                                                          | 309 kB     00:00
----------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                          14 MB/s | 9.6 MB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : php70-json-7.0.13-1.19.amzn1.x86_64                                                                                        1/6
  Installing : php70-process-7.0.13-1.19.amzn1.x86_64                                                                                     2/6
  Installing : php70-xml-7.0.13-1.19.amzn1.x86_64                                                                                         3/6
  Installing : php70-cli-7.0.13-1.19.amzn1.x86_64                                                                                         4/6
  Installing : php70-common-7.0.13-1.19.amzn1.x86_64                                                                                      5/6
  Installing : php70-7.0.13-1.19.amzn1.x86_64                                                                                             6/6
  Verifying  : php70-7.0.13-1.19.amzn1.x86_64                                                                                             1/6
  Verifying  : php70-common-7.0.13-1.19.amzn1.x86_64                                                                                      2/6
  Verifying  : php70-json-7.0.13-1.19.amzn1.x86_64                                                                                        3/6
  Verifying  : php70-process-7.0.13-1.19.amzn1.x86_64                                                                                     4/6
  Verifying  : php70-xml-7.0.13-1.19.amzn1.x86_64                                                                                         5/6
  Verifying  : php70-cli-7.0.13-1.19.amzn1.x86_64                                                                                         6/6

Installed:
  php70.x86_64 0:7.0.13-1.19.amzn1

Dependency Installed:
  php70-cli.x86_64 0:7.0.13-1.19.amzn1            php70-common.x86_64 0:7.0.13-1.19.amzn1        php70-json.x86_64 0:7.0.13-1.19.amzn1
  php70-process.x86_64 0:7.0.13-1.19.amzn1        php70-xml.x86_64 0:7.0.13-1.19.amzn1

Complete!

#9


0  

The php 7 package name is php70w. So what you can do is, install a Webtatic repo on you linux machine and install it from there.

php7包名是php70w。所以你可以做的是,在你的linux机器上安装一个Webtatic的repo,然后在那里安装它。

rpm -ivh https://mirror.webtatic.com/yum/el6/latest.rpm
yum clean all
yum install --enablerepo=webtatic php70w

#10


0  

Several answers should work here; however, when I was installing mine, it would not render pages and would display text instead of rendered PHP.

这里应该有几个答案;但是,当我安装我的程序时,它不会显示页面,而是显示文本而不是呈现的PHP。

To fix that, I ran

为了解决这个问题,我跑了

sudo yum install php70-php-fpm

sudo yum安装php70-php-fpm

After that, everything started working.

从那以后,一切都开始运转了。

#11


0  

Here is how I installed PHP 7.1 on Amazon Linux:

下面是我如何在Amazon Linux上安装PHP 7.1:

wget http://rpms.remirepo.net/enterprise/remi-release-6.rpm
rpm -Uvh remi-release-6.rpm epel-release-latest-6.noarch.rpm
yum-config-manager --enable remi-php71

wget ftp://195.220.108.108/linux/epel/6/x86_64/Packages/s/scl-utils-20120229-1.el6.x86_64.rpm
rpm -Uvh scl-utils-20120229-1.el6.x86_64.rpm 

yum install php71

https://gist.github.com/ihor/581d169886c29e7e17d01b0041167b01

https://gist.github.com/ihor/581d169886c29e7e17d01b0041167b01

#12


0  

Late answer, but worth knowing since this is a bit simpler / php7 isn't available in the standard repos for LTS AMI, and this didn't come up until I searched a bit harder:

很晚的回答,但是值得知道的是,因为这更简单一点/ php7在LTS AMI的标准repos中没有,直到我搜索得更深入一点之后才出现:

amazon-linux-extras install php7.2

Version of extras can be checked with a list command if v7.2 is no longer current:

如果v7.2不再是当前版本,可以使用列表命令检查额外的版本:

amazon-linux-extras list