Install Laravel and all dependencies on Amazon Linux AMI With Apache2, PHP 7.2, Composer and MySQL

Mohammadali Fallahian
Aug 12 · 3 min read

Check your Linux version and update packages

Check Linux version:

$ cat /etc/*-release

Update packages:

$ sudo yum update

Install Apache2 web server and PHP related modules

Install Apache2 web server:

$ sudo yum install httpd24

Install PHP 7.2 and related modules:

$ sudo yum install php72 php72-mysqlnd php72-mbstring php72-pdo

Install MySQL server

Install MySQL Server:

$ sudo yum install mysql56-server

To update the root password:

$ mysqladmin -u root password [your_new_password]

Install Composer

Download composer:

$ sudo curl -sS | sudo php

Move Composer to make it executable:

$ sudo mv composer.phar /usr/local/bin/composer
$ sudo ln -s /usr/local/bin/composer /usr/bin/composer

Install Laravel and set permissions of web directory

Install Laravel globally:

$ composer global require "laravel/installer"

Add ec2-user to the apache group:

$ sudo usermod -a -G apache ec2-user

Change the owner of web directory to apache:

$ sudo chown -R ec2-user:apache /var/www

Add write permissions for directories, sub-directories and files:

$ sudo chmod 2775 /var/www$ find /var/www -type d -exec sudo chmod 2775 {} \;$ find /var/www -type f -exec sudo chmod 0664 {} \;

Create new laravel project in “ /var/www” folder:

$ cd /var/www$ ~/.composer/vendor/bin/laravel new MyProject

Configuring web server

Open httpd.conf to make some changes:

$ sudo vim /etc/httpd/conf/httpd.conf

Make the following edits ( you can view the line numbers):

119 DocumentRoot "/var/www/MyProject/public"131 <Directory "/var/www/MyProject/public">151 AllowOverride All

Start the web server up and ensure httpd starts on boot:

$ sudo chkconfig httpd on$ sudo /etc/init.d/httpd start

We just need to update the permissions again to avoid issues down the track.

$ find /var/www -type d -exec sudo chmod 2775 {} \;$ find /var/www -type f -exec sudo chmod 0664 {} \;

Install FTP Server

For the easy transfer of files between a client and server install FTP server:

$ Sudo yum install vsftpd

Configure security groups in your instance:

Log in to the AWS EC2 Management Console and select Security Groups from the navigation tree on the left. Select the security group assigned to your EC2 instance. Then select the Inbound tab, then click Edit.

Add two Custom TCP Rules with port ranges 20–21 and 1024–1048. For Source, you can select ‘Anywhere’. If you decide to set Source to your own IP address, be aware that your IP address might change if it is being assigned via DHCP.

update the vsftpd.conf file:

$ sudo vi /etc/vsftpd/vsftpd.conf

Change anonymous_enable value:


Add these lines:

pasv_address=<Public IP of your instance>

Restart vsftpd:

$ sudo /etc/init.d/vsftpd restart

Create a new user on EC2 instance:

$ adduser awsftpuser
$ passwd awsftpuser
After executing the above two commands enter your new password

Restricting user to their Home directory:

$ sudo vi /etc/vsftpd/vsftpd.conf

Remove # argument from this line:


Restart the FTP service:

$ sudo /etc/init.d/vsftpd restart

Change / Set user’s FTP home directory & give group permissions:

$ sudo usermod -d /var/www/ ftpuser

Then, make sure the ftpuser is the part of the group which owns the files in this folder, to allow them to upload/change/delete as you wish. To check the ownership status of files in your www folder, do the following:

$ cd /var/www/
$ ls -l
$ usermod -a -G <your group name> ftpuser
For example: usermod -a -G apache ftpuser
$ sudo /etc/init.d/vsftpd restart

Set to automatically start FTP Server when your server boots:

$ sudo chkconfig --level 345 vsftpd on

Install phpMyAdmin

$ sudo yum --enablerepo=epel install phpmyadmin

Map phpMyAdmin to a web accessible directory:

$ sudo ln -s /usr/share/phpMyAdmin /var/www/MyProject/public /phpmyadmin

You can access to phpMyAdmin panel through:

http://<Public IP of your instance>/phpmyadmin

Restart the httpd service:

$ sudo /etc/init.d/httpd restart

Enjoy Using Laravel on Amazon Linux AMI Server …

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade