top of page

Installing and Running Wordpress on EC2

Writer: Eunho Park
Eunho Park
Jul 25, 2024
2 min read

With the assistance of ChatGPT, I successfully set up my initial LAMP stack.


Today, I established a WordPress website utilizing the LAMP stack on AWS.


I launched an Ubuntu instance, generated an RSA key pair, and configured it to permit SSH, HTTP, and HTTPS access.


After it was up and running, I successfully accessed the instance via SSH from my terminal.


 ssh -i 'myKeyFile' ubuntu@myInstancePublicIp.


I had to try a few times because I was unaware that I should use "ubuntu" as the user instead of ec2-user when I am accessing ubuntu instance.


After that, I updated the package manager.

sudo apt update
sudo apt install apache2
sudo systemctl enable apache2

Upon accessing my IP address, I was able to view the default web page.


Desiring to set up WordPress on the web server, I proceeded to install the remaining components of the stack.


sudo apt install apache2 mysql-server php libapache2-mod-php php-mysql php-cli php-curl php-gd php-mbstring php-xml php-xmlrpc php-zip

Downloaded and extracted WordPress

wget https://wordpress.org/latest.tar.gz
tar -xvzf latest.tar.gz

Moved WordPress to the Web Directory


sudo mv wordpress/* /var/www/html

Set up permissions for WordPress files


sudo chown -R www-data:www-data /var/www/html/
sudo chmod -R 755 /var/www/html/

Created MySQL database for WordPress


sudo mysql -u root -p

Configured MySQL


CREATE DATABASE wordpress;
CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Configure WordPress

Rename the sample configuration file and edit it:


cd /var/www/html/ sudo cp wp-config-sample.php wp-config.php sudo nano wp-config.php

Update the database information in the wp-config.php file:

// ** MySQL settings ** //
define( 'DB_NAME', 'wordpress' );
define( 'DB_USER', 'wordpressuser' );
define( 'DB_PASSWORD', 'password' );
define( 'DB_HOST', 'localhost' );
define( 'DB_CHARSET', 'utf8' );
define( 'DB_COLLATE', '' );

Enable the Apache rewrite module and restart Apache:

sudo a2enmod rewrite
sudo systemctl restart apache2

Even after restarting Apache and refreshing my browser, I still saw the default page instead of the WordPress installation. It wasn't until I renamed the index.html file in the /var/www/html directory that I was able to complete the WordPress installation.


Below is a screenshot of the WordPress webpage now working properly.


It sparked my curiosity about the storage of data in the MySQL database.


I chose to delve deeper into the database.


sudo mysql -u root -p

show databases;

use wordpress;

show tables;


select * from wp_comments;



Below is the actual comment,


Here I tried to delete data from database and see if this gets reflected on the actual wordpress website.


delete from wp_comments where comment_ID=1;

It is now gone from the database


and also gone on the webpage



Success!


Even though I got a lot of help from chatGpt, it feels pretty good to see things working as they should. I learned a bunch of new stuff from this demo, like the Linux folder structure and where to find config files. Also, got a refresher on playing around with data in a MySQL database and using AWS Cli. Can't wait for my next learning adventure! Now, it's time to grab a beer.


Goodnight everyone!

Comments


  • Linkedin
  • Instagram

The RNIT

© 2035 by Inner Pieces.

Powered and secured by Wix

Contact

Ask me anything

Thanks for submitting!

bottom of page