Loading...

How to deploy a Laravel project on AWS free tier

Here’s a step-by-step guide on how to deploy a Laravel project on the AWS Free Tier:

Step 1: Sign up for AWS Free Tier
If you haven’t already, visit the AWS website (https://aws.amazon.com/) and sign up for an AWS Free Tier account. This account provides you with access to a limited set of AWS services for free within specified usage limits.

Step 2: Launch an EC2 Instance

  1. Log in to your AWS Management Console.
  2. Navigate to the EC2 service.
  3. Click on “Launch Instance” to create a new EC2 instance.
  4. Select an Amazon Machine Image (AMI) based on your requirements (preferably a Linux-based one like Amazon Linux 2).
  5. Choose an instance type eligible for the Free Tier, such as t2.micro.
  6. Configure the instance details, including the number of instances, network settings, and storage.
  7. Add any additional tags if necessary.
  8. Configure security groups to allow inbound traffic to your instance. At the very least, open ports 80 (HTTP) and 22 (SSH) to access your Laravel project and for SSH connections.
  9. Review your instance details and click “Launch.” You’ll be prompted to create or select an SSH key pair, which you can use to connect to your EC2 instance.

Step 3: Connect to Your EC2 Instance

  1. Once your EC2 instance is launched, you’ll need to connect to it via SSH.
  2. Use an SSH client (e.g., OpenSSH, PuTTY) to establish a secure connection to your instance.
  3. Download the private key file (.pem) associated with the SSH key pair you selected during instance creation.
  4. Open a terminal or command prompt and navigate to the directory where the private key file is located.
  5. Run the following command to set the permissions for the private key file:
    chmod 400 your_private_key.pem
  6. Connect to your EC2 instance using SSH with the following command:
    ssh -i your_private_key.pem ec2-user@your_instance_public_dns

Step 4: Install Required Software on EC2 Instance

  1. Once you’re connected to your EC2 instance, update the package manager by running the following command:
    sudo yum update -y
  2. Install the required software packages:
  • Install Apache web server:
    sudo yum install httpd -y
  • Install PHP:
    sudo yum install php -y
  • Install Composer (for Laravel):
    sudo php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
  • Install additional PHP extensions required by Laravel:
    sudo yum install php-mbstring php-xml php-zip php-json -y sudo systemctl restart httpd

Step 5: Configure Apache for Laravel

  1. Update the Apache configuration file:
    sudo nano /etc/httpd/conf/httpd.conf
  2. Look for the <Directory "/var/www/html"> block and update it as follows:
   <Directory "/var/www/html">
       AllowOverride All
   </Directory>
  1. Save the file and exit the text editor.
  2. Restart the Apache service:
    sudo systemctl restart httpd

Step 6: Deploy Your Laravel Project

  1. Navigate to the Apache web server document root directory:
    cd /var/www/html
  2. Clone or upload your Laravel project to this directory. You can use git to clone your project or transfer the files

1 Comment

Digital Transformation - How To Overcome Common Challenges - AI Blog Articles October 28, 2024

[…] For more insights on leveraging technology in your projects, check out how to deploy a Laravel project on AWS Free Tier. […]

Top