Installing and Running Wordpress on EC2
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 updatesudo apt install apache2sudo systemctl enable apache2Upon 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-zipDownloaded and extracted WordPress
wget https://wordpress.org/latest.tar.gztar -xvzf latest.tar.gzMoved WordPress to the Web Directory
sudo mv wordpress/* /var/www/htmlSet 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 -pConfigured 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.phpUpdate 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 rewritesudo systemctl restart apache2Even 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 -pshow 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