To install WordPress on an AWS EC2 Ubuntu instance, you first need to launch an EC2 instance running Ubuntu, connect to it via SSH, and then set up a web server stack such as LAMP (Linux, Apache, MySQL, PHP) or LEMP (Linux, Nginx, MySQL, PHP). After installing the necessary packages, you can download WordPress from its official site, configure the database and user in MySQL, update the wp-config.php file with your database credentials, and finally complete the installation through the web browser setup wizard.
Prerequisites
Before you start, ensure you have:
- An AWS account.
- Basic knowledge of Linux commands and the AWS Management Console.
Step 1: Launch an EC2 Instance
1.1 Log In to AWS Management Console
- Visit the AWS Management Console.
- Log in with your credentials.
1.2 Launch a New EC2 Instance
- In the AWS (Amazon Web Services) Management Console, navigate to Services > EC2.
Click on Launch Instance. - Choose an Amazon Machine Image (AMI). Elect Ubuntu Server 20.04 LTS (HVM), SSD (Solid State Drive) Volume Type.
- Choose an instance type. For this tutorial, the t2.micro (free tier eligible) is sufficient.
- Click Next: Configure Instance Details and configure as needed. Defaults are usually fine for a basic setup.
- Click Next: Add Storage and configure the storage. A least of 10 GB is recommended.
- Click Next: Add Tags to add tags (optional).
- Click Next: Configure Security Group. Make a new security group with the following rules:
- HTTP: Port 80 (Anywhere)
- HTTPS: Port 443 (Anywhere)
- SSH: Port 22 (Your IP or Anywhere, but restricting to your IP is more secure)
- Review your configuration and click Launch.
- When prompted, create a new key pair or use an existing one. Download the key pair (a .pem file) and keep it secure.
1.3 Connect to Your Instance
- Open your terminal (or order Prompt in Windows).
- Navigate to the indicative where your key pair .pem file is located.
- Connect to your EC2 instance using SSH:
sh Copy code ssh -i "your-key-pair.pem" ubuntu@your-ec2-public-dns - Accept the SSH fingerprint if prompted.
Step 2: Install LAMP Stack
To run WordPress, you need a web server, database server, and PHP. The LAMP stack (Linux, Apache, MySQL, PHP) is a common choice.
2.1 Update and Upgrade Packages
sh Copy code sudo apt update sudo apt upgrade
2.2 Install Apache
sh Copy code
sudo apt install apache2Verify Apache is running:
sh Copy code
sudo systemctl status apache22.3 Install MySQL
sh Copy code
sudo apt install mysql-serverRun the security script to secure MySQL:
sh Copy code
sudo mysql_secure_installationFollow the prompts to set up your MySQL installation.
2.4 Install PHP
sh Copy code
sudo apt install php libapache2-mod-php php-mysql2.5 Restart Apache
sh Copy code
sudo systemctl restart apache2Step 3: Configure MySQL for WordPress
3.1 Log In to MySQL
sh Copy code
sudo mysql -u root -p3.2 Create a Database and User for WordPress
SQL Copy code CREATE DATABASE wordpress; CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost'; FLUSH PRIVILEGES; EXIT;
Replace password with a hard password of your choice.
Step 4: Install WordPress
4.1 Download WordPress
Navigate to the Apache root directory and download WordPress:
sh Copy code cd /var/www/html sudo wget https://wordpress.org/latest.tar.gz
4.2 Extract WordPress
sh Copy code
sudo tar -xvzf latest.tar.gz4.3 Set Permissions
sh Copy code sudo chown -R www-data:www-data /var/www/html/wordpress sudo chmod -R 755 /var/www/html/wordpress
4.4 Configure Apache for WordPress
Create an Apache configuration file for WordPress:
sh Copy code
sudo nano /etc/apache2/sites-available/wordpress.confAdd the following content:
apache Copy code <VirtualHost *:80> ServerAdmin [email protected] DocumentRoot /var/www/html/wordpress ServerName example.com ServerAlias www.example.com <Directory /var/www/html/wordpress/> Options FollowSymLinks AllowOverride All Require all granted </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
Replace example.com with your domain name. Save and close the file (Ctrl+O, Enter, Ctrl+X).
Enable the new configuration & the rewrite module:
sh Copy code sudo a2ensite wordpress.conf sudo a2enmod rewrite sudo systemctl restart apache2
4.5 Configure WordPress
- Navigate to the WordPress directory:
sh Copy code cd /var/www/html/wordpress - Create a WordPress configuration file from the sample file:
sh Copy code sudo cp wp-config-sample.php wp-config.php - Edit the WordPress configuration file:
sh Copy code sudo nano wp-config.php - Update the database details in wp-config.php:
PHP Copy code define('DB_NAME', 'wordpress'); define('DB_USER', 'wpuser'); define('DB_PASSWORD', 'password'); define('DB_HOST', 'localhost');
- Save and close the file (Ctrl+O, Enter, Ctrl+X).
Step 5: Complete WordPress Installation
5.1 Access WordPress Web Interface
Open your web browser and navigate to http://your-ec2-public-dns. You should follow the WordPress installation page.
5.2 Complete the Setup
- Select your language and click Continue.
- Fill in the site information (site title, username, password, email).
- Click Install WordPress.
Conclusion
You now have a fully functional WordPress site running on an AWS EC2 instance with Ubuntu. This setup provides a robust, scalable, and secure environment for your website. Remember to keep your system updated and secure by regularly applying updates and monitoring your server’s performance. Happy blogging!



