Here's a step-by-step guide to fix this:
Step-by-Step Guide
Connect to Your EC2 Instance via SSH
Connect to your EC2 instance using SSH. Replace /path/to/your-key.pem with the path to your SSH key, and your-ec2-instance-public-dns with the public DNS of your EC2 instance.
ssh -i /path/to/your-key.pem ubuntu@your-ec2-instance-public-dns
Set Correct Ownership
Ensure that the public directory is owned by the web server user (www-data for Apache on Ubuntu).
sudo chown -R www-data:www-data /var/www/html/your-laravel-project/public
Set Correct Permissions
Adjust the permissions to allow the web server to read and execute files in the public directory.
sudo chmod -R 755 /var/www/html/your-laravel-project/public
Example Commands to Execute
# Connect to your EC2 instance
ssh -i /path/to/your-key.pem ubuntu@your-ec2-instance-public-dns
# Navigate to your project directory
cd /var/www/html/your-laravel-project
# Set correct ownership to www-data
sudo chown -R www-data:www-data public
# Set permissions to 755
sudo chmod -R 755 public
Verify Permissions
To verify the permissions, you can use the ls -ld command:
ls -ld /var/www/html/your-laravel-project/public
The output should look something like this:
drwxr-xr-x 10 www-data www-data 4096 Jun 7 10:00 public
This indicates that the public directory has the correct permissions and is owned by www-data.
0 More Answers