Apache2 on Ubuntu – Hosting multiple websites

Create directories for a new site. E.g.
/var/www/sites/mysite.com/htdocs
/var/www/sites/mysite.com/logs
/var/www/sites/mysite.com/cg-bin


In /etc/apache2/conf.d/ create new file virtual.conf
#
# Running multiple virtual hosts.
#
NameVirtualHost *


/etc/apache2/sites-available
This contains configuration files for sites which are available but not necessarily enabled.
/etc/apache2/sites-enabled
This directory contains site files which are enabled.
Each configuration file in the sites-enabled directory is loaded when the server starts - whilst the files in sites-available are ignored.
Configuration files should be created in sites.available and later enabled running a2ensite command if needed (see bellow).

Create /etc/apache2/sites-available/www.mysite.com with the following contents:

<VirtualHost *>
ServerAdmin This email address is being protected from spambots. You need JavaScript enabled to view it.
ServerName  www.mysite.com
ServerAlias mysite.com

# Indexes + Directory Root
DirectoryIndex index.php index.html
DocumentRoot /var/www/sites/mysite.com/htdocs

# CGI Directory
ScriptAlias /cgi-bin/ /var/www/Sites/mysite.com/cg-bin
<Location /cgi-bin>
Options +ExecCG
</Location>

# Logfiles
ErrorLog  /var/www/sites/mysite.com/logs/error.log
CustomLog /var/www/sites/mysite.com/logs/access.log combined
</VirtualHost>

Enable site:
a2ensite www.mysite.com
(To disable - a2dissite www.mysite.com)
This puts symbolic link in sites-enabled

Restart apache:
/etc/init.d/apache2 reload

In addition (after change from one website to multiples):
Delete: default in sites-available and 000-default in sites enabled

Default site:
One of the sites is a default site. Default site is loaded when server can't match URL address.
It looks like the default site is the one which comes first in alphabetical order in sites-available folder. 

To stop warning NameVirtualHost *:80 has no VirtualHosts when reloading apache
/etc/apache2/ports.conf
Comment:
#NameVirtualHost *:80

To stop warning apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName when reloading apache
/etc/apache2/apache2.conf
Add Line:
ServerName www.mysite.com


Ubuntu Server 10.10

Ubuntu server network stops working after moving to another VMware host

Delete:
/etc/udev/rules.d/70-persistent-net.rules

Restart machine
This will update the MAC address

Set up Ubuntu Web Server

Install LAMP (Linux-Apache-MySQL-PHP)

Select LAMP option during installation.
or
sudo tasksel install lamp-server

default WWW root folder
/var/www

To restart apache:
sudo /usr/sbin/apache2ctl restart

Install phpmyadmin

sudo aptitude install phpmyadmin
address:
http://serverip/phpmyadmin/

If installation was successful, but browsing to the above address you are getting "Not Found" error, try to create a symbolic link phpmyadmin pointing to /usr/share/phpmyadmin your /var/www . You can do this by running:
sudo ln -s /usr/share/phpmyadmin /var/www

Install FTP server

sudo apt-get install vsftpd

config file: /etc/vsftpd.conf
Change
anonymous_enable=YES
change to NO
#local_enable=YES
Uncomment
#write_enable=YES
Uncomment

Default FTP directory:
/home/username/

To change default directory:
/etc/vsftpd.conf
Add line:
local_root=/your/directory

/etc/init.d/vsftpd stop
/etc/init.d/vsftpd start


Change permissions of ftp directory
chmod -R 07555 /your/directory

Install SSH server

sudo apt-get install openssh-server
sudo /etc/init.d/ssh restart


Install SendMail

sudo apt-get install sendmail

If SendMal is very slow to send emails (can take 2-3 minutes) check following:
/var/log/mail.log
you may have entries like this:
My unqualified host name (localhost) unknown; sleeping for retry
This means SendMail is looking for FQDN (fully qualified domain name) and can't find it.
Check your /etc/hosts file
Make sure you have FQDN as the first entry pointing to 127.0.0.1, e.g.
127.0.1.1   mail.mydomain.com localhost.localdomain localhost SERVER-NAME

For testing purposes you could use localhost.localdomain, e.g.
127.0.1.1   localhost localhost.localdomain SERVER-NAME
However it's better not to do it on a live server as this violates some email standards and your IP may get blacklisted as a SPAM sender.

Set Static IP

sudo nano /etc/network/interfaces
Change #The primary network interface with your details
auto eth0
iface eth0 inet static
address 192.168.0.100
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
gateway 192.168.0.1


sudo nano /etc/resolv.conf
domain domain-name
search
domain-name
nameserver 192.168.0.5
nameserver 192.168.0.6


sudo /etc/init.d/networking restart

Remove DHCP client
sudo apt-get remove dhcp-client
sudo /etc/init.d/networking restart


Install GUI for Ubuntu Server (Not recommended)


sudo aptitude install x-window-system-core gnome
To start GUI
sudo gdm

Enable root account (not recomended)

sudo passwd root

To disable root account
sudo usermod -p '!' root

Ubuntu Server 10.10
Ubuntu Server 11.04



Newsletter

Subscribe to receive occasional updates on new posts.
Your email will not be used for any other purpose and you can unsubscribe at any time.
Please wait
Privacy Policy