-
Make sure ubuntu is up to date
sudo apt update
-
Install Apache 2
sudo apt install apache2
-
Check if apache's status
sudo systemctl status apache2
Should output
● apache2.service - The Apache HTTP Server Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled) Drop-In: /lib/systemd/system/apache2.service.d └─apache2-systemd.conf Active: active (running) since Thu 2019-03-14 15:26:24 CET; 2min 20s ago Main PID: 12952 (apache2) Tasks: 55 (limit: 4915) CGroup: /system.slice/apache2.service ├─12952 /usr/sbin/apache2 -k start ├─12953 /usr/sbin/apache2 -k start └─12954 /usr/sbin/apache2 -k start
-
Check if you can reach the default site with your browser Go to
http://localhost
. You should be created with "Apache2 Ubuntu default Page" -
Create your virtual host named for example:
tests.js
sudo vim /etc/apache2/sites-available/tests.js.conf
- Paste these directives in the file by pressing in a sequence
"
,+
,p
<VirtualHost *:80> ServerAdmin admin@example.com ServerName tests.js ServerAlias www.tests.js DocumentRoot "/home/g/Documents/workspace/js/tests" ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined <Directory "/home/g/Documents/workspace/js/tests"> Options Indexes FollowSymlinks AllowOverride All Require all granted </Directory> #set the file that appache will serve if directory is requested <IfModule dir_module> DirectoryIndex index.php index.html </IfModule> </VirtualHost>
- Paste these directives in the file by pressing in a sequence
-
Enable the new vhost and disable the default one:
sudo a2ensite tests.js.conf sudo a2dissite 000-default.conf
-
Test your configuration
sudo apachectl configtest > Syntax OK
You may get the following Warning:
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message Syntax OK
The message is self explanatory: do
sudo vim /etc/apache2/apache2.conf
and type somewhere in a new lineServerName localhost
-
Restart apache to load your configuration:
sudo systemctl restart apache2
Set up Apache with Vhosts on Ubuntu 18.04
Invalid Date