Jump to content

Setting virtual hosts correctly in Apache 2.4 for multiple local web apps?

I'm not sure if this is the right section of the forum, but I figured it was related.

I'm trying to set up my Arch Linux server to host multiple web apps locally for me, such as a mail client and CRM. 

What the apps are don't really matter for my question though. I'm trying to figure out how to properly set it up such that I can use the following ways to access each app:

192.168.1.40/mail
192.168.1.40/crm
192.168.1.40

The way the CRM explains to add the site to Apache's config file is to use a virtual host and set the DocumentRoot to the app's folder.

My general DocumentRoot for Apache is /srv/http. I've created a directory within it called "crm" and symlinked the app's folder there. Same for the mail app.

However, the VirtualHost example the CRM's guide gives states to put the DirectoryIndex for the app as app.php. I don't know how to do this without locking everything through the IP address to that app's folder. 

i.e. I'd like to go to 192.168.1.40/crm and it use /srv/http/crm/app/app.php as the DirectoryIndex there, while I want 192.168.1.40 to just be a listing of the apps (an index), while I want 192.168.1.40/mail to use /srv/http/mail/app.php as the DirectoryIndex.

The reason I want to do that is because the CRM's example worked fine for the CRM. The app's setup page came up correctly. But then I couldn't access /srv/http/mail or just /srv/http for the index. So I'm thinking that's what I should do. If that's not the right/best way to set this up, then please explain what is.

I'm not entirely sure how to do that because I don't know enough about Virtual Hosts and how Apache handles these things to understand how to do this.

† Christian Member †

For my pertinent links to guides, reviews, and anything similar, go here, and look under the spoiler labeled such. A brief history of Unix and it's relation to OS X by Builder.

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

It's actually simple. I did this two years ago on a client's server running two instances of wordpress.

 

cd /etc/apache2/sites-available

sudo cp default FirstSite

sudo cp default SecondSite

sudo nano FirstSite

This file should look like this

<VirtualHost *:80>
    ServerAdmin your_email_address
    ServerName firstsite.com
    ServerAlias www.firstsite.com
    
    DocumentRoot /var/www/FirstSite
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /var/www/FirstSite>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>

sudo nano SecondSite

This file should look like this

    <VirtualHost *:80>
    ServerAdmin your_email_address
    ServerName secondsite.com
    ServerAlias www.secondsite.com
    
    DocumentRoot /var/www/SecondSite
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /var/www/SecondSite>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>

sudo a2ensite FirstSite
sudo a2ensite SecondSite

sudo service apache2 reload

=======================Current Build=======================

Motherboard: ASUS Z170-AR

CPU: i5-6600k @ 4.5Ghz Overclocked

GPU: Gigabyte GTX980 @ 1200 Mhz Oveclocked GPU boost 1400Mhz

Memory: Corsair Dominator 16Gb @ 3200 Mhz

Cooler: NZXT Kraken x61

Storage: Corsair Force GS 128Gb + WD2TB + Seagate 1TB

PSU: Corsair HX650

Lighting: NZXT HUE+ with extension

Display: LG 34' Ultrawide 3440x1440

Peripherals: Razer Blackwidow x Chroma + Razer Firefly + Razer Mamba Chroma

Headphones: Astro A40 + Miniamp

 

Link to comment
Share on other sites

Link to post
Share on other sites

10 hours ago, Geoffrey said:

It's actually simple. I did this two years ago on a client's server running two instances of wordpress.

 

cd /etc/apache2/sites-available

sudo cp default FirstSite

sudo cp default SecondSite

sudo nano FirstSite

This file should look like this

<VirtualHost *:80>
    ServerAdmin your_email_address
    ServerName firstsite.com
    ServerAlias www.firstsite.com
    
    DocumentRoot /var/www/FirstSite
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /var/www/FirstSite>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>

sudo nano SecondSite

This file should look like this

    <VirtualHost *:80>
    ServerAdmin your_email_address
    ServerName secondsite.com
    ServerAlias www.secondsite.com
    
    DocumentRoot /var/www/SecondSite
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /var/www/SecondSite>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>

sudo a2ensite FirstSite
sudo a2ensite SecondSite

sudo service apache2 reload

Hmm, thank you.

My greater issue now is converting that into Arch commands.

Examples:
command a2ensite doesn't exist.

apache is known as httpd

I do not have a "sites-available" sub-directory within /etc/httpd and /etc/apache2 doesn't exist.

Guess I'll have to do more research. Thanks for the direction tho!

Well, that and I'd prefer them all use the same domain. This may mean they aren't different virtual hosts though. 

The two ways I'd be fine with accessing them is the following:

crm.192.168.5.40
192.168.5.40/crm

I tried the first one, but that didn't work out for me.

† Christian Member †

For my pertinent links to guides, reviews, and anything similar, go here, and look under the spoiler labeled such. A brief history of Unix and it's relation to OS X by Builder.

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

I believe you can have them on the same domain. Try to set them up in different subdirectories and make a 

.htaccess

=======================Current Build=======================

Motherboard: ASUS Z170-AR

CPU: i5-6600k @ 4.5Ghz Overclocked

GPU: Gigabyte GTX980 @ 1200 Mhz Oveclocked GPU boost 1400Mhz

Memory: Corsair Dominator 16Gb @ 3200 Mhz

Cooler: NZXT Kraken x61

Storage: Corsair Force GS 128Gb + WD2TB + Seagate 1TB

PSU: Corsair HX650

Lighting: NZXT HUE+ with extension

Display: LG 34' Ultrawide 3440x1440

Peripherals: Razer Blackwidow x Chroma + Razer Firefly + Razer Mamba Chroma

Headphones: Astro A40 + Miniamp

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×