AWS
Deploying a PHP 7.4 + Laravel 6 Project to AWS EC2
Thank you for your continued support.
This article contains advertisements that help fund our operations.
Table Of Contents
オススメ本
This article explains how to deploy a PHP7.4 and Laravel6 project to AWS EC2. Various commands specifying the PHP version are included, making it a useful reference for people using different versions.
Creating and Connecting to EC2
Creating an EC2 Instance
- Access the AWS console.
- Go to the instance screen under the EC2 section.
- Click on "Launch instance" in the top right corner.
- Choose AmazonLinux.
- Select "t2.micro" as it is available in the free tier.
Creating a Security Group in Step 6
- Name the security group.
- Add "HTTP" to the inbound rules.
Creating a Key Pair when Starting up
- Create a key pair with a specified name for SSH connection.
SSH Connection to EC2
- Open terminal.
- Navigate to the folder where the key is saved.
- Change permissions using the command
chmod 400 ????.pem
. - Connect to EC2 using the command
ssh -i "???.pem" ec2-user@????.ap-northeast-1.compute.amazonaws.com
.
Installing PHP7.4
- Install PHP7.4, Apache, and MySQL.
- Use various commands to install PHP7.4 and necessary extensions.
Installing Composer
- Change permissions using
sudo chown ec2-user:ec2-user /var/www/html
. - Visit the Composer official website and follow the instructions to install Composer.
Connecting to GitHub via SSH
- Install Git using
sudo yum install git
. - Create an SSH key for connecting to GitHub.
Setting up Laravel Environment
- Clone the Laravel project.
- Install dependencies and generate a key for the .env file.
Editing Apache Config File
- Edit the Apache config file to point to the Laravel project's public directory.
- Restart Apache for the changes to take effect.
Setting up RDS for Database
- Create an RDS instance in the AWS console.
- Update the .env file with database connection details.
Bonus: Accessing Database on EC2
- Access the database on EC2 using the command
mysql -h <DB instance> -P 3306 -u <username> -p
.
This concludes the deployment of a Laravel project on EC2. Additional steps may be required for projects using Laravel-mix with Vue.js, such as installing Node.js separately.
Please Provide Feedback
We would appreciate your feedback on this article. Feel free to leave a comment on any relevant YouTube video or reach out through the contact form. Thank you!