Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Sat Oct 20, 2012 2:04 pm 
Offline
Senior Newbie

Joined: Sat Oct 20, 2012 1:19 pm
Posts: 5
Hello,

System: Debian 6

I am a new user and read the guide on how to set up virtual host on apache here at Linode. I like to have another approach and need help setting it up correctly.

What I want
* One main public web folder (/var/www)
* symbolic links in /var/www to the user home folder
* Three setups, dev, test, and produktion (dev.grytet.eu, test.grytet.eu, grytet.eu)
* Separate logs (error.log, access.log for: dev, test and production
* Not now, but eventually use SSL

My problem
When I enter a subdomain in the URL like test.grytet.eu I get error that it can not find it. If I enter dev.grytet.eu it says it is parked at my registrator. If I enter only grytet.eu it works as intended. How can I make it work for test and dev aswell?

What I have done

* Pointed my domain with A record
* Pointed my subdomains with CNAME (just recently, perhaps it has not resolved yet, and that is why I get the faulty behaviour).
* I have created separated log files for dev, test, and production
* I have turned of default virtual host
* I have created a new virtual-host file for my site
* I have made symbolics links to diffrent part in the users public folder (In virtual host file they are called main_public, dev_public, and test_public
* Restarted apache

The virtual-host file
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>




What am I missing, why can I not put in dev.grytet.eu or test.grytet.eu and get to the right place, it is working fine with grytet.eu

Will I be able to add SSL config to this later?

Regards
Martin


Last edited by onslow77 on Sun Oct 21, 2012 9:17 am, edited 1 time in total.

Top
   
PostPosted: Sat Oct 20, 2012 9:36 pm 
Offline
Senior Member
User avatar

Joined: Sun Jan 18, 2009 2:41 pm
Posts: 830
Your problem in large part may just be cached DNS values. For me, grytet.eu, http://www.grytet.eu, dev.grytet.eu, and test.grytet.eu all point to your Linode, which is what you want. Visiting dev.grytet.eu brings up a single file named "dev" containing "Nu är vi i dev!" so if that's what's in /var/www/dev_public then you're OK.

However, http://www.test.grytet.eu and http://www.dev.grytet.eu still point to a Loopia address. This shouldn't prevent test.grytet.eu and dev.grytet.eu from working, but is something you'll probably want to fix.

Edit: ignore the "http://" text above; the forum automatically inserts this on things it thinks should be links.


Top
   
PostPosted: Sun Oct 21, 2012 9:13 am 
Offline
Senior Newbie

Joined: Sat Oct 20, 2012 1:19 pm
Posts: 5
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


Last edited by onslow77 on Sun Oct 21, 2012 3:39 pm, edited 1 time in total.

Top
   
PostPosted: Sun Oct 21, 2012 10:20 am 
Offline
Senior Member

Joined: Fri Feb 17, 2012 8:20 pm
Posts: 365
http://xkcd.com/979/ - well done :)


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group