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

Laragon: installing more versions of Apache/HTTPD

Most of the time, we casually install various PHP versions and server tools without checking if they were built for Win32 or Win64. A discussion for another day. I recently downgraded Laragon’s from PHP8.1-x64 to PHP7.x-x86. This had a little consequence - APACHE! Hence, I got the error below, indicating that my PHP and Apache can’t work together because they are of different architectures or builds.   The originally installed Apache was for 64-bit PHP versions, there are no Apache versions designed to run both 32-bit and 64-bit builds of PHP. In this article, I share steps and links that guide you to install multiple versions and builds of Apache on Laragon. 1. For all intent and purposes, you are advised to always download the latest version of Apache. Visit this URL https://www.apachelounge.com/download/additional/ to see the different versions available. It is easy to access the 64-bit versions from the homepage. However, to access the 32-bit versions, you need to use this URL. 2

Resolving Incompatible Builds of PHP and Apache in Laragon: Add multiple versions of Apache

 As developers, it's often the case that different versions of PHP and server tools are installed quickly without taking into account the architecture for which they were built. In this article, we will focus on solving a specific error that arises when running incompatible builds of PHP and Apache. Recently, I encountered an issue when downgrading my Laragon setup from PHP 8.1 (x64) to PHP 7.x (x86). This caused compatibility problems with Apache, and I received an error message indicating that my PHP and Apache builds were not compatible, as the Apache installed was built for x64 versions of PHP. In this article, I'll provide a step-by-step guide on how to install multiple versions of Apache on Laragon. By following these steps, you can resolve any similar issues that you may encounter. Step 1: Download the Latest Version of Apache Visit https://www.apachelounge.com/download/additional/ to download the latest version of Apache. The homepage provides quick access to 64-bit ve

VS CODE: Unable to install extensions on Ubuntu/Linux

Hey, its one of those days, i just wished i could code away the night. i decided that tonight, it was going to be VS Code all through. I closed Sublime text. It was not long before I started missing the php code linting and ever intelligent code completions that were built into sublime text. I checked the suggestions on the Extensions Tab of VS Code. and there it was! Felix Becker's "PHP IntelliSense" package. To my cute surprise, Upon clicking, the extension's description and Installation "Read Me" could not display correctly, 'twas as good as blank. All i could see was this: I thought, this is something light, so i started searching but then it was not better explained except for the GitHub issue which I found to be useful, Link is at the bottom of this page.  I hate to discover it was a DNS issue. How to detect the Issue Simply visit the URL below, if you are able to view the image on the page, then you are not affected by this issue. DNS Test URL: ht