Home directory websites using vhost
Needs / Issues
- Develop websites located inside home directory;
- No need for special (root/web server) privileges to develop sites;
- Websites are referenced with DNS, not aliases.
Audience
- Administrator / Power user;
- Developer user.
Initial Setting
- Apache 2.2 (or newer).
Steps
-
In a shell session (as user):

- Create your "root" directory
mkdir ~/public_html
This is where the site will be hosted.
- Make sure the Apache user can access that root directory:
namei -l ~/public_html
All directories in the output list should be at least executable by the Apache user.
- Create your "root" directory
-
In a shell session (as root):
- Enable VHosts in Apache's configuration:
vi /etc/httpd/conf/httpd.conf
Uncomment the following line:NameVirtualHost *:80
- Create an Apache configuration file for your website:
vi /etc/httpd/conf.d/YOUR_WEBSITE.conf
Have it contain:<VirtualHost *:80>ServerName YOUR_WEBSITE.localhost
DocumentRoot /home/YOUR_USERNAME/public_html
<Directory "/home/YOUR_USERNAME/public_html">
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>ErrorLog logs/YOUR_WEBSITE.localhost-error_log
CustomLog logs/YOUR_WEBSITE.localhost-access_log common
</VirtualHost> - Restart the web server:
service httpd restart
- Add a local DNS entry to your website:
vi /etc/hosts
Add the following line:127.0.0.1 YOUR_WEBSITE.localhost
- Enable VHosts in Apache's configuration:
-
In your web browser:
- Browse to the URL you created:
http://YOUR_WEBSITE.localhost/ - You should be served your new website.
- Browse to the URL you created:
Should these steps not work for you, please let me know.