Install LAMP Stack on Amazon EC2
This guide walks through installing a full LAMP (Linux, Apache, MySQL, PHP) stack on an Amazon EC2 Ubuntu instance, including adding the Ondrej PPA for up-to-date PHP packages.
Prerequisites
- An Amazon EC2 instance running Ubuntu 16.04 or later
- SSH access with sudo privileges
- Ports 80 and 443 open in the EC2 security group
Steps
1. Update the package index
sudo apt-get update
2. Add the Ondrej PHP PPA for latest PHP packages
sudo add-apt-repository ppa:ondrej/apache2
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
3. Install Apache, MySQL, PHP and common extensions
sudo apt-get -y install apache2 mysql-server
sudo apt-get -y install zip curl php libapache2-mod-php php-curl php-gd php-mysql php-mbstring php-zip php-xml php-mcrypt php-cli php-intl
4. Enable the PHP module and restart Apache
sudo a2enmod php7.0
sudo service apache2 restart
5. Increase upload limits in php.ini
sudo nano /etc/php/7.0/apache2/php.ini
Set:
upload_max_filesize = 32M
post_max_size = 32M
6. Secure MySQL installation
sudo mysql_secure_installation
Verify
apache2 -v
php -v
mysql --version
Browse to the server IP to see the Apache default page.
Notes
- To list available PHP modules:
sudo apt-cache search php7.0- | less - To switch between PHP versions, use
a2dismod php5anda2enmod php5.6then restart Apache. - After installing phpMyAdmin, choose Apache2 as the web server and opt in to configure the database with dbconfig-common.