5-Minute Guide to Installing Laravel on Amazon Web Servers

5-Minute Guide to Installing Laravel on Amazon Web Servers

Brandon Estrella
Allison Morris | November 23, 2016

Here at Site Transition we absolutely love Laravel. Paired with a new instance of an Amazon Web Server and we feel like we can accomplish anything!

Here is our 5-minute guide to installing Laravel on a new AWS instance.

Before we start, we are assuming

  1. You have a running instance of AWS already set up
  2. You are familiar with SSH
  3. You understand the basics of Linux. Mostly, navigating your away around the terminal.

Step 1: SSH into your new Instance

We use PHP storm as our development IDE which has a great ssh tool built in, however any ssh tool such as Putty will work here

Step 2: Update your AWS

The first thing that should be done is updating your instance

$ sudo yum update -y

Step 3: Install Apache, PHP, MySQL, PHP-MySQL Ext, and PHP ext for AWS

Include the necessary requirements

$ sudo yum install -y httpd24 php56 mysql55-server php56-mysqlnd php56-mbstring

Step 4: Start Apache

Fire up the web server

$ sudo service httpd start

Note: To auto launch apache at system boot

$ chkconfig httpd on

Check the public DNS in the web browser. You should see the Apache Linux AMI test page

Boom! Your web server is up and running

Step 5: Set your file permissions

$ sudo groupadd www
$ sudo usermod -a -G www ec2-user

Now, exit your ssh connection and reconnect for your file groupadd change to take effect

Step 6: Continue setting file permissions

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

Step 7: Secure your MySQL install

All MySQL comes pre-loaded with default settings that should be changed on every install for security purposes

$ sudo service mysqld start
$ sudo mysql_secure_installation

The current password for root is blank, so just hit enter upon receiving the first prompt.

Press 'Y' and hit enter for each of the next 5 options


Note: To auto launch MySQL at system boot

$ sudo chkconfig mysqld on

Step 7: Create a fresh database

Let's create a new database that will be used with Laravel. *Remove the asterisks below and replace with the password that you created above during the MySQL secure install step.

$ mysql -uroot -p****
$ create database databasename;
$ \q

Step 7: Install Composer

Composer is an application-level package manager for the PHP programming language that provides a standard format for managing dependencies of PHP software and required libraries.

$ sudo curl -sS https://getcomposer.org/installer | sudo php
$ sudo mv composer.phar /usr/local/bin/composer
$ sudo ln -s /usr/local/bin/composer /usr/bin/composer

Step 8: Install GIT

$ sudo yum install git-all

Step 9: Install Laravel

$ cd /var/www
$ sudo git clone https://github.com/laravel/laravel.git
$ cd /var/www/laravel
$ sudo composer install
$ sudo chown -R ec2-user /var/www/laravel
$ sudo chmod -R 755 /var/www/laravel
$ sudo chmod -R 777 /var/www/laravel/storage

Step 10: Create .env file by renaming the .env.example file

$ mv .env.example .env

Step 11: Generate Laravel Key

$ php artisan key:generate

Step 12: Update the .env file

This is where Laravel stores the variables for the database config file, among others. TIP: you can not use the mouse to click position when editing files in linux. Use the arrow keys to navigate around

$ nano .env
DB_DATABASE = databasename
DB_PASSWORD = "created when securing mysql above"

To save changes press CTRL + X, then yes to saving the file as the same name

Step 13: Change Httpd.conf file

Now, we need to let Apache know where to files reside.

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

There will be 2 areas where the path should be updated and 1 change to allow pretty urls.

DocumentRoot "/var/www/html" change to DocumentRoot "/var/www/laravel/public"
Directory "/var/www/html" change to Directory "/var/www/laravel/public"
AllowOverride None change to AllowOverride All

Step 14: Restart Httpd

Restart Apache for changes to take effect

$ sudo service httpd restart

You're done!

You now have a fully functional Laravel installation set up on your Amazon Web Server. Check it out at your public DNS to see the Laravel home page

Brandon Estrella
Allison Morris
Content Writer
Featured in AWS, Laravel