Here you can check details with screenshot : Check here The objective of this blog is to guide readers in setting up a WordPress website using the LAMP stack on an Amazon EC2 instance.
By the end of this tutorial, you will have learned how to:
→ LAMP Stack: Set up the foundational LAMP (Linux, Apache, MySQL, PHP) stack on your EC2 instance.
→ WordPress Installation: Install and configure WordPress on your EC2 server.
→ Security Measures: Implement essential security measures to protect your WordPress site.
→ Domain Connection: Point your domain name to your EC2 instance for public access.
Step 1: Launch an Amazon EC2 Instance
→ Navigate to the EC2 dashboard.
→ Click “Launch Instance” to start the EC2 instance creation process.
→ Select an Amazon Machine Image (AMI) for your instance, such as “Amazon Linux 2 or base on your requirement.”
→ Choose an instance type based on your requirements.
→ Choose or create an SSH key pair to access your instance securely.
→ Configure instance details like network settings, storage, and tags.
→ Create or select an existing security group allowing inbound traffic on ports 80 (HTTP) and 443 (HTTPS).
→ Review your instance settings and click “Launch.”
→ Click “Launch Instances.”
Step 2: Connect to Your EC2 Instance
→ Once your instance is running, select it in the EC2 dashboard.
→ Click “Connect” to view connection instructions for the SSH client. You can use third-party software such as PuTTY, Git Bash, Manage Desktop, or any terminal application on your operating system to connect using the instructions provided.
→ The EC2 Instance Connect option allows you to directly connect via a new tab for SSH access.
→ Use an SSH client to connect to your instance using the provided public DNS and private key (.pem) file.
Step 2: Update Your System
→ Once connected to your EC2 instance via SSH, update the system to ensure all packages are up to date:
→ “ sudo dnf update -y ”
Step 3: Install Apache, PHP, and MariaDB
1. Install the required software packages:
“ sudo dnf install -y httpd wget php-fpm php-mysqli php-json php php-devel ”
“ sudo dnf install -y mariadb105-server ”
2. Check the MariaDB version:
“ dnf info mariadb105 ”
Step 4: Start and Configure Apache
1. Start the Apache web server and enable it to start on boot:“ sudo systemctl start httpd && sudo systemctl enable httpd ”
2. Verify if Apache is enabled:“ sudo systemctl is-enabled httpd ”
3. Add your user (e.g., ec2-user) to the Apache group: “ sudo usermod -a -G apache ec2-user ”
4. Log out and log back in to refresh your groups: “exit
groups ”
Step 5: Configure Permissions
1. Adjust the permissions for the web directory: “sudo chown -R ec2-user:apache /var/www
sudo chmod 2775 /var/www && find /var/www -type d -exec sudo chmod 2775 {} \;
find /var/www -type f -exec sudo chmod 0664 {} \; ” 2. Test PHP installation:
“ echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php ”
Step 6: Install and Start MariaDB
1. Start the MariaDB service:
“ sudo systemctl start mariadb ”
2. Secure the installation: “ sudo mysql_secure_installation ”
3. Follow the prompts to remove anonymous users, disable remote root login, remove the test database, and reload privilege tables.
Step 7: Install WordPress
tar -xzf latest.tar.gz ”
2. Start Apache and MariaDB services:
“ sudo systemctl start mariadb httpd ”
Step 8: Create a Database for WordPress
1. Access MySQL as the root user:
“ mysql -u root -p ”
2. Create a new database and user for WordPress:
“ CREATE DATABASE wordpress-db;
CREATE USER 'wordpress-user'@'localhost' IDENTIFIED BY 'your_strong_password'; GRANT ALL PRIVILEGES ON `wordpress-db`.* TO "wordpress-user"@"localhost"; FLUSH PRIVILEGES;
exit; ”
Step 9: Configure WordPress
1. Copy the sample WordPress configuration file:
“ cp wordpress/wp-config-sample.php wordpress/wp-config.php ”
2. Edit the configuration file:
“ nano wordpress/wp-config.php ”
3. Update the database details:
“ define('DB_NAME', 'wordpress-db');
define('DB_USER', 'wordpress-user');
define('DB_PASSWORD', 'your_strong_password'); ”
Step 10: Deploy WordPress
1. WordPress files to the web directory: “cp -r wordpress/* /var/www/html/ ”
2. If installing WordPress in a subdirectory: “ mkdir /var/www/html/blog
cp -r wordpress/* /var/www/html/blog/ ”
Step 11: Configure Apache
1. Edit the Apache configuration file:
“ sudo nano /etc/httpd/conf/httpd.conf ”
2. Adjust <Directory> settings:
“ AllowOverride All ”
3. Restart Apache:
“ sudo systemctl restart httpd ”
Step 12: Finalize the Installation
2. Complete the WordPress setup process through the web interface.
→ Congratulations! You have successfully installed WordPress on your Amazon EC2 instance using the Amazon Linux AMI.
Step 13: Point Your Domain to EC2
1. Log in to your domain registrar’s control panel.
2. Create an A record pointing to your EC2 public IP address.
3. Optionally, set up a CNAME record for the www subdomain.
Step 14: Server Configuration and Pricing
Configuration:
→ RAM: WordPress requires at least 512 MB of RAM, but 1 GB is recommended for basic functionality and 2 GB or more for optimal performance
→ Processor (CPU): WordPress requires a minimum processor of 1 GHz, one core, and one thread.
→ Storage space: The amount of storage space you need depends on how you use your site. For example, 1 GB may be enough for a simple website with a few images.
Pricing:
Configuration:
- RAM: 1 GB minimum recommended, 2 GB for optimal performance.
- Processor (CPU): At least 1 GHz, one core, one thread.
- Storage: Minimum 1 GB for a basic site.
Pricing:
- T2 Small: ~$16.79–$22.19/month (varies by region).
- T3 Small: ~$15.18–$22.19/month (varies by region).
Step 15: Common Issues and Resolutions
Issue 1: Site Not Loading Cause: Security group does not allow HTTP/HTTPS. Resolution: Update the security group to allow inbound traffic on ports 80 and 443.
Issue 2: Database Connection Error Cause: Incorrect database credentials or MySQL service not running. Resolution:
- Verify wp-config.php for correct credentials.
- Restart MySQL: sudo systemctl restart mysqld.
Issue 3: Permission Denied Cause: Incorrect file permissions. Resolution:
sudo chown -R apache:apache /var/www/html
sudo chmod -R 755 /var/www/html
Issue 4: SSL Certificate Missing Cause: No HTTPS configured. Resolution: Install Certbot:
sudo yum install certbot python3-certbot-apache -y
sudo certbot --apache