๐ Host Free Wordpress in EC2 with free tier AWS
This tutorial will guide you through setting up a WordPress site on an AWS EC2 instance using the AWS Free Tier. By the end of this tutorial, you will have a fully functional WordPress site accessible via the internet.
1 Connect to EC2 Instance
Use SSH to connect to your instance:
chmod 400 your-key.pem ssh -i /path/to/your-key.pem ubuntu@your-ec2-public-ip
2 Update and Upgrade Packages
sudo apt update sudo apt upgrade
3. Install PHP, MariaDB and Nginx
sudo apt install nginx mariadb-server php-fpm php-mysql
4. Install WordPress
cd /var/www sudo wget https://wordpress.org/latest.tar.gz sudo tar -xzvf latest.tar.gz sudo rm latest.tar.gz sudo chown -R www-data:www-data wordpress sudo find wordpress/ -type d -exec chmod 755 {} \; sudo find wordpress/ -type f -exec chmod 644 {} \;
5. Configure MySQL for WordPress
sudo mysql_secure_installation sudo mysql -u root -p
create database example_db default character set utf8 collate utf8_unicode_ci; create user 'example_user'@'localhost' identified by 'example_pw'; grant all privileges on example_db.* TO 'example_user'@'localhost'; flush privileges; exit
6. Configure Nginx Web Server
cd /etc/nginx/sites-available/ sudo vim wordpress.conf
upstream php-handler { server unix:/var/run/php/php7.4-fpm.sock; } server { listen 80; server_name your_domain www.your_domain; root /var/www/wordpress; index index.php; location / { try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass php-handler; } }
sudo ln -s /etc/nginx/sites-available/wordpress.conf /etc/nginx/sites-enabled/ sudo nginx -t sudo systemctl restart nginx
7. Access WordPress Installation
Open your web browser and navigate to your EC2 instance's public IP address. Complete the WordPress installation steps using the database credentials set up earlier.
8. Install PHP Packages Required by WordPress
sudo apt install php-curl php-dom php-mbstring php-imagick php-zip php-gd
9. Install an SSL Certificate for HTTPS
sudo apt install snapd sudo snap install core; snap refresh core sudo snap install --classic certbot sudo ln -s /snap/bin/certbot /usr/bin/certbot sudo certbot --nginx
10. Link Domain name (Optional)
If you have a domain name, you can link it to your EC2 instance by creating a DNS record.
Go to your registrar and find the DNS settings of your domain name. Create an A record that points to the IP address of your EC2 instance and another A record for the www version of your website that points to the same IP address of your EC2 instance.