Site in home directory

stleon
  12 years ago
  7

Hi2all, today I read a nice tutorial by @mysoomro, and I want to take you a few words, how start your web-project in home directory.

The default directory for files of a site is in /var/www. To access this directory, we need rights of root. To create a website, for example, /home/user/www/ perform the following steps:

1. Make a copy of the standard config file site (/etc/apache2/sites-available/default) and rename it to (/etc/apache2/sites-available/mysite).

sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/mysite

2. Open a new config file in a text editor nano.

sudo nano /etc/apache2/sites-available/mysite

3. Change the DocumentRoot setting in the new location site.

/home/user/www/

4. Change the parameter Directory, replacing <Directory /var/www/> on <Directory /home/user/www/>. So, you you get something like:

<VirtualHost *:80>
ServerAdmin webmaster@localhost
 
DocumentRoot /home/stleon/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/stleon/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
 
    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>
 
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@localhost
 
DocumentRoot /home/stleon/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/stleon/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
 
    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>
 
</VirtualHost>

Save the file.

5. Now you have to deactivate the old site (default) and add a new (mysite).

sudo a2dissite default && sudo a2ensite mysite

6. Restart Apache2:

sudo /etc/init.d/apache2 restart

7. Then open with gedit /etc/apache2/envvars:

sudo gedit /etc/apache2/envvars

8. Find export APACHE_RUN_USER=www-data and export APACHE_RUN_GROUP=www-data. Replace it to 

export APACHE_RUN_USER=username export APACHE_RUN_GROUP=username

 

9. Restart Apache2:

sudo /etc/init.d/apache2 restart

I hope this tutorial has been useful to you

 

 

export APACHE_RUN_USER=stleon
export APACHE_RUN_GROUP=stleon

 

 

export APACHE_RUN_USER=stleon
export APACHE_RUN_GROUP=stleon

 

 

export APACHE_RUN_USER=stleon
export APACHE_RUN_GROUP=stleon

 

# export APACHE_RUN_GROUP=www-data
Comments
jamied_uk 10 years ago

great tut but what if i want to add another site keeping the current site @ /var/www/ (and use say another port aswell as my other site on the standard port 80 how can i achieve this without loosing my original default apache2 site? or perhaps even having it goto localhost.site2 instead of localhost 1 out of these 2 options would be amazing is it possible to do this at all? (on the same a[ache server)?


ciaobello 10 years ago

I like this tutorial. Just got a error when i wanted to restart apache:
* Restarting web server apache2 ... waiting /var/lock/apache2 already exists but is not a directory owned by ciaobello.
Please fix manually. Aborting.

I fixt it manually with:
sudo chown -R ciaobello:ciaobello /var/lock/apache2


trollboy 12 years ago

I prefer to keep my sites out of my home directory but this would work if you want to keep your sites in your home.