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.
Create a new app in Elastic Beanstalk
Then choose Web server environment.
You can temporary choose Sample application first.
Or you can use command line to create (see here)
$ cd to
$ eb create <environment> -t webapp
Now you can click on the link above to see your sample page
eb in your local
Once you have installed. Run the following command
$ eb init
You will be prompted to key in AWS credential. Refer the instruction here
Enable ssh login
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
Add environment variables
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
Configure RDS for your project
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
$ eb deploy <environment>
It will deploy the latest commit, if you have any changes which not committed yet, it won't be deployed.