Are you struggling to find an easy tutorial on how to deploy Laravel application on AWS EC2? Then here is a blog for you to lessen your hustle! Follow this step-by-step guide to deploy your application on Amazon EC2.
You’d be learning about the following topics for this tutorial.
Make sure you have the following resources to use.
To host our Laravel app on Amazon EC2 we will be using the following technical stack.
Use the following command for logging in to your EC2 instance.
Unleash the power of AWS and elevate your Laravel app to new heights!
Hire AWS Developers who can craft robust infrastructure that fuels your success and witness your digital ambitions come to life.
First of all, run the command to update the libraries with the latest packages.
Get superuser permissions.
Using the previous variable, add the repository. Then, press enter to confirm.
Once done with the installation, check NGINX version.
There are two ways to install a MySQL database.
Install MySQL in Ubuntu by running the below command.
Now, open the MySQL prompt.
Once we are done with the installation process use the below command to configure the root account with an authentication password.
Flush the privileges (changes)
For creating a MySQL database instance, go to the link below, there is a step-by-step guide: Create a MySQL DB instance and connect to a database using AWS RDS.
Since we are done with configuring our database let’s move towards the Laravel project setup. If you are familiar with the initial setup of laravel then feel free to skip the next section and jump to the deployment section.
Develop and Deploy with Bacancy!
Looking for top-notch developers with extraordinary problem-solving skills to accomplish your requirements? Contact us now and hire DevOps developer.
curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php HASH=`curl -sS https://composer.github.io/installer.sig`
echo $HASH Verify the installation script for the composer. php -r "if (hash_file('SHA384', '/tmp/composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
Create the Laravel project
Install composer in the preferable directory
Copy .env file from .env.example and add the following changes. In case you’re using RDS then you need to configure it with RDS creds.
cp .env.example .env DB_DATABASE=dabasename DB_USERNAME=root DB_PASSWORD=your_password DB_HOST=localhost DB_PORT=3306
Migrate the database
Run the server
Now move your Laravel demo code to /var/www/html.
Moving towards the final step- change the Nginx configuration file as per your requirements to deploy the application.
After changing the default virtual host file, your file would look like something like this.
server { listen 80; server_name localhost; root /var/www/html/demo/public; add_header X-Frame-Options "SAMEORIGIN"; add_header X-Content-Type-Options "nosniff"; index index.php; charset utf-8; location / { try_files $uri $uri/ /index.php?$query_string; } location = /favicon.ico { access_log off; log_not_found off; } location = /robots.txt { access_log off; log_not_found off; } error_page 404 /index.php; location ~ \.php$ { fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; include fastcgi_params; } location ~ /\.(?!well-known).* { deny all; } }
Save the file and run the following commands to verify the Nginx syntax and restart Nginx for loading your changes.
Visit http://EC2_PUBLIC_IPADDRESS
So, this was about how to deploy laravel application on AWS EC2. What are you waiting for? Go try these steps and host your application as well! For more such cloud tutorials, feel free to visit the Cloud tutorials page and start learning! Write us back your suggestions and feedback; we’d love to hear from you!
Your Success Is Guaranteed !
We accelerate the release of digital product and guaranteed their success
We Use Slack, Jira & GitHub for Accurate Deployment and Effective Communication.