Hello again!
I manage to solve this with help from "dcraig" in Linode IRC chat.
So this is what I wanted:
* A central place where you point towards what is public
* A public space in users home directory where user have full control of add and delete
* Seperate space: dev.grytet.eu, test.grytet.eu, and production grytet.eu
* Seperate apache loggings for the above environment
This what I did (System debian 6)
1. Disable default virtual host
Code:
sudo a2dissite default
2. Go to home directory
Code:
cd ~
3 Create public folder
Code:
mkdir public
4. Seperate folders in public space
Code:
cd public
mkdir dev
mkdir test
5. Make sure public folder has 755 drwxr-xr-x Owner everything, Others just read
Code:
chmod -R a+rx ~/public
6. Create the folder and separate log files in /var/log/dev and var/log/test
Code:
cd /var/log
sudo mkdir dev
cd dev
sudo nano apache_access.log
sudo nano apache_error.log
cd /var/log
sudo mkdir test
cd test
sudo nano apache_access.log
sudo nano apache_error.log
7. Add symbolic links in the public www folder, (in debian it is /var/www) to the user public space (dev, test, and production (public))
Code:
ln -s [TARGET DIRECTORY OR FILE] ./[SHORTCUT]
Example
Code:
cd /var/www
ln -s /home/{user}/public main_public
Repeat the above step for dev and test
8. Create the new virtual host file
Code:
sudo nano /etc/apache2/sites-available/grytet.eu
9. Add this in file just created
Code:
# domain: grytet.eu
# public: /var/www (symbolic linked to user home directory)
# Main
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/main_public
ServerName www.grytet.eu
ServerAlias grytet.eu
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
# Test
<VirtualHost *:80>
DocumentRoot /var/www/test_public
ServerName www.test.grytet.eu
ServerAlias test.grytet.eu
# Logging
ErrorLog /var/log/test/apache_error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/test/apache_access.log combined
</VirtualHost>
# Dev
<VirtualHost *:80>
DocumentRoot /var/www/dev_public
ServerName www.dev.grytet.eu
ServerAlias dev.grytet.eu
# Logging
ErrorLog /var/log/dev/apache_error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel debug
CustomLog /var/log/dev/apache_access.log combined
</VirtualHost>
10. Enable the new virtual host file
Code:
sudo a2ensite grytet.eu
11. Restart apache
Code:
sudo service apache2 restart
In the above, switch out my domain to your own, and change name of files and folders to your preference.
Do not forget
At your host registrator, apart from pointing your main domain, you also need to create the sub domains (dev, and test) and point them with either A or CNAME, if you use A point to your servers ip, if you use CNAME point to your main domain. Advantage of using CNAME is that it follows your main domain, so if you ever change your host or ip, you just need to point your main domain to the new place.
Why this approach
On debian system, normal user can not write to /var/www, so uploading and deleting files was a no go. From what I read it was not advised to add a normal user to the www folders user group and let that group write to it. I could just have used the user home directory as DocumentRoot, putting a symbolic link however gave me more of an overview.
Note
If you want for instance
http://www.test.grytet.eu to work you need to add (
http://www.test) as a subdomain at your registrator (atleast where I have my domain) I have just done that and pointed it (CNAME --> grytet.eu), Perhaps I need to add that to my virtual host file, same as i did for dev and test. I have to wait and see once it has propagated. update - No change was required to the virtual host file, it works as intended.
As a final word - If you have any suggestion on improvement, please let me know!
Regards
Martin