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

How to Selectively Disable Timestamp Columns in Laravel Models

Introduction: In Laravel, the updated_at and created_at columns are timestamp columns that automatically update whenever a model is saved or created. However, there might be scenarios where you want to selectively disable one or both of these columns for specific models. Fortunately, Laravel provides a straightforward way to achieve this by customizing your model's const UPDATED_AT and const CREATED_AT constants. In this blog post, we will explore how to selectively disable timestamp columns in Laravel models, discuss the benefits of this approach, and guide you through the necessary steps. Step 1: Create a Laravel Model and Migration To demonstrate this process, let's assume we have a model called Download that represents a downloadable file in our application. If you don't have a model already, you can create one using the php artisan make:model Download command in your terminal. To generate the migration for the downloads table, run the following command: php ar...

[SOLVED] Linux - Issues installing Docker on Ubuntu - libseccomp2 version 2.3.1 installed but 2.4 required

This article has been improved for a better understanding - goto  https://splashcoder.blogspot.com/2023/07/installing-docker-on-ubuntu-1804-solved.html There is a possibility that you are trying to install docker. There is a very comprehensive guide at https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository. The linked guide serves as a reference for this article. We try to address the common errors in this article. Just so you won’t have to scour the entire answers on StackOverflow. Step 1: The first thing is to run our famous "apt update" command. So run the command below. sudo apt-get update You may observe that there are some errors. And YES! we are using a fairly old Ubuntu 18.04 Bionic Beaver Release. It seems perfect for this as most people have issues installing docker anyways. To resolve this, you may refer to  Configure DNS server IP to resolve errors with apt-get update Step 2: Following the Docker article, we should run the commands below. sudo...

Linux - Configure DNS server IP to resolve errors with apt-get update

Perhaps you have a new install of Ubuntu, and you are about to install docker or any other Linux packages. The first step is to update the application repositories using the sudo apt update command. There is a very small possibility that you will get the error below if you are using a fresh install of the Ubuntu 18.04 LTS (Bionic Beaver). This error simply means that Linux is unable to connect to the official repository likely due to a DNS configuration or a network issue. Here we try to help you resolve the DNS issue. To resolve this, you must specify a DNS in your network settings. Well, there is one popular DNS that works well: Google's DNS. Follow through, please. STEP 1: Go to the settings page of Linux (Ubuntu) STEP 2: This should reveal a plethora of options. On the left pane, simply scroll down and click Network as shown below. This reveals your different network connections, for me, “enp0s3” is the adapter connecter to the internet. So, I must configure DNS for “enp0s3”. ...