Set up WordPress on Single instance EC2 in Ubuntu

  1. If you do not have a server, you may check out Setup EC2 with Instance Connect ( or (
  2. Install PHP 8.1 on Ubuntu.

Update OS

sudo su -
apt -y update
apt -y upgrade

Install Apache, PHP, MySQL

apt -y install apache2 php8.1
apt -y install mysql-server
mysql -uroot
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'P@ssw0rd';
flush privileges; 
Securing the MySQL server deployment.

Enter password for user root: P@ssw0rd  (For security reason, you do not see any * when you typed.)

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: N
Using existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other key for No) : N

 ... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y

Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...

 - Removing privileges on test database...

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y

All done! 

Install PHP and library

apt -y install php8.1 php8.1-mysql
apt -y install php8.1-curl php8.1-mbstring
sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 200M/g' /etc/php/8.1/cli/php.ini
sed -i 's/post_max_size = 8M/post_max_size = 200M/g' /etc/php/8.1/cli/php.ini
sed -i 's/max_file_uploads = 20/max_file_uploads = 200/g' /etc/php/8.1/cli/php.ini
service apache2 restart


vi /var/www/html/phpinfo.php

On your keyboard type i to change to insert mode. Type the following PHP code.


Press “Esc” key, then type “:wq” -> enter

Open browser and check your PHP. “http://your-ip-address/phpinfo.php”

Setup Database

mysql -uroot -p

Type your MySQL password

create database wordpress;
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost';

Install WordPress

tar zxvf wordpress-6.0.tar.gz
mv wordpress /var/www/html
chown -R www-data.www-data /var/www/html
chmod -R 755 /var/www/html

Setup WordPress

In your browser, open URL


Setup your admin user and password.

All done!

WordPress Admin page


, , ,