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
- Log in to your AWS Management Console.
- Navigate to the EC2 service.
- Click on “Launch Instance” to create a new EC2 instance.
- Select an Amazon Machine Image (AMI) based on your requirements (preferably a Linux-based one like Amazon Linux 2).
- Choose an instance type eligible for the Free Tier, such as t2.micro.
- Configure the instance details, including the number of instances, network settings, and storage.
- Add any additional tags if necessary.
- 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.
- 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
- Once your EC2 instance is launched, you’ll need to connect to it via SSH.
- Use an SSH client (e.g., OpenSSH, PuTTY) to establish a secure connection to your instance.
- Download the private key file (.pem) associated with the SSH key pair you selected during instance creation.
- Open a terminal or command prompt and navigate to the directory where the private key file is located.
- Run the following command to set the permissions for the private key file:
chmod 400 your_private_key.pem
- 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
- Once you’re connected to your EC2 instance, update the package manager by running the following command:
sudo yum update -y
- 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
- Update the Apache configuration file:
sudo nano /etc/httpd/conf/httpd.conf
- Look for the
<Directory "/var/www/html">
block and update it as follows:
<Directory "/var/www/html">
AllowOverride All
</Directory>
- Save the file and exit the text editor.
- Restart the Apache service:
sudo systemctl restart httpd
Step 6: Deploy Your Laravel Project
- Navigate to the Apache web server document root directory:
cd /var/www/html
- Clone or upload your Laravel project to this directory. You can use
git
to clone your project or transfer the files
[…] For more insights on leveraging technology in your projects, check out how to deploy a Laravel project on AWS Free Tier. […]