Skip to main content

How to configure multiple host for Apache on Ubuntu

Introduction

I recently switched to Ubuntu Desktop. Everything was simple and
straight forward until i needed to run multiple Laravel projects on my
LAMP stack.

For the records, I will also demonstrate how i installed a stable LAMP setup. If you are only interested in configuring multiple Host on Apache, you can click here to skip the story.

Installing the LAMP Stack

LAMP simply means Linux,Apache,MySql,PHP.

I tried so many methods but the command below made life easier for the living.

sudo apt-get install lamp-server^

The command above installed all i needed without any issue. I already configured Mysql from previous installation. All data and configurations of MySql from previous installation remained intact.

I installed the laravel installer and initialized a new Laravel project in the Apache directory.

cd /var/www/html

At first i was comfortable with using 

php artisan ser

Later i decided i was not convenient with the 127...:8080, in windows i had laragon to create vanity urls for my new projects.

 

Configuring Apache

1. first I created 2 laravel projects in the home directory. one called flighter and the other called pakt.

2. I also decided that flighter will be accessible as fly.mk and pakt will be accessible as pakt.pak

2. We need to create entries for these custom domains in the /etc/hosts file. see below command

nano /etc/hosts

you can see the screenshots before and after editing the host file.


3. I created an apache conf file for my domain names. the conf files are usually stored at /etc/apache2/sites-available.

below is a sample of the conf file i created. you can create many conf files if you like but i chose to use one conf file for both domains i am creating.

<VirtualHost *:80>  
  ServerAdmin admin@example.com
     DocumentRoot /var/www/html/flighter/public
     ServerName fly.mk
     ServerAlias www.fly.mk

     <Directory /var/www/html/flighter/public>
        Options +FollowSymlinks
        AllowOverride All
        Require all granted
     </Directory>

     ErrorLog ${APACHE_LOG_DIR}/flighter-error.log
     CustomLog ${APACHE_LOG_DIR}/flighter-access.log combined
</VirtualHost>

<VirtualHost *:80>   
  ServerAdmin admin@example.com
     DocumentRoot /var/www/html/pakt/public
     ServerName pakt.pak
     ServerAlias www.pakt.pak

     <Directory /var/www/html/pakt/public>
        Options +FollowSymlinks
        AllowOverride All
        Require all granted
     </Directory>

     ErrorLog ${APACHE_LOG_DIR}/pakt-error.log
     CustomLog ${APACHE_LOG_DIR}/pakt-access.log combined
</VirtualHost>

4. save the code above as mydomains.conf

5. run the commands below to enable the new virtual hosts and rewrite modules for our projects.

sudo a2ensite mydomains.conf

sudo a2enmod rewrite

6. then restart apache with the command below

systemctl restart apache2

7. now you can access any of the laravel projects from 

fly.mk and pakt.pak

 

I hope i was brief enough to spark your interest most articles and SO answers forget to mention steps 1, 2 and 3. 

Let me know if you faced any challenge while practicing these.

Thanks for reading.

Comments

Popular Articles

Issue with installing python-axolotl or python-axolotl-curve25519 on Windows

It is peeve amazing how many hours get burnt while trying to resolve simple package dependency issues. I may be too dumb to proffer a lasting one-fits-all solution to all dependency issues, but I got this issue fixed in my own case. Problem Description: The python-axolotl library requires certain dependencies that are not properly managed when installing libraries via a command line's requirement.txt file. I got real help by reading through this link below, but this page might be more helpful when it comes to detailed instructions. Actual instructions: https://github.com/tgalal/python-axolotl Typical errors might look like the following: 1. In this case, missing library(s). Libraries needed for compiling some python resources. Unfortunately, http://aka.ms/vcpython27  has been decommissioned because Python2x is EOL. You can still get the VcPython27 from an archive at https://web.archive.org/web/20210106040222/download.microsoft.com/download/7/9/6/796EF2E4-801B-4F...

Chrome Extension (part 1): Injecting External Scripts into a Web Page

Recently, I was required to develop a chrome extension for some executives. This plugin only targeted a few of our most visited websites. There was a lot of approaches to implement the extension and all our use cases. One particular challenge was trying to inject scripts from our own CDN into specific web pages. the scripts were required to interact with the page and all variables possible. Since there is a script isolation thing for Chrome Extensions, I felt this was a good challenge to take up in my spare time. Here is a sample of my content script. content.js document.onreadystatechange = function () { console.log("document state is:" + document.readyState); if (document.readyState == "complete") { let randAntiCache = Math.random().toString().split('.')[1]; let scriptURL4="http://localhost.test/testscript.js?v="+randAntiCache; let scriptnode4 = document.createElement("script"); scriptnode4.setAttribute("s...

Who is this Brown Skin Girl?

In the recent wake of a great musical sensation and a re-make of the famous Lion King movie, Beyonce has been on the global selection of artistes to share performances. Today, I will try to examine the poetry of the track titled Brown Skin Girl, All interpretations in this article are my personal candid opinion. so feel free to share yours in the comments section, i will be glad to add it to my edits. So while I may not pretty boy; your heart is amiss; Play it like a villain `cause she caught in a wave This paints the picture of a guy who feels He is not good enough for the lady of his dreams, so he said Tonight I am walking away Lined up my mind, on the grind yeah yeah meaning he tryin' to give up. But then in the chorus, He said Tonight I might fall in love Depending on how you hold me I'm glad that I'm calming down can't let no one come control me So this dude aint feeling he's the kinda guy for bae, but bae be doubting if she still want...