How to install PHP 7 on EC2 t2.micro Instance runn

2020-02-02 04:43发布

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

14条回答
放荡不羁爱自由
2楼-- · 2020-02-02 05:04

Current answer to problem (not original version in question) - worth knowing since this is a bit simpler and php7 isn't available in the standard repos for Amazon Linux 2, and this didn't come up until I searched a bit harder:

amazon-linux-extras install php7.2

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

amazon-linux-extras list
查看更多
Juvenile、少年°
3楼-- · 2020-02-02 05:04

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:

ln -s /usr/bin/php70 /usr/local/bin/php 
php -v
查看更多
太酷不给撩
4楼-- · 2020-02-02 05:04

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:

  1. Remove the current version of php and related tools:

sudo yum remove 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):

sudo yum remove 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)

sudo yum install httpd24.x86_64

sudo service httpd start

  1. Install PHP 7

sudo yum install 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!
查看更多
走好不送
5楼-- · 2020-02-02 05:07

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:

# 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
查看更多
Rolldiameter
6楼-- · 2020-02-02 05:07

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

To list available packages, run yum list php70*

查看更多
Lonely孤独者°
7楼-- · 2020-02-02 05:07

It's simple. Just:

sudo amazon-linux-extras install -y php7.2
查看更多
登录 后发表回答