Pretty simple, but you’ll need to handle the coding part.
- Create an A record at DO for a wild-card sub-domain (*.users.your-domain.com, for example)
- In apache, create a wild-card vhost:
Example vhost config (written for CentOS 6.6)
#### This is where you put your files for that domain: /var/www/vhosts/c.jonsjava.com
# This section sets directives for the directory.
# -Indexes <-- That blocks index listings on folders that don't have a default file (index.php/index.html/default.html/etc)
# FollowSymLinks <-- This will treat symlinks like they should be treated in linux: as folders/files in the folder the symlink resides
# MultiViews <--It's easier for you to read this: http://httpd.apache.org/docs/2.0/content-negotiation.html#multiviews
Options -Indexes FollowSymLinks MultiViews
# AllowOverride All <-- This is required for Apache HTTPD server to read .htaccess files. It says that you can have a per-folder override for apache directives
## Everything to see here. Just the log files. Good to use for troubleshooting errors.
CustomLog /var/log/httpd/users.your-domain.com-access.log combined
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
- In your PHP, have it get the host name:
$URL = $_SERVER[SERVER_NAME];
Now, you have the user. Just have your code configured to show that users page, or a 404 if it doesn’t exist.