Help - Search - Members - Calendar
Full Version: How-To host apache namebased sites without a control Panel
The Planet Forums > System Administration > HOWTOs
top500
CAUTION: This gets technical and requires fairly solid ssh knowledge.
CAUTION: Many issues are not covered, such as email users and file ownership and sql-xfer and php stuff and all those functions etc etc.
This is only a very basic tutorial that explains how to get apache to work on the html side of things

-------------------------------
CAUTION: user:user ownership
Following this tutorial verbatim will leave all your sites root:root
-------------------------------

Pre-requisites: A flavor of Linux, debian and apache are the ones I use (Ubuntu Gutsy, CentOS 5.0)
Properly propagated or correctly pointed nameservers.
Working Apache!
This can and does work for Windows servers but this is written for Unix

---------------------------------
WARNING: Editing of critical server files is required!!!
---------------------------------
DANGER: Removing a cp on a production server could delete all your sites!
---------------------------------

NOTES: Probably best for servers with few sites.

----------------------------------

Credits and Thanks to the Orbit Support Team for their invaluable assistance!


Steps:

- Order up a server without a cp or remove the cp on the one you have.
> In my case I waited until a server upgrade to make the switch, I felt it better to start clean.
WARNING: I am not telling you how to remove the cp, this is what I meant about technical, if it works don't fix it.

This might work leaving the cp on your server so long you disable the references within apache, but I would either start clean or remove it entirely myself. Obviously on a production server you'll want to backup every thing.

Once that is done, straight to the good stuff:

/////////////////////////////////

- ssh + su to root (on redhat 'su-' on debian 'sudo su')
- go to root of root folder by doing a 'cd /'
- Create a folder sites 'mkdir sites'

/////////////////////////////////

- Go find httpd.conf (some default 'cd /etc/httpd/conf')
> If you can not find it try doing a 'locate httpd.conf'

- Back it UP! 'cp httpd.conf httpd.conf.LASTWORKING
> So if at anytime it fouls up totally you can restore apache
When editing, ALWAYS make a backup first!

/////////////////////////////////

- edit httpd.conf as follows: (either pico or vi)

Most of this should be right towards the end of your file.

Find: NameVirtualHost
Change the entry from

#NameVirtualHost *
to
NameVirtualHost 127.0.0.1:80 <--- Your server IP address not 127.0....

-----
Find the stuff that looks like:
#<VirtualHost *>
# ServerAdmin webmaster@domainname.com
# DocumentRoot /www/docs/domainname.com
# ServerName domainname.com
# ErrorLog logs/domainname-error_log
# CustomLog logs/domainname-access_log common
#</VirtualHost>

Delete all that (or leave it commented) and replace or add this line:
Include /etc/httpd/conf/virtual/*.conf
^^^^^^^^^^^
(/etc/httpd/conf/ <-- path to your httpd.conf)

Save and Exit.

/////////////////////////////////

From within /etc/httpd/conf/ (or where your httpd.conf is)
mkdir virtual
cd virtual

/////////////////////////////////

You have to decide NOW which way to name your sites.
Either site1, site2, etc...
I used the domainname without the com
Or some kind of nomenclature

This tutorial assumes domainname
SO, time to create a domainname.conf (the name of the domain you wish to host!)
vi domainname.conf

Then, drop this into that:

<VirtualHost domain.com:80>
ServerAdmin webmaster@domain.com
DocumentRoot /sites/domain/www/html
ServerName domain.com
ServerAlias *.domain.com
ScriptAlias /cgi-bin "/sites/domain/www/cgi-bin"

<Directory "/sites/domain/www/cgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

(don't forget to change ALL 'domain' instances with the actual name of the domain, with or without .com as stated)

Save and Exit


> Create ONE .conf for every domain you intend to host!
top500
Ok, it is time to create the sitex or domain folder structure.
We want cgi-bin and html directories and all that.

Find out where your current www path is, where apache would go if you had only one site, you want that.
Some apache default /var/www/ or wherever the root for html files is <- that path.

Then:
cd /sites

Now, create one folder for each domain you intend to host!
mkdir domainname
(or mkdir sitex)
Repeat for each of the sites.

Then, cd to the first domain
cd domainname OR cd site1

And, create the structure:
cp -Rf /var/www/ /sites/domainname/

OR cp -Rf /var/www/ /sites/site1/

If your default www is not in /var/www/ then replace as appropriate.


Now just to do a quick check to make sure it worked, do a 'dir' command, you should see a single folder 'www'
So, cd www

Do another dir and you should see the sub-structure (in some cases it's cgi-bin error html icons manual mrtg usage)
I would go ahead and edit up a quick index.html inside the html folder put some bs in there then:

service httpd restart

And check and see if your domain actually works from within a browser.

If it doesn't something went wrong, I assume the nameservers have propagated or are pointed correctly.

If it did, simply create the structure now for every other domain you intend to host.
And remember to do a

service httpd restart

exit
exit
top500
Other stuff:

To transfer files server-to-server my favorite is Rsync.
No nonsense, no backup-restores over two sets of softwares that don't talk to each other etcetc
Only thing is it does not transfer the sql table and it is a bit manual, one site at a time.
There did exist a script that takes advantage of multi-site servers, but I never used it, google for it if you like via 'rsync' + keyword
I usually do the sql manually, copy out the current one into files, then upload those into the new one, voila.

As for the actual html / cgi-bin files, here's how Rsync works:

Steps: Log in to NEW server as root.
Get your root password for the OLD server you will need it!

Copy FROM old TO new (while logged in to NEW)

Once for the bin:
rsync --verbose --progress --stats --compress --recursive --times --perms --links --rsh=/usr/bin/ssh root@127.0.0.1:/home/virtual/domainname.com/var/www/cgi-bin/ /sites/domainname/www/cgi-bin/

Note: 127.0.0.1 is the IP address of your OLD server!
format: rsync --optionsoptionsetcetc --rsh=/thisisgood/ssh root@your.old.server.ip:/root/path/to/the/site/ /new/server/path/

Important: SPACE between ssh root@... and the two paths

And again for the html:
rsync --verbose --progress --stats --compress --recursive --times --perms --links --rsh=/usr/bin/ssh root@127.0.0.1:/home/virtual/domainname.com/var/www/html/ /sites/domainname/www/html/

Other notes:
Remove --verbose for large sites (more than 2-3 gigs of files)
Transfers about 7gigs an hour for me.
You could try this as the appropriate user but I prefer root because less permission errors get in my way initially.
You may have to Chown!!!
Whichever user:user should own the files on your new server!
Format of chown is:
Chown -R user:group *.*
(-R makes it recursive so make sure you're in the correct directory!!!)

As of the time I finished writing this tutorial at least the stonypointlawncare.com site was working as per this method.
atopqualitysite is still on the old server for now (like 8 gigs of files, i gtg zzzz first)
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.