Install Laravel on EC2 instance with Nginx server
Wednesday, 29 June 2016
Link to Github repo
There are pretty clear instructions on how to install Laravel with your local system on the framework's official website. But how about running it live? In this post, we'll use Amazon Web Services (AWS) to launch a single ec2 instance inside a Virtual Private Cloud (VPC) with Laravel and Nginx installed.
A typical web application consists of a web server backed by a database. This will be the backbone for our architecture: an EC2 instance running inside a public subnet linked to a private MySQL database with security groups to regulate traffic between the two. This translates into a webserver being publicly accessible (we want people to be able to send requests to our webserver) and a DB instance accepting traffic from the webserver only. We'll also provide an IAM role for our EC2 instance, so that we can further attach policies to it if we need to.
To see all this in action, open CloudFormation in your AWS console, click "Create New Stack" and specify the following Amazon S3 template URL:
At this stage, you should already be able to have an overlook of the template. Click "Next", pick up a name for your stack and provide parameters. You can leave most options as is, but you'll need to provide a database username and password, as well the name of an existing KeyPair to enable SSH access to your instance. In case you haven't created such a KeyPair so far, visit this page. Click "Next" again, optionally specifying tags for your stack, then "Create" and wait a couple of minutes for the stack creation to complete. Finally click the link under the "Output" tab.
You are now up and running with a fresh new Laravel install on a Nginx webserver. Read this next post of mine to learn how to deploy your code from BitBucket to your newly created instance with AWS CodeDeploy.