Updated 18 Nov 2013
Getting started * Download, compile and install Apache * Get Apache up and running * Configure Apache to host multiple websites
You will most likely want to install a web server to serve up your website(s). Apache and Nginx are the two most common. There may be more documentation and examples for Apache, but perhaps Nginx is faster and uses less memory when you're dealing with a huge volume of visitors.
You will need to know how to create, delete, and modify Apache or Nginx virtual hosts for each website on your server.
If you expect a lot of traffic to your site you may also want to install Varnish, Memcache, or other caching programs to optimize performance.
The web's most widely-used web server is called Apache. It's open source and free to use.
Many commonly-used programs can be installed on Arch by issuing a simple pacman command. At the time of writing, Arch is still in the Arch User Repository (AUR), so it must be compiled and installed manually. (You could of course use Yaourt instead.)
Here you will download the Apache package from the AUR direct to your VPS, compile it and then install it.
First off, for the sake of tidiness, create a directory where all future build packages can be downloaded to.
The above commands create a new directory called 'builds' under the root directory and ls lists the contents under the root directory. There should now be a builds directory in there. Make it the current directory:
Now find Apache on the AUR. Point your browser to aur.archlinux.org. Input 'apache24' into the package search box. (Apache 2.4 is the most recent version at the time of writing.)
The search will return a couple of relevant results. You are looking for the one with the description A high performance Unix-based HTTP server. Click through to the package details.
Assuming that you're accessing the AUR from your local browser, you'll need to download the tarball directly to your VPS and not to your local machine. So don't click but copy the download tarball link. Then from the command line use curl and paste the link in. It should look something like this:
curl gets the content of a URL and displays it in the command terminal. But used with the option -O (capital o), curl will save the URL's output to a file in your VPS' filesystem, and will use the URL's filename (apache24.tar.gz) as the name of the saved file.
Issue the command man curl to read more about curl.
Because the builds directory is the current directory, you should find the tarball (apache24.tar.gz) there. Use the command ls to list the directory's contents:
The tar (tape archive) command is used to convert a group of files into an archive. An archive is a single file that contains individual files plus information to allow them to be extracted to their original form. Although tar was originally designed for backups on magnetic tape, it can now be used to create archive files anywhere on a filesystem.
Archives that have been created with tar are commonly referred to as tarballs.
tar does not perform compression itself. apache24.tar.gz is a tarball compressed with a utility called gzip, hence the .gz at the end.
To extract the archive of files inside apache24.tar.gz issue the command:
where -x means extract, -v (verbose) will display the files in the archive, -z means decompress with the gzip utility, and following the -f will be the tar filename to be extracted. Here's what to expect:
The extraction process created a directory under builds called 'apache24' and inside this are Apache's files, including the all-important PKGBUILD. The PKGBUILD file is used by the command makepkg, which uses the instructions contained within it to create a pacman-installable, binary package with the extenstion '.pkg.tar.xz'.
The -A option ignores the target Arch architecture. The -c option cleans up the directory after makepkg is done, and -s installs any needed dependencies automatically.
It may take some time to finish, but makepkg should have created a file inside the apache24 directory with the filetype .pkg.tar.xz. ls in long listing format (-l) should give the following files:
And there's the package: apache24-2.4.4-4-x86_64.pkg.tar.xz. Install this package by using the -U option with pacman (replace apache24-2.4.4-4-x86_64 with the actual package name in your case):
Great, you've got Apache installed on your VPS.
Apache needs a little bit of configuration before it will serve up your webpages. Navigate to Apache's configuration file and open it using Nano:
Scroll down through the file using CTRL+v until you get to Listen. Check that Listen is uncommented (no preceding #):
Scroll down to Servername and edit so:
Hit CTRL+o then ENTER to write your modifications and then CTRL+x to exit Nano. Now open up the hosts file:
Edit the line beginning 127.0.0.1 by appending your hostname (as defined in your VPS control panel) to the end. Then save and exit.
Open the hostname file and add your hostname underneath localhost. Save and exit.
Restart Apache to effect the changes:
Apache serves up webpages from the /srv/http directory. It will look for a page called index.html by default, which will serve as your website's homepage. Edit the default index.html page:
Your first webpage should be something nice. Try this old chestnut (if you must):
Save and exit. Then point your browser to your VPS' IP address and voila!
Using Apache, you can run many websites on the same server using the same IP address, even for different domains. This is called name-based virtual hosting. First, configure httpd.conf to allow virtual hosting:
Scroll down through the configuration file using CTRL+v until you get to #Virtual hosts. Uncomment the following line by removing the preceding hash #:
CTRL+o then ENTER to write and then CTRL+x to quit Nano.
Suppose you have registered two unique domains called yourdomain1.com and yourdomain2.net. You will need to update the DNS records for each domain name so that they point to the nameservers of your VPS hosting company. This is done through your VPS' control panel and also through the control panel of your domain registrar (where you bought the domains).
Access your VPS' account control panel. You should be able to add domains to your VPS. Add both yourdomain1.com and yourdomain2.net. Check your VPS host's nameservers in the domain properties. (The records you're looking for are the NS records.) There will be at least two, maybe three nameservers (in case one goes offline, there is a backup so your domain name can still be resolved). They should look something like ns1.yourVPShost.com, ns2.yourVPShost.com.
Also check that both domains have an 'A' record pointing to the IP address of your VPS.
Then access your control panel at your domain registrar. You will need to configure each domain so that it points to the aforementioned nameservers.
While you're waiting for your domain registrar to effect the changes (which can take a few minutes to several hours), configure Apache's virtual hosts configuration file httpd-vhosts.conf to tell Apache about your domains:
Delete the existing lines of virtual host examples (using CTRL+k) and replace them with the following:
ServerAlias www.yourdomain1.com 123.45.678.90
CustomLog "/var/log/httpd/yourdomain1.com-access_log" common
CustomLog "/var/log/httpd/yourdomain2.net-access_log" common
DocumentRoot is the directory from where the domain's webpages will be served from. To keep things organised between websites, you should create your own directory structure inside the /srv/http directory. In my case, I created a subdirectory called www, and then further subdirectories for each website, a yourdomain1.com directory and a yourdomain2.net directory.
Now, as per the configuration above, when you go to yourdomain1.com (or the alias www.yourdomain1.com), Apache will serve the files from the /srv/http/www/yourdomain1.com directory.
When you go to yourdomain2.net (or www.yourdomain2.net), the same Apache running on the same server will serve the files from the /srv/http/www/yourdomain2.net directory.
Notice that in ServerAlias for yourdomain1.com I also included the IP address 123.45.678.90 of the VPS. In case someone physically types the IP address into a browser, Apache will serve yourdomain1.com as default, and not yourdomain2.net.
CTRL+o then ENTER to write and then CTRL+x to quit Nano. Restart Apache to effect the changes:
Try it out by putting your different website addresses into your browser. (Of course, each website directory should have an index.html file in it first.)
If you want Apache to start when your VPS boots up issue the following command: