This detailed guide explains how to set up a PrestaShop application on an Amazon EC2 instance while hosting the database separately using Amazon RDS. This configuration ensures compliance with best practices by separating the database server from the application server.
Table of Contents
- Prerequisites
- Create an EC2 Instance
- Connect to the EC2 Instance
- Install and Configure Apache, PHP, and PrestaShop
- Set Up the Database on Amazon RDS
- Finalize PrestaShop Installation
- Testing the Application
- Conclusion
1. Prerequisites
Before you start, ensure that you have:
- An AWS account with Free Tier access.
- An SSH client installed (e.g., OpenSSH or PuTTY).
- Familiarity with basic Linux terminal commands.
2. Create an EC2 Instance
Navigate to the EC2 Dashboard
-
Go to the AWS Management Console:
- Navigate to aws.amazon.com/console.
- Select EC2 from the services menu.
Launch an EC2 Instance
- Click Launch Instance.
- Choose the following configurations:
- AMI: Select Ubuntu 22.04 LTS.
- Instance Type: Choose t3.micro (Free Tier eligible).
-
Configure the Key Pair:
- Select an existing key pair or create a new one.
- Download and securely store the private key file (
.pem
).
-
Configure Security Group:
- Allow SSH (port 22) and HTTP (port 80) from anywhere.
- Click Launch Instance.
-
Name the Instance:
- Assign a meaningful name (e.g., "PrestaShop-Server").
3. Connect to the EC2 Instance
- Retrieve the Public IPv4 Address of your EC2 instance.
- Connect using the Terminal:
ssh -i /path/to/keyfile.pem ubuntu@<EC2-public-IP>
- Update and Upgrade the Instance:
sudo apt update
sudo apt upgrade -y
4. Install and Configure Apache, PHP, and PrestaShop
- Install Apache and PHP:
sudo apt install apache2 php libapache2-mod-php php-mysql php-xml php-curl php-mbstring unzip -y
-
Test Apache Installation:
- Access the public IPv4 address in a browser. You should see the Apache2 default welcome page.
Remove Default Apache Landing Page:
sudo rm /var/www/html/index.html
-
Download and Install PrestaShop:
- Download PrestaShop:
wget https://github.com/PrestaShop/PrestaShop/releases/download/8.1.2/prestashop_8.1.2.zip
-
Install unzip and extract the files:
sudo apt install unzip -y unzip prestashop_8.1.2.zip
-
Move the extracted files to the web directory:
sudo mv * /var/www/html/
-
Set proper ownership and permissions:
sudo chown -R www-data:www-data /var/www/html sudo chmod -R 755 /var/www/html
- Install Required PHP Extensions:
sudo apt install php8.3-gd php8.3-intl php-zip -y
sudo phpenmod gd intl
sudo systemctl restart apache2
- Enable Apache Mod_Rewrite:
sudo a2enmod rewrite
sudo systemctl restart apache2
5. Set Up the Database on Amazon RDS
Navigate to the RDS Dashboard
- Select RDS from the AWS services menu.
- Click Create Database.
Configure the Database
- Choose Standard Create.
- Select MySQL as the engine.
- Set the Database Name (e.g., prestashop-db).
- Choose Free Tier instance size.
- Set a Username and Password for the database.
Enable EC2 Access
-
Modify the RDS security group:
- Add an inbound rule to allow MySQL traffic (port 3306) from the EC2 instance's security group.
Connect to the RDS Instance
- Install the MySQL client on the EC2 instance:
sudo apt install mysql-client -y
- Log in to the RDS instance:
mysql -h <RDS-endpoint> -P 3306 -u <username> -p
- Create the PrestaShop database:
CREATE DATABASE prestashop;
- Exit the MySQL client:
EXIT;
6. Finalize PrestaShop Installation
-
Access the PrestaShop Setup Wizard:
- Open your browser and navigate to the EC2 public IPv4 address.
- Follow the on-screen prompts.
-
Database Configuration:
- Enter the following details:
- Database Server Address: RDS endpoint.
- Database Name: prestashop.
- Database Login: The username you configured for RDS.
- Password: The password for the database.
- Enter the following details:
-
Complete the Installation:
- Follow the remaining steps in the setup wizard.
7. Testing the Application
- Access your PrestaShop site using the EC2 instance's public IPv4 address in a browser.
- Verify that the homepage loads correctly and that the database connection is functional.
Conclusion
By following this guide, you have successfully deployed PrestaShop on an EC2 instance with a secure RDS-hosted database. This setup ensures scalability and security, adhering to AWS Free Tier limits. Your PrestaShop application is successfully deployed and accessible publicly. Visit the site at: http://13.60.199.116/index.php.
Top comments (0)