Elastic Beanstalk

I assume you already have a laravel project ready to deploy and an account in AWS. I registered for free tier. It's a free account but you need to input your cc details.

Alt Text

After logging in, search for Elastic Beanstalk in AWS Management Console.

Alt Text

Click Create Application.

Alt Text

Input your application name. Then for platform, choose PHP and click create application after.

Alt Text

Alt Text

In uploading laravel project source code, I tried two ways.

First method:

** Upload and Deploy**

Alt Text

Alt Text

Zip your laravel project. Make sure you zip it inside your laravel project just like what I did in the screenshot above. Upload the zip file then click Deploy.

Alt Text

Click Configuration in the left pane, then on the software category section, click edit action.

Alt Text

Set document root to /public then click apply.

Alt Text

Alt Text

Click the link for your site and you will be able to see your landing page in the browser. If not, please let me know.

Second Method:

Using Code Pipeline

Search for Code Pipeline in AWS Management Console .

Alt Text

Click create pipeline

Alt Text

Input your details

Alt Text

I'm using Github as my source provider. Choose the appropriate repository and branch. The next steps are all self-explanatory.

Alt Text

You will be able to see a screenshot like mine above if you are able to connect with code pipeline with github.


Search for EC2 in AWS Management Console

Alt Text

Click Running instances.

Alt Text

Right click on your laravel project name. Click connect. Please take note of the commands stated.

Now, lets create a key pairs. Still in EC2 Dashboard, in network and security click key pairs. Create key pair. A .pem file will be downloaded.

I tried using putty, winscp and git bash in connecting. I'll show how I did it with these three. You can choose whatever is more suited for you. They just have the same result.


We need to convert the .pem file to .ppk. To do that download first putty. Download the putty and putty gen installers here:

Puttygen is used to generate a .ppk by using the .pem file

Once done, open puttygen.

Alt Text

Click load then locate your .pem file.

Alt Text

Click save private key.

Alt Text

Open putty then in Auth section browse .ppk file.

Alt Text

The host name is ec2-user@your public DNS in EC2 instances section. Click open after.

Alt Text

If you see the same screen with my screenshot above, you are able to connect successfully using Putty.


Download and install winscp here:

Alt Text

Alt Text

Open winscp and click Advanced. In SSH authentication section, uploadyour .ppk file. If you will upload the .pem file, it's fine. This will be converted to .ppk.

Alt Text

Same with putty, hostname is your public DNS and user name is ec2-user. Click login.

Alt Text

If you have the same screenshot as mine above, you have successfully connected to winscp. Go ahead and transfer/copy/update files from your local machine to the server.

Note: If you're using winscp, you need to use GIT or putty to execute commands.

GIT Bash

Download git here :

chmod 400 laravel-newkey.pem

This is my instance in EC2. Change this with your instance. You must execute it in the folder where you save your .pem file. In my case, my .pem file is in downloads folder.

Alt Text

Execute the ssh command found in your ec2 instance. Make sure to use ec2-user not root.

I'll proceed on using GIT bash.

sudo chown -R ec2-user /var/app/current/

First give the current user permission to write.

cd /var/app/current/

To go to your laravel project folder, execute command above.

Alt Text

sudo curl -sS | sudo php
sudo mv composer.phar /usr/local/bin/composerp
sudo ln -s /usr/local/bin/composer /usr/bin/composer
sudo composer install

We need to install composer, so please execute commands above. This will create a vendor file in your laravel project folder.

sudo chmod -R 0777 storage
sudo chmod 777 storage/logs/laravel.log
sudo chmod 777 storage/framework/cache

Change your storage file permission so that the server can access it.

cp .env.example .env
php artisan key:generate

Don't forget to have .env file, then execute php artisan key:generate.

Before we'll proceed to database, there has been a change in Elastic beanstalk as of this writing. It is now configured to nginx instead of apache so the .htaccess file no longer works. All laravel routes are getting 404 Not Found Nginx error except for the landing page. If you don't encounter this issue, just ignore the work around below.

 cd /etc/nginx/conf.d/elasticbeanstalk

Navigate to the php.conf file using the command above.

sudo nano php.conf

The above command will let us open the file

location / {
        try_files $uri $uri/ /index.php?$query_string;
            gzip_static on;

Insert the following into this after index and before location.

Alt Text

To save, press ctrl+o. Then ctrl+x to exit.

sudo nginx -s reload

Run command above to restart nginx.


Alt Text .env file

Alt Text Environment variables in Elastic Beanstalk software section

Alt Text My database setup in Elastic Beanstalk database section

The info for database config is in RDS. Go ahead and search for RDS in AWS management section.

Alt Text DB_name is ebdb

Alt Text DB_HOST is the endpoint

DBUSERNAME and DBPASSWORD are the one you setup in environment variables in Elasticbeanstalk sofware section. It should be the same in the .env file.

Alt Text I already migrated my db a while ago and forgot to screenshot ehhe

After setting up your database config, go ahead and migrate and seed. Then after, access your site in the browser.

Sharing my knowledge about deployment and I hope I did not miss a thing. Please let me know if you encounter issues. I’ll be happy to help.