Installing Apache
Soruce: https://ubuntu.com/tutorials/install-and-configure-apache#5-activating-virtualhost-file
To install Apache, install the apache2
by executing:
sudo apt update
sudo apt install apache2
Creating Your Own Website
Apache comes with a basic site enabled. We can modify its content in /var/www/html
or settings by editing its Virtual Host file found in /etc/apache2/sites-enabled/000-default.conf
.
Creating a folder for our new website in /var/www/
by running
sudo mkdir /var/www/y2v/
We have it named y2v here but any name will work, as long as we point to it in the virtual hosts configuration file later.
Now that we have a directory created for our site, lets have an HTML file in it. Let’s go into newly created directory and create one by typing:
cd /var/www/y2v/
nano index.html
Paste the following code in the index.html
file:
<html>
<head>
<title> Ubuntu CyberWorld Test! </title>
</head>
<body>
<p> I'm running this website on an Ubuntu Server server!
</body>
</html>
Now let’s create a VirtualHost file so it’ll show up when we type in y2v.example.com
.
Setting up the VirtualHost Configuration File
We start this step by going into the configuration files directory:
cd /etc/apache2/sites-available/
Since Apache came with a default VirtualHost file, let’s use that as a base. (gci.conf
is used here to match our subdomain name):
sudo cp 000-default.conf y2v.conf
Now edit the configuration file:
sudo nano y2v.conf
We should have our email in ServerAdmin
so users can reach you in case Apache experiences any error:
ServerAdmin yourname@example.com
We also want the DocumentRoot
directive to point to the directory our site files are hosted on:
DocumentRoot /var/www/y2v/
The default file doesn’t come with a ServerName
directive so we’ll have to add and define it by adding this line below the last directive:
ServerName y2v.example.com
This ensures people reach the right site instead of the default one when they type in y2v.example.com
.
Activating VirtualHost file
After setting up our website, we need to activate the virtual hosts configuration file to enable it. We do that by running the following command in the configuration file directory:
sudo a2ensite y2v.conf
You should see the following output
Enabling site y2v.
To activate the new configuration, you need to run:
systemctl reload apache2
root@ubuntu-server:/etc/apache2/sites-available#
To load the new site, we restart Apache by typing:
service apache2 reload
# Change permissions in case it is needed
chown -R www-data:www-data *
Soruce: https://ubuntu.com/tutorials/install-and-configure-apache#5-activating-virtualhost-file