Setup Laravel 5 in Amazon Elastic Beanstalk
This is my first time dealing with AWS. Initially, I setup my Laravel project in a normal EC2 instance, and manually install mysql, web server, etc.
Then a friend of mine told me that this kind of infrastructure is not scalable. Eventually I go for Elastic Beanstalk.
Create an AWS account
You need a valid credit card to perform this action. Just follow the instruction will do.
Then choose Web server environment.
You can temporary choose Sample application first.
Or you can use command line to create (see here)
Now you can click on the link above to see your sample page
Once you have installed. Run the following command
You will be prompted to key in AWS credential. Refer the instruction here
Go to Configuration on your left side, then select Instances
If you don’t have a key, create it. Download it and put into your
NOTE: Bare in mind that whenever you ssh in and change something, the changes only temporary, once it scale up and down the changes will be lost
If you notice, there is a file named .env.sample in all laravel project, and you need to rename/copy it as .env (without sample), this is because the configuration cannot be push to git repo, due to security reason.
Now, in elasticbeanstalk, if you ssh in and rename it to .env, then when it scale up and down, the .env will be lost, and the site may be down. Thus, the you have to add the config settings to environment variables
Go to Services (in the top left), and choose
RDS, then follow the instruction.
Now go to your instances
Get the link and put it in your environment variable.
Now, the deployment is pretty simple (assume you’re using git here)
In your local,
cd to the project root, then run a command
It will deploy the latest commit, if you have any changes which not committed yet, it won’t be deployed.