0 votes
2 views
in AWS by (19.2k points)

I want to install the latest PHP 7.0 on an AWS EC2 T2.Micro Instance. So far I have read that currently, AWS does not support PHP 7. 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 ([email protected]) (gcc version 4.8.3 20140911 (Red Hat 4.8.3-9) (GCC) )

1 Answer

0 votes
by (44.6k points)

We can use the official PHP packages and Apache’s packages. Follow the below steps to do so.

1. Install PHP 7.0 and Apache web server 2.4 on your 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 a few 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 the directory has both index.html and index.php, then it will the html file with the following set up. If you do not want that to happen, then these you have these options:

We have to reverse their order so that index.php will be displayed if this happens:

 <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 your Apache web server as such it starts at every boot

sudo chkconfig httpd on

5. Test your installation

Create phpinfo.php:

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

Enter your instance’s IP address with /phpinfo.php to test if PHP has been installed. You will see a sample PHP page with commands.

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

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...