Free Tier: Install WordPress on an Ubuntu Instance
In this tutorial, use an Oracle Cloud Infrastructure Free Tier account to set up an Ubuntu instance. Next, install an Apache web server, PHP 8, MySQL, and finally WordPress. After installation, access your new WordPress installation from the internet. This tutorial covers all the steps necessary to set up a virtual network, a compute instance, and connect the host to the internet.
Key tasks include how to:
- Set up a compartment for your development work.
- Install an Ubuntu Linux instance and connect it to a Virtual Cloud Network (VCN).
- Set up an Oracle Cloud Infrastructure virtual cloud network and related network services required for a host to connect to the internet.
- Set up
ssh
encryption keys to access the Ubuntu Linux Server.
- Configure ingress rules for a VCN.
- Configure Apache, PHP 8, MySQL, and WordPress on the VM.
- Connect to the instance from the internet.
Here is a simplified diagram of the setup for the Linux VM.
For additional information, see:
Before You Begin
To successfully complete this tutorial, you must have the following:
Requirements
- An Oracle Cloud Infrastructure Free Tier account. Start for free.
- A MacOS, Linux, or Windows computer with
ssh
support installed.
1. Set up a Compartment for Development
Configure a compartment for your development.
Create a compartment for the resources that you create in this tutorial.
- Sign in to the Oracle Cloud Infrastructure Console.
- Open the navigation menu and click Identity & Security. Under Identity, click Compartments.
- Click Create Compartment.
- Fill in the following information:
- Name:
<your-compartment-name>
- Description:
Compartment for <your-description>.
- Parent Compartment:
<your-tenancy>(root)
- Name:
- Click Create Compartment.
Reference: Create a compartment
2. Install an Ubuntu Linux Instance
Use the Create a VM Instance workflow to create a new compute instance.
The workflow does several things when installing the instance:
- Creates and installs a compute instance running Ubuntu Linux.
- Creates a VCN with the required subnet and components needed to connect the Ubuntu Linux instance to the internet.
- Creates an
ssh
key pair you use to connect to the instance.
To get started installing an instance with the Create a VM instance workflow, follow these steps:
The steps provided are for a Free Tier account. If you are using a paid account, the steps might differ from those shown here.
3. Enable Internet Access
The Create a VM Instance workflow automatically creates a VCN for your VM. You add an ingress rule to the subnet to allow internet connections on port 80.
Follow these steps to select the VCN's public subnet and add the ingress rule.
4. Install and Configure Apache, PHP 8, MySQL, and WordPress
Next install and configure Apache web server and PHP to run on the Ubuntu Linux instance.
Connect to the Ubuntu instance and configure the firewall settings. Follow these steps:
- Sign in to your Free Tier account.
- Open the navigation menu and click Compute. Under Compute, click Instances.
- Click the link to the instance you created in the previous step.
From the Instance Access section, write down the Public IP Address the system created for you. You use this IP address to connect to the instance.
- Open a Terminal window.
- Change into the directory where you stored the
ssh
encryption keys you created in part 1. - Connect to the VM with this SSH command.
ssh -i <your-private-key-file> ubuntu@<your-public-ip-address>
Since you identified your public key when you created the VM, this command logs you into the VM. You can now issue
sudo
commands to install and start the server. - Update firewall settings.
Next, update the
iptables
configuration to allow HTTP traffic. To updateiptables
, run the following commands.sudo iptables -I INPUT 6 -m state --state NEW -p tcp --dport 80 -j ACCEPT
sudo netfilter-persistent save
The commands add a rule to allow HTTP traffic and saves the changes to the
iptables
configuration files.
- Install Apache Server.
sudo apt update
sudo apt -y install apache2
- Next start Apache.
sudo systemctl restart apache2
- You can now test the server.
You can test the server from the command line with
curl localhost
. Or, you can connect your browser to the public IP address assigned to the VM: http://<your-public-ip-address>. The page looks similar to:
- Install PHP and then some helpful modules with the following commands.
sudo apt -y install php
sudo apt -y install php-mysql php-curl php-gd php-zip
- Verify installation and restart Apache.
php -v
sudo systemctl restart apache2
- Add a PHP test file to the VM.
sudo vi /var/www/html/info.php
- In the file, input the following text and save the file:
<?php phpinfo(); ?>
- Connect to
http://<your-public-ip-address>/info.php.
The browser produces a listing of the PHP configuration on the VM similar to the following.
Tip
The image will differ due to operating system updates.You have successfully installed Apache and PHP on an Oracle Cloud Infrastructure instance.
Note
After you are done testing, delete theinfo.php
file.
Set up the Apache server to read and write from the /var/www/html
directory.
- Add a username to the
www-data
group so you can edit the/var/www/html
directory.sudo adduser $USER www-data
- Now change the ownership of the content directory.
sudo chown -R www-data:www-data /var/www/html
- Change permissions on the files and directory.
sudo chmod -R g+rw /var/www/html
- Reboot your machine for changes to take effect.
Next, you install and configure the MySQL server and client so it can be used with WordPress.
Because of configuration changes to the Ubuntu MySQL setup, this tutorial adds additional steps before and after the
sudo
mysql_secure_installation
script. The new steps are required for the
mysql_secure_installation
script to complete
successfully.- Install the MySQL Server package.
sudo apt -y install mysql-server
This step can take some time.
- Sign in to MySQL.
sudo mysql
- Change the MySQL
root
user to allow password authentication.mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '<your-password>';
Note
This password is temporary. You reset the root password in the following steps. - Exit MySQL.
mysql> exit
- Secure MySQL with the
mysql_secure_installation
script.- Run the script.
sudo mysql_secure_installation
Produces this output:
Securing the MySQL server deployment.
- You are prompted for the temporary password you set.
Enter password for user root:
Enter the password.
- Turn on Password Validation:
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 set up VALIDATE PASSWORD component? Press y|Y for Yes, any other key for No:
- Select
Y
. - Select the password validation level.
There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG:
- Change the root password.
Using existing password for root. Estimated strength of password: XX Change the password for root ? ((Press y|Y for Yes, any other key for No) :
- Select
Y
. - Set the root password.
New password: Re-enter new password: Estimated strength of the password: 100 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) :
Note
This step replaces the initial temporary password set earlier. - Select
Y
. - Select the remaining security options.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Success. All done!
Tip
Taking the default values,Y
to all options, is recommended.
- Run the script.
- Sign in to MySQL with the new password.
mysql -u root -p
- Change the MySQL authentication method back to
auth_socket
.mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH auth_socket;
Tip
Theauth_socket
authentication method allows you to authenticate withsudo
rather than with a MySQL password. - Exit MySQL.
mysql> exit
- Sign in to MySQL.
sudo mysql
You get a MySQL prompt.
- List the default databases.
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.01 sec)
- Create a user for MySQL.
mysql> CREATE USER '<your-user-name>'@'localhost' IDENTIFIED BY '<your-password>'; Query OK, 0 rows affected (0.01 sec)
- Make the user an admin.
mysql> GRANT ALL PRIVILEGES ON *.* TO '<your-user-name>'@'localhost'; Query OK, 0 rows affected (0.01 sec)
- Create the WordPress database.
mysql> create database wpdb; Query OK, 1 row affected (0.01 sec)
- Check the result.
mysql>show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | | wpdb | +--------------------+ 5 rows in set (0.00 sec)
- Flush privileges to clear cached memory.
mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec) mysql> exit Bye
Download and follow these steps to install WordPress on the server.
- Open a terminal window and create a
tmp
directory. - Download the WordPress Linux zip from
https://wordpress.org/download/
and unzip.wget <url-for-download/filename>.tar.gz
tar xvfz <download-file-name>.tar.gz
The command creates a
wordpress
directory with the PHP code for WordPress in it. - Copy the contents of the
wordpress
directory to the/var/www/html
directory.cp -R /home/<your-username>/tmp/wordpress/* /var/www/html
The contents of the
wordpress
directory are copied into the/var/www/html
directory. This command is a sample. The command might differ depending on the name of your directories. - Change into to the
/var/www/html
directory.cd /var/www/html
- Rename the default
index.html
file.mv index.html index.html.bk
Now
index.php
is loaded by default when the root directory is accessed. - Rename the
wp-config-sample.php
file.mv wp-config-sample.php wp-config.php
- Update the values for the MySQL set up.
vi wp-config.php
- Run the installation script by opening a browser and this URL:
http://<your-public-ip-address>/wp-admin/install.php
Note
Create an administrator account for the WordPress blog. Ensure you write down the information from the install page. You need the information to sign in to the WordPress blog. - Open the new blog at:
http://<your-public-ip-address>
Finish any other configuration you need for WordPress. Here is a link to help.
You have set up a WordPress blog on an OCI compute instance.
What's Next
You have successfully installed and deployed an Apache web server on Oracle Cloud Infrastructure using a Linux instance.
To explore more information about development with Oracle products, check out these sites: