title | parent | toc | tags | categories | thumbnail | date | description | author | draft | slug | ||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Free Tier: Install WordPress on an Ubuntu Instance |
|
true |
|
|
assets/modernize-healthcare-ambulance.jpeg |
2021-11-24 9:45 |
This tutorial guides you through configuring WordPress on your Ubuntu OCI instance. |
|
true |
freetier-wordpress-ubuntu |
{% slides %} In this tutorial, use an Oracle Cloud Infrastructure Free Tier account to set up an Ubuntu instance. Next, install an Apache web server, PHP 7, 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 your Ubuntu Linux instance and connect it to your Virtual Cloud Network (VCN).
- Set up an Oracle Cloud Infrastructure virtual cloud network and related network services required for your host to connect to the internet.
- Set up
ssh
encryption keys to access your Ubuntu Linux Server.
- Configure ingress rules for your VCN.
- Configure Apache, PHP 7, MySQL, and WordPress on your VM.
- Connect to your instance from the internet.
Here's a simplified diagram of the setup for your Linux VM.
{% imgx assets/wordpress-apache-diagram.png "OCI Apache network diagram" %}
For additional information, see:
To successfully complete this tutorial, you must have the following:
- An Oracle Cloud Infrastructure Free Tier account. Start for Free.
- A MacOS, Linux, or Windows computer with
ssh
support installed.
Configure a compartment for your development.
Create a compartment for the resources that you create in this tutorial.
- Log 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:
- Description: Compartment for .
- Parent Compartment: (root)
- Click Create Compartment.
Reference: Create a compartment
Use the Create a VM Instance wizard to create a new compute instance.
The wizard 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 your Ubuntu Linux instance to the internet.
- Creates an
ssh
key pair you use to connect to your instance
To get started installing your instance with the Create a VM Instance wizard, follow these steps:
- From the main landing page, select Create a VM Instance wizard.
{% imgx assets/wordpress-apache-quickactions.png "Screenshot of the Create VM Instance wizard" %}
The Create Compute Instance page is displayed. It has a section for Placement, Image and shape, Networking, Add SSH keys, and Boot volume. 2. Choose the Name and Compartment. Initial Options: * Name: * Create in compartment: Enter a value for the name or leave the system supplied default. 3. Review the Placement settings, and click the Show advanced options link. Take the default values. Your 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
For Free Tier, use Always Free Eligible option for availability domain.
-
Review the Image and shape settings.
- Select the latest Ubuntu image.
- Click Change Image.
- Select the latest Ubuntu image.
- Click Select Image. Your image is displayed, for example your data looks similar to the following:
- Image: Canonical Ubuntu 20.04
- Image build: 2020.12.11-0
- Take the default values for Shape. For example, your data looks similar to the following:
- Shape: VM.Standard.E2.1.Micro
- OCPU count: 1
- Memory (GB): 1
- Network bandwidth (Gbps): 0.48 For Free Tier, use Always Free Eligible shape options.
- Select the latest Ubuntu image.
-
Review the Networking settings. Take the default values provided by the wizard.
The following is sample data. The actual values change over time or differ in a different data center.
- Virtual cloud network: vcn--
- Subnet: vcn--
- Assign a public IPv4 address: Yes
-
Review the Add SSH keys settings. Take the default values provided by the wizard.
- 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.
Put your private and public key files in a safe location. You cannot retrieve keys again after the compute instance has been created.
-
Review the Configure boot volume settings. Take the default values provided by the wizard. Leave all check boxes unchecked.
-
Click Create to create the instance. Provisioning the system might take several minutes.
You have successfully created an Ubuntu Linux instance.
The Create a VM Instance wizard automatically creates a VCN for your VM. You add an ingress rule to your subnet to allow internet connections on port 80.
Follow these steps to select your VCN's public subnet and add the ingress rule.
-
Open the navigation menu and click Networking, and then click Virtual Cloud Networks.
-
Select the VCN you created with your compute instance.
-
With your new VCN displayed, click 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 your VCN is displayed.
-
Click the Default Security List link. The default Ingress Rules for your VCN are displayed.
-
Click Add Ingress Rules. An Add Ingress Rules dialog is displayed.
-
Fill in the ingress rule with the following information.
- 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
Click Add Ingress Rule. Now HTTP connections are allowed. Your VCN is configured for Apache server.
-
Click Add Ingress Rule. Now HTTP connections are allowed. Your VCN is configured for Apache server. You have successfully created an ingress rule that makes your instance available from the internet.
Next install and configure Apache web server and PHP to run on your Ubuntu Linux instance.
Connect to your Ubuntu instance and configure your firewall settings. Follow these steps:
-
Log into 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 your instance.
-
Open a Terminal window.
-
Change into the directory where you stored the ssh encryption keys you created in part one.
-
Connect to your 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 your VM. You can now issue
sudo
commands to install and start your server. -
Update firewall settings. Next, update your 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.
sudo apt update
sudo apt -y install apache2
-
Next, start Apache.
sudo systemctl restart apache2
-
You can now test your server.
You can test your server from the command line with curl localhost. Or, you can connect your browser to the public IP address assigned to your VM:
http://<your-public-ip-address>
. The page looks similar to:{% imgx assets/wordpress-apache-ubuntu-default.png "Apache 2 Ubuntu default page" %}
-
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 your 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 PHP configuration on your VM.
{% imgx assets/wordpress-apache-php-ubuntu-details.png "A table listing the PHP configuration on your VM" %}
You have successfully installed Apache and PHP 7 on your Oracle Cloud Infrastructure instance.
After you are done testing, delete the
info.php
file.
Set up your Apache server to read and write from the /var/www/html
directory.
-
Add your 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.
-
Install the MySQL Server package.
sudo apt -y install mysql-server
This step can take some time.
-
Next, perform a secure configuration of MySQL.
sudo mysql_secure_installation
Produces this output:
Securing the MySQL server deployment. Connecting to MySQL using a blank 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:
-
Select a level.
-
Set the root password.
Please set the password for root here. 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) :
-
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!
-
Log in to MySQL.
sudo mysql
You are given 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 your 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 your 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>.gz
tar xvfz <download-file-name>.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/htm
l 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. Your command differs 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 your root directory is accessed. -
Rename the
wp-config-sample.php
file.mv wp-config-sample.php wp-config.php
-
Update the values for your 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
Create an administrator account for your WordPress blog. Ensure you write down the information from the install page. You need it to log into your WordPress blog.
-
Open your 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 Oracle Cloud Infrastructure (OCI) compute instance.
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:
- Oracle Developers Portal
- Oracle Cloud Infrastructure {% endslides %}