The following guide will help you to setup the hosts, in case you want to run multiple websites on your VPS. This is similar to setting up a shared server that hosts multiple websites, using a single shared IP address. Note: * This documentation assumes you've already installed the LAMP stack on your VPS. If you haven't done that yet, refer to the LAMP installation guide. * Ensure that you are connected to the server using an SSH client as a "root" user. * Website management becomes easier through cpanel and Plesk. If you have installed these panels, you need not follow this documentation. The process to host a single website is different from having multiple sites. Case 1 - If you want to host only one domain name in the VPS, then all you need to do is point your domain name to the IP address of the VPS. (This can be done by simply adding an A record from its DNS interface). By default the document root of your server is /var/www/html. You can upload the contents of your site in this directory, if you are planning to host only one domain name. Case 2 - However, if you want to host multiple domain names in the same VPS, then you would be required to create a virtual host entry in your Apache configuration file. Refer to the steps mentioned below. Host your websites Page 1
Step I Lets take an example of websites domain1.com and domain2.com. You'll first have to create folders for each under /var/www/html. You can create the folders from Plesk Power Panel's - File Manager or via SSH. The steps given below are using CLI (Command Line Interface). a. Navigate to the directory /var/www/html b. Create the directories for each website using mkdir command. c. Once directories are created (as shown below), we can proceed to the next step. Host your websites Page 2
Step II Open the Apache configuration file. Use command vi /etc/httpd/conf/httpd.conf Scroll down to the bottom of this file, uncomment the lines and add your domain names to the Apache conf as illustrated below. Host your websites Page 3
name-based virtual hosting explained NameVirtualHost - Designates an IP address for name-based virtual hosting. <VirtualHost> - Contains directives that apply only to a specific hostname or IP address. ServerAdmin - Email address that the server includes in error messages sent to the client. DocumentRoot - This directive sets the directory from which httpd will serve files for this host. ServerName - Used to uniquely identify the Virtual Host. This will be the your domain name in FQDN (Fully Qualified Domain Name) format. ServerAlias - This directive is used to set the alternate names for the host. ErrorLog - Location where the server will log errors for this host. If you want to learn more about Virtual Hosts or customize it further, you may refer to Apache Virtual Host documentation - http://httpd.apache.org/docs/2.2/vhosts/ Step III For the configuration changes to take effect, we'll now have to restart the Apache service. Host your websites Page 4
DNS configuration and Test Run The above three steps complete all the crucial settings for hosting multiple domain names. Further, to check how these sites will resolve or to test their functioning, we'll add sample html files. You can use the sample html script. -------------------------- <html> <head> <title>domain1.com's page</title> </head> <body> This is domain1.com </body> </html> -------------------------- Create the index.html files for domain1.com and domain2.com. Host your websites Page 5
If you are hosting a single domain name on this server, simply using your VPS' IP address will show up your site. However, if you have multiple sites and want to try this prior to setting up their DNS servers, you can edit your local computer's HOST file. Windows 7 and XP users can do this from C:\Windows\System32\drivers\etc\hosts Linux users will have to edit the following file /etc/hosts After opening these files in text editor, add IP address of your VPS followed by the domain name. e.g. 11.12.13.14 domain1.com 11.12.13.14 domain2.com For actual resolution over internet, create A records for each domain name pointing to the IP address of the VPS, in their respective DNS servers. Host your websites Page 6
Uploading via FTP You can upload the sites using any FTP client of your choice. To connect via a client, you'll need Host: <IP_address_of your_vps> Username: root Password: <root_user_password> (same as your VPS password) FTP Type: SFTP Port No.: 22 This complete setup is with minimal configuration; you can customize or secure your website further according to your needs. Host your websites Page 7