How to install PHP 7 and MySQL on EC2 Instance – Amazon

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

# Remove current apache & php (If you have installed a earlier version or you are having problems.  Don't worry this WILL NOT remove any of your files, and it will make backup's of any config files you have).
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 mysql 5.6 server (optional only if you need MySQL)
sudo yum install mysql56-server

# 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

#Optional Install - only install if you need SSL
sudo yum install mod24_ssl

2. Modify DirectoryIndex to include index.php

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

find this:

<IfModule dir_module>
    DirectoryIndex index.html

and modify it to look like this:

<IfModule dir_module>
    DirectoryIndex index.html index.php

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

(Optional) Only use index.php as the DirectoryIndex:

<IfModule dir_module>
    DirectoryIndex index.php

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

Comments are closed.