DEV Community

Cover image for Laravel Deployment on Elastic Beanstalk

Laravel Deployment on Elastic Beanstalk

Youssef Selem on April 20, 2020

so i was trying to deploy Laravel web application on AWS elastic beanstalk, although it appeared to be easy it wasn't. some obstacles were hidden o...
Collapse
 
robotys profile image
Robotys

If you are using git for the laravel code, you might want to use elastic beanstalk cli tools. Then you can deploy the changes immediately with eb deploy command.

Collapse
 
yousseffarag96 profile image
Youssef Selem

Actually i did that after deployment 😅

Collapse
 
brnathanlima profile image
Nathanael Lima

I have the same problem

Collapse
 
safventure11000 profile image
Saf11000 • Edited

I was able to fix it. This is what I did.

cd /etc/nginx/conf.d/elasticbeanstalk - Navigate to the php.conf file
sudo nano php.conf - open the file

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

Insert the following after index and before location, then save and restart.

Alt Text

There has been a change in Elastic beanstalk. 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.

Thread Thread
 
brnathanlima profile image
Nathanael Lima

Thank you for your answer but it didn't work...

Thread Thread
 
safventure11000 profile image
Saf11000 • Edited
Thread Thread
 
brnathanlima profile image
Nathanael Lima

Tried both but didn't work :/

Anyway, I created a brand new Laravel app and pulled a repo on it called rennokki/laravel-aws-eb and I was able to deploy without any problem. There might be something wrong in my app, not in the deployment process itself. Since it's still a small app I think that I'll recreate it...

Thanks for trying to help!

Thread Thread
 
safventure11000 profile image
Saf11000

nice :)

Collapse
 
jmpps profile image
JM PPS

Sorry but this is so wrong.
You should never "log in" and install anything on an ec2 instance that is built by Elastic Beanstalk.

The configuration of your elastic beanstalk environment should be done using the .ebextensions and .platform directories. Look it up.

Otherwise, the moment you do an update or scale out and EB build a new instance, you have to log in and do it all over again.

You can also set all your settings as environment variables in the elastic beanstalk config.

Collapse
 
safventure11000 profile image
Saf11000

Please let me know if you are able to fix this. I also have the same problem. thanks :)

Collapse
 
usamahusnain profile image
usama-husnain

i am facing this issue when running php artisan migrate:

SQLSTATE[HY000] [2002] Connection timed out (SQL: select * from information_schema.tables where table_schema = ebdb and
table_name = migrations and table_type = 'BASE TABLE')

please help anyone

Collapse
 
mo2menelzeiny profile image
Mo'men El-Zeiny

Awesome guide man!
though, whats so special about Elastic Beanstalk anyways?

Collapse
 
yousseffarag96 profile image
Youssef Selem

It connects all the services in one place..think about it as the boiler plate

Collapse
 
williamabbott profile image
williamabbott

If you have more than one instance you will need a centralized cache, and not running separately on each instance as they will become out of sync === different content on different instances.

Collapse
 
jayroy777 profile image
Jay Roy

Thanks, man your explanation solved my problem.