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.

A diagram of the components needed to run a Apache webserver on Oracle Cloud Infrastructure

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

Create a compartment for the resources that you create in this tutorial.

  1. Sign in to the Oracle Cloud Infrastructure Console.
  2. Open the navigation menu and click Identity & Security. Under Identity, click Compartments.
  3. Click Create Compartment.
  4. Fill in the following information:
    • Name: <your-compartment-name>
    • Description: Compartment for <your-description>.
    • Parent Compartment: <your-tenancy>(root)
  5. 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.
Review Installation Steps

To get started installing an instance with the Create a VM instance workflow, follow these steps:

Important

The steps provided are for a Free Tier account. If you are using a paid account, the steps might differ from those shown here.
  1. Click the Oracle Cloud icon to go to the main landing page.
    • Scroll down to Launch Resources.
    • Select Create a VM instance workflow.
    The Create compute instance page is displayed. The page sections include
    • Name and Compartment
    • Placement
    • Security
    • Image and shape
    • Networking
    • Add SSH keys
    • Boot volume
  2. Choose the Name and Compartment.

    Initial Options

    • Name: <name-for-the-instance>
    • Create in compartment: <your-compartment-name>

    Enter a value for the name or use the system supplied default. For compartment, select the compartment you created.

  3. Review the Placement settings.
    • Take the default values. An availability domain is assigned to you.

    The data might look similar to the following:

    Availability domain

    • Availability domain: AD-1
    • Capacity type: On-demand capacity
    • Fault domain: Let Oracle choose the best fault domain
    Note

    For Free Tier, use the Always Free Eligible option for availability domain.
  4. Review the Security settings.
    • Take the default settings.

    The data might look similar to the following:

    Security

    • Shielded instance: Disabled
    • Confidential computing: Disabled
  5. Review the Image and shape settings. Change the operating system image.
    • Click Edit.
    • Click Change Image.
    • Click Ubuntu.
    • Select Canonical Ubuntu 22.04 or a later version.
    • Click Select Image.
    Note

    The following is sample data for an AMD virtual machine. The actual values might differ.

    Image and shape

    • Image: Canonical Ubuntu 22.04
    • Image build: <current-build-date>
    • Shape: VM.Standard.E2.1.Micro
    • OCPU: 1
    • Memory (GB): 1
    • Network bandwidth (Gbps): 0.48
    Note

    For Free Tier, use Always Free Eligible shape options.
    • Continue to the next section.
  6. Review the Networking settings. Make the following changes to the default.
    • Click Edit.
    • Primary Network: Select Create new virtual cloud network.
    • New virtual cloud network name: Take the generated VCN name or provide a name.
    • Create in compartment: <your-compartment-name>.
    • Subnet: Select Create new public subnet.
    • New subnet name: Take the generated subnet name or provide a name.
    • Create in compartment: <your-compartment-name>.
    • CIDR block: Take the default value (for example, 10.0.0.0/24).
    • Public IPv4 address, take the default value of Assign a public IPv4 address.
    • Continue to the next section.
  7. Review the Add SSH keys settings. Take the default values provided by the workflow.
    • Select the Generate a key pair for me option.
    • Click Save Private Key and Save Public Key to save the private and public SSH keys for this compute instance.

    If you want to use your own SSH keys, select one of the options to provide your public key.

    Note

    Put your private and public key files in a safe location. You can't retrieve keys again after the compute instance has been created.
  8. Review the Boot volume settings.

    Uncheck the Specify a customer boot volume size setting.

    Check the Use in-transit encryption setting.

    Uncheck the Encrypt this volume with a key that you manage setting.

  9. Click Create to create the instance. Provisioning the system might take several minutes.
You have successfully created an Ubuntu Linux instance.

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.

Create an Ingress Rule for the VCN

Follow these steps to select the VCN's public subnet and add the ingress rule.

  1. Open the navigation menu and click Networking, and then click Virtual Cloud Networks.
  2. Select the VCN you created with the compute instance.
  3. With the new VCN displayed, click <your-subnet-name> subnet link.

    The public subnet information is displayed with the Security Lists at the bottom of the page. A link to the Default Security List for the VCN is displayed.

  4. Click the Default Security List link.

    The default Ingress Rules for the VCN are displayed.

  5. Click Add Ingress Rules.

    An Add Ingress Rules dialog is displayed.

  6. Fill in the ingress rule with the following information.

    Fill in the ingress rule as follows:

    • Stateless: Checked
    • Source Type: CIDR
    • Source CIDR: 0.0.0.0/0
    • IP Protocol: TCP
    • Source port range: (leave-blank)
    • Destination Port Range: 80
    • Description: Allow HTTP connections
  7. Click Add Ingress Rules.
    Now HTTP connections are allowed. The VCN is configured for HTTP traffic on port 80.
You have successfully created an ingress rule that makes the instance available on port 80 from the internet.

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.

Configure the Ubuntu Firewall

Connect to the Ubuntu instance and configure the firewall settings. Follow these steps:

  1. Sign in to your Free Tier account.
  2. Open the navigation menu and click Compute. Under Compute, click Instances.
  3. 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.

  4. Open a Terminal window.
  5. Change into the directory where you stored the ssh encryption keys you created in part 1.
  6. 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.

  7. Update firewall settings.

    Next, update the iptables configuration to allow HTTP traffic. To update iptables, 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
  1. Install Apache Server.
    sudo apt update
    sudo apt -y install apache2
  2. Next start Apache.
    sudo systemctl restart apache2
  3. 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: Apache Server Test Page

Install PHP
  1. 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
  2. Verify installation and restart Apache.
    php -v
    sudo systemctl restart apache2
  3. Add a PHP test file to the VM.
    sudo vi /var/www/html/info.php
  4. In the file, input the following text and save the file:
    <?php
    phpinfo();
    ?>
  5. 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.
    PHP configuration Page

    You have successfully installed Apache and PHP on an Oracle Cloud Infrastructure instance.

    Note

    After you are done testing, delete the info.php file.
Configure Apache HTML Directory

Set up the Apache server to read and write from the /var/www/html directory.

  1. Add a username to the www-data group so you can edit the /var/www/html directory.
    sudo adduser $USER www-data
  2. Now change the ownership of the content directory.
    sudo chown -R www-data:www-data /var/www/html
  3. Change permissions on the files and directory.
    sudo chmod -R g+rw /var/www/html
  4. Reboot your machine for changes to take effect.
Install and Configure MySQL Server and Client

Next, you install and configure the MySQL server and client so it can be used with WordPress.

Important

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.
  1. Install the MySQL Server package.
    sudo apt -y install mysql-server

    This step can take some time.

  2. Sign in to MySQL.
    sudo mysql
  3. 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.
  4. Exit MySQL.
    mysql> exit
  5. Secure MySQL with the mysql_secure_installation script.
    1. Run the script.
      sudo mysql_secure_installation

      Produces this output:

      Securing the MySQL server deployment.
    2. You are prompted for the temporary password you set.
      Enter password for user root:

      Enter the password.

    3. 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:    
                          
    4. Select Y.
    5. 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:                        
                          
    6. 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) :                            
    7. Select Y.
    8. 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.
    9. Select Y.
    10. 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.
  6. Sign in to MySQL with the new password.
    mysql -u root -p
  7. Change the MySQL authentication method back to auth_socket.
    mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH auth_socket;
    Tip

    The auth_socket authentication method allows you to authenticate with sudo rather than with a MySQL password.
  8. Exit MySQL.
    mysql> exit
Set up WordPress MySQL Database
  1. Sign in to MySQL.
    sudo mysql

    You get a MySQL prompt.

  2. List the default databases.
    mysql> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    | sys                |
    +--------------------+
    4 rows in set (0.01 sec)
                        
  3. Create a user for MySQL.
    mysql> CREATE USER '<your-user-name>'@'localhost' IDENTIFIED BY '<your-password>';
    Query OK, 0 rows affected (0.01 sec)
  4. Make the user an admin.
    mysql> GRANT ALL PRIVILEGES ON *.* TO '<your-user-name>'@'localhost';
    Query OK, 0 rows affected (0.01 sec)
                        
  5. Create the WordPress database.
    mysql> create database wpdb;
    Query OK, 1 row affected (0.01 sec)
                        
  6. Check the result.
    mysql>show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    | sys                |
    | wpdb               |
    +--------------------+
    5 rows in set (0.00 sec)
  7. Flush privileges to clear cached memory.
    mysql> FLUSH PRIVILEGES;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> exit
    Bye
Install and Configure WordPress

Download and follow these steps to install WordPress on the server.

  1. Open a terminal window and create a tmp directory.
  2. 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.

  3. 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.

  4. Change into to the /var/www/html directory.
    cd /var/www/html
  5. 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.

  6. Rename the wp-config-sample.php file.
    mv wp-config-sample.php wp-config.php
  7. Update the values for the MySQL set up.
    vi wp-config.php
  8. 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.
  9. 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: