Installing Ubuntu Server and WordPress To Build A Website
Whether you are building a website for your passion, curiosity, or business, everyone should be able to express themselves on the web. Thanks to open source technologies like Linux and WordPress, you can do it from your home all by yourself. In this article, we will take a look at how to build a website completely by yourself in order to protect your privacy, wallet, and curiosity. You don’t need any prior knowledge about coding to get started!
Preparation
There are some things that you need before we start.
Hosting
You can either purchase hosting or host yourself. There are also free or trial services you can use like Amazon Web Services. In this article, we will talk about hosting the website ourselves with an Ubuntu (A Linux Distro) Server. You can use any old PC, laptop, or even a Raspberry Pi for this.
Internet Access
This might look obvious, but when we are talking about Internet Access for a website, we are not just talking about downloading, but also uploading with port forwarding. If you are unfamiliar with port forwarding, in very simple terms, it is a tunnel to the web from your router that allows everyone on the internet to reach your website. You generally need a Static IP for this, but in this article we will talk about how to use Cloudflare Tunnel in order to allow access even without port forwarding or Static IP.
Domain
A Domain is a name that generally ends with .com for people to write on their browser or search engine to find your website. When they go to your domain name, it resolves to your IP address, which serves them your website if everything works as they should. You can purchase your domain from various websites like cloudflare.com or namecheap.com for this purpose.
Time
You should leave at least a full day for this project. If everything goes well, it shouldn’t take more than 2 hours, but it is a good idea to leave some time free for any misconfiguration or bugs that might arise.
Setting Up the Ubuntu Server
We chose Ubuntu Server for our hosting because it is secure, up-to-date and it just works well. You need a computer and a USB stick for this.
Download the Ubuntu Server ISO
- Visit: https://ubuntu.com/download/server
- Select the latest LTS version.
- Download the ISO.
Create Bootable USB
- Use a tool like Rufus.
- Select the ISO file and your USB drive.
- Start the process.
Boot from USB
- Insert the USB drive into your target computer.
- Restart and enter BIOS/UEFI settings.
- Change boot order to prioritize the USB.
- Save and exit BIOS/UEFI.
Follow the Installation Wizard
- The installer will guide you through:
- Language selection
- Keyboard layout
- Network configuration
- Disk partitioning
- User account creation
- Optional software installation
- The installer will guide you through:
Complete and Reboot
- The installation will take some time.
- Once done, reboot and remove the USB drive.
- Your Ubuntu Server is ready!
Once you log in your Ubuntu Server, you will see a terminal interface. We will use this terminal to install and maintain our server for our website.
Using the Terminal
First thing we should do is to update and upgrade the server. You can do this by typing the following code to your console:
sudo apt update
sudo apt upgrade
Next, we need to install Apache, MySQL and WordPress to our server. You can think of all these like programs. Apache handles the connection to the internet while MySQL is our database, and WordPress is the content manager for our website.
sudo apt install apache2 mysql-server php libapache2-mod-php php-mysql
During MySQL installation, the wizard will ask you to set up a password. Choose a password you won’t forget.
Create a WordPress Database in MySQL
sudo mysql -u root -p
# Login to MySQL with this command. Enter your MySQL root password when prompted
CREATE DATABASE wordpress_db;
CREATE USER 'wordpress_user'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wordpress_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
# You can change "wordpress_db", "wordpress_user" and "your_password" with the values you want.
Download & Install WordPress
Now that our database is set up, we can start installing WordPress, which will control our website. Use the following code to install WordPress to /var/www/html location on your disk.
cd /var/www/html/
sudo wget https://wordpress.org/latest.tar.gz
sudo tar -xzvf latest.tar.gz
sudo rm latest.tar.gz
sudo cp -a wordpress/* .
sudo chown -R www-data:www-data /var/www/html/
sudo find /var/www/html/ -type d -exec chmod 755 {} \;
sudo find /var/www/html/ -type f -exec chmod 644 {} \;
Configuring Apache and Cloudflare Tunnel
Now that our website is ready, the next step is to configure Apache in order to serve it online. You need to know where the website (WordPress) files are and what your port will be to do this. We will also use Cloudflare Tunnel in order to expose our website to the internet since it is much securer than port forwarding, but if you already have your port forwarded, simply skip the Cloudflare steps and use that port. You might also need to install Cert Bot if you want to use HTTPS while port forwarding.
- Move your name-servers to Cloudflare and set up a tunnel
- Note the port number you put on the tunnel settings
- If it doesn’t work, try disabling TLS Verify on tunnel settings
Making the Website Online
Now that our port is ready, let’s configure Apache and say hello to our website!
Check Where Your Website Files Are:
- The default location for website files on Ubuntu Server is
/var/www/html/
. - If you’ve chosen a different location, make sure to adjust the paths accordingly in the following steps.
Create and Configure a .conf
File:
Create a new virtual host configuration file (replace
mywebsite
with your desired name):
sudo nano /etc/apache2/sites-available/mywebsite.conf
- Paste the following configuration, replacing placeholders with your actual details:
<VirtualHost *:80>
ServerName yourdomain.com # Replace with your actual domain name
ServerAlias www.yourdomain.com # Optional, for handling 'www' subdomain
DocumentRoot /var/www/html/mywebsite # Adjust if your website files are elsewhere
<Directory /var/www/html/mywebsite> # Adjust if your website files are elsewhere
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
- Edit
ports.conf
File (Usually Not Necessary):
If you are using the default 80 port, you won’t need to make any changes in the ports file. Make sure the port you are using on your Cloudflare tunnel is correct. If you point the tunnel to “localhost:80” it should work without editing the ports file. If you want Apache to listen to other ports, simply add the port you want to the ports.conf file in “/etc/apache2/ports.conf” using nano or any other text editor.
Enable the Site and Restart Apache:
sudo a2enmod rewrite
sudo a2enmod ssl
sudo a2ensite mywebsite.conf
sudo systemctl restart apache2
Start Editing Your Website
Congratulations, you should have a working website at this point. Simply write your domain name to a browser to connect to WordPress and start editing your website! If you need any assistance, Epheos is always here to help.