Running a WordPress website on AWS EC2 gives you full control over your hosting environment. When combined with Ubuntu 24.04, it creates a reliable and scalable setup that can handle everything from small blogs to high-traffic business websites.
If you are just getting started, setting up WordPress on a new EC2 instance is one of the most efficient ways to create a custom hosting solution. For those who already have a website, migrating your WordPress site from an older host or server ensures better performance, improved security, and more flexibility in the long run.
This guide walks you through both approaches. First, you will learn how to launch a brand-new WordPress site from scratch. Then, we will cover how to safely migrate an existing WordPress website to a new AWS EC2 instance running Ubuntu 24.04.
Prerequisites: Migrate a WordPress Website to AWS EC2 Ubuntu Server 24.04
Before you begin setting up or migrating your WordPress website to AWS EC2 with Ubuntu 24.04, make sure you have everything you need in place. This will help you follow the steps smoothly and avoid delays during the process.
Here is what you should have ready:
- An active AWS account with access to the EC2 service
- A secure key pair to connect to your server using SSH
- Basic knowledge of the Linux command line
- A domain name (optional but helpful for testing and SSL setup)
- A complete backup of your existing WordPress site if you plan to migrate
- A stable internet connection for transferring files between servers
Once these items are ready, you can move forward confidently with either the new setup or the migration process.
Need Help Migrating Your WordPress Website to AWS?
We handle secure WordPress migrations with zero downtime, optimized server configurations, and complete peace of mind.
Set Up WordPress from Scratch with LAMP Stack on Ubuntu 24.04

If you are starting fresh, installing WordPress on an AWS EC2 instance with the LAMP stack is one of the most straightforward ways to get your website online. The LAMP stack includes Linux, Apache, MySQL, and PHP, which together provide a stable environment for WordPress.
Step 1: Launch a New EC2 Instance
Log in to your AWS Management Console and go to the EC2 Dashboard. Click on the Launch Instance button.
Choose the Ubuntu Server 24.04 LTS as your machine image. Select an instance type based on your needs. For small projects, the t2.micro instance is suitable and eligible for the AWS Free Tier.
During configuration, enable auto-assign public IP and create a new key pair if you do not already have one. Allow SSH, HTTP, and HTTPS in the security group rules. Finally, launch the instance and note its public IP address.
Step 2: Connect to the Server via SSH
Open your terminal or SSH client. Use the command below to connect, replacing the placeholders with your actual key file path and EC2 public IP.
ssh -i /path/to/your-key.pem ubuntu@your-ec2-ip
Make sure your key file has the correct permissions. If needed, run this command before connecting:
chmod 400 your-key.pem
Step 3: Update and Install Apache Web Server
Once logged in, update the server and install Apache with the following commands:
sudo apt update
sudo apt install apache2 -y
After installation, make sure Apache is running:
sudo systemctl enable apache2
sudo systemctl start apache2
Visit your EC2 public IP address in a browser. If Apache is running, you will see the default Ubuntu web page.
Step 4: Install MySQL and Create the WordPress Database
Install MySQL Server:
sudo apt install mysql-server -y
Secure the MySQL installation by running:
sudo mysql_secure_installation
Next, log in to MySQL to create the database and user for WordPress:
sudo mysql
Inside the MySQL prompt, run:
CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'yourpassword';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Step 5: Install PHP and Required Extensions
WordPress needs PHP to run, along with several extensions. Install everything using:
sudo apt install php libapache2-mod-php php-mysql php-curl php-gd php-mbstring php-xml
You can confirm the PHP version installed by running:
php -v
Restart Apache to load the PHP module:
sudo systemctl restart apache2
Step 6: Download and Configure WordPress
Go to your temporary directory and download WordPress:
cd /tmp
curl -O https://wordpress.org/latest.tar.gz
tar xzvf latest.tar.gz
Create the configuration file:
cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php
Copy the WordPress files to the web root:
sudo cp -a /tmp/wordpress/. /var/www/html
Set the proper permissions:
sudo chown -R www-data:www-data /var/www/html
sudo find /var/www/html -type d -exec chmod 750 {} \;
sudo find /var/www/html -type f -exec chmod 640 {} \;
Step 7: Configure Apache Virtual Host
Create a new Apache configuration file for your site:
sudo nano /etc/apache2/sites-available/wordpress.conf
Paste the following configuration:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
<Directory /var/www/html/>
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Enable the site and necessary modules:
sudo a2ensite wordpress.conf
sudo a2enmod rewrite
sudo a2dissite 000-default.conf
sudo apache2ctl configtest
sudo systemctl restart apache2
Step 8: Complete the WordPress Installation
Open your browser and visit your EC2 public IP or domain name. You should see the WordPress setup screen.
Choose your language, site title, admin username, and password. Enter your email address and decide whether to discourage search engines.
Once you click Install WordPress, you will be taken to the login page. Use the credentials you just created to log in and start customizing your website.
Migrate an Existing WordPress Site to AWS EC2 with Nginx and SCP
If you already have a WordPress website running on another server, you can move it to a new EC2 instance using a secure and efficient method. This part of the guide shows you how to migrate your files and database using SCP and configure Nginx on your Ubuntu 24.04 server.
Step 1: Prepare Your New EC2 Instance
Start by launching a new EC2 instance with Ubuntu 24.04, just like you would for a fresh setup. Once the server is up, install the following packages:
sudo apt update
sudo apt install nginx mysql-server php-fpm php-mysql -y
Enable and start the services:
sudo systemctl enable nginx mysql php8.1-fpm
sudo systemctl start nginx mysql php8.1-fpm
Step 2: Set Up SSH Access Between Servers
To copy files directly between servers, you need to establish a secure connection.
On your new EC2 instance, generate a new SSH key:
ssh-keygen -t ed25519 -C "wordpress_migration"
Display your public key:
cat ~/.ssh/id_ed25519.pub
Now, log in to your old server and add this key to its authorized keys file:
nano ~/.ssh/authorized_keys
Paste the key and save. This allows the new server to connect securely.
Step 3: Transfer Website Files Using SCP
Back on your EC2 server, copy the WordPress files from the old server:
scp -r user@oldserver:/var/www/html /home/ubuntu/html_backup
Move the files into place and adjust permissions:
sudo mv /home/ubuntu/html_backup /var/www/yourdomain.com
sudo chown -R www-data:www-data /var/www/yourdomain.com
Step 4: Create MySQL Database and Import the Data
On your EC2 server, log into MySQL:
sudo mysql
Create a database and user:
CREATE DATABASE wordpress CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci;
CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Export the database from the old server:
mysqldump -u db_user -p db_name > export.sql
Transfer it to the EC2 instance:
scp export.sql ubuntu@ec2-ip:/home/ubuntu/
Import it into the new database:
mysql -u wordpressuser -p wordpress < /home/ubuntu/export.sql
Step 5: Configure Nginx for the Migrated Site
Create a new Nginx configuration file:
sudo nano /etc/nginx/sites-available/yourdomain.com
Add the following configuration:
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
root /var/www/yourdomain.com;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
Enable the site and reload Nginx:
sudo ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
Step 6: Test the Site with Local DNS
Before updating the DNS for the world, you can test your new server using your local machine. Edit your hosts
file:
On Mac or Linux:
sudo nano /etc/hosts
Add the following line:
EC2_PUBLIC_IP yourdomain.com
Now, when you open your site in a browser, it will load from the new EC2 server, while visitors will still see the live site from the old server.
Step 7: Set Up SSL with Let’s Encrypt
Once DNS is switched and your domain points to the new EC2 server, install Certbot to enable HTTPS:
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
Certbot will configure SSL and renew certificates automatically.
Step 8: Final Database Sync and DNS Switch
To avoid losing any recent data, perform one final database export and import before switching DNS.
On the old server, export the database again:
mysqldump -u db_user -p db_name > latest.sql
Transfer it to the EC2 server:
scp latest.sql ubuntu@ec2-ip:/home/ubuntu/
Import it:
mysql -u wordpressuser -p wordpress < /home/ubuntu/latest.sql
Now update your DNS A record to point to your EC2 instance’s public IP. DNS changes can take a few minutes to a few hours to propagate.
Conclusion: Launch, Migrate, and Grow with AWS EC2
Setting up or migrating a WordPress website to AWS EC2 with Ubuntu 24.04 gives you greater control, stronger performance, and room to grow. Whether you chose the LAMP-based fresh installation or migrated from an old server using Nginx and SCP, you now have a powerful setup ready to support your site’s future.
With your WordPress site running on EC2, you benefit from flexible scaling, fast response times, and full ownership of your server environment. As traffic grows or requirements change, you can upgrade your instance type, set up automatic backups, or even connect with additional AWS services like CloudFront or Route 53.
Remember to keep your server updated, monitor performance regularly, and renew your SSL certificates when needed. With this foundation in place, you are ready to build a secure and professional online presence that can handle whatever comes next.