Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to create multiple level subdomains with apache2 and/or PHP

Tags:

linux

php

apache2

I am looking for a way to have multiple-level subdomains on a server running Apache2.2 and PHP5. Ideally the solution will be in Apache and not PHP.

For instance:

www.apps.example.com OR test.apps.example.com

I've seen this on commercial sites before but have not seen any solutions for how to implement this. I essentially want to allow users to either enter www before any subdomain or just to enter the subdomain without the www's. so both x.example.com and www.x.example.com resolve to the same directory.

I am running CentOS 5.4 & Ubuntu 8.04, PHP 5.2.10 & Apache 2.2

Thanks

like image 357
Patrick Avatar asked Oct 26 '22 01:10

Patrick


1 Answers

You can dynamically add entries into apache config files using a PHP language, But remember you are living on edge of uncertainty

// add this to your httpd.conf
Include extra/httpd-vhosts.conf

// add this to extra/httpd-vhosts.conf
<VirtualHost *:80>
// with www prefix
DocumentRoot /www/example/x
ServerName x.example1.com
ServerAlias www.x.example1.com
</VirtualHost>

<VirtualHost *:80>
// without www prefix
DocumentRoot /www/example/x
ServerName x.example1.com
</VirtualHost>
like image 166
Ish Avatar answered Nov 01 '22 10:11

Ish