Today I will be showing you how to setup a virtualized cloud server on rackspace.com cloud hosting, using an Arch Linux base install. After we get the virtual machine up and running with Arch, we’ll install the Apache, PHP, and MySQL web server stack to get a web server running.
If you don’t know, Rackspace is a cloud-based virtual machine hosting service (among other things). This means they allow you to set up and run virtual machines with a dedicated IP addresses, which you can access from anywhere on the web, and have full control to configure, make changes, install software, and so forth, just as if you had a dedicated box connected to the internet. This gives you the benefits of virtualization with the added bonus of reliability and scalability, with most of the networking pains taken away and no need for hardware.
First things first, register for a free cloud-server account at rackspace.com (this link uses our affiliate code, so we prefer you go through that url to help us!). It’s free to sign up, but they do require a credit card so that they can automatically bill you for any charges you do incur. Charges are based on the number of and types of server instances you have running and the bandwidth they use. FOLLOWING THIS TUTORIAL WILL INCUR CHARGES OF A FEW CENTS.
The cheapest option is a 256MB RAM, 10GB disk server instance, which costs $0.015 per hour while it is running – that’s 1.5 cents per hour, or about $11 per month if left running continuously. This option is adequate for this tutorial. Bandwidth is rated at $0.18 (18 cents) per outgoing gigabyte and free for incoming bandwidth. To put things in perspective, running the steps of this tutorial, downloading and installing additional packages and playing around with a server instance over the course of a day, with a total of 0.01 GB out and 0.16GB in, has cost me $0.27 (27 cents). As you see, cloud-hosted virtualized servers are very cheap, and allow you to easily scale up and down as your needs change.
Ok, so you’re signed up. Now you need to log in and create a new server instance. Go to www.rackspace.com and hover over the Login button on the top-right of the page, and click the Cloud Control Panel option that appears. You’ll be taken to the initial Control Panel homepage with an overview of your bandwidth usage (and Disk space for Cloud Files – more on that later). There is a tab at the top called “Getting Started” which has some very useful and concise descriptions of various features and terms; I highly recommend reading through it. Let’s get started setting up our server. Click the Hosting button on the left-hand menu, and then click the Cloud Servers option the appears below it. This will take you to the Cloud Servers page where you can create and manage different server instances and get some overview of each one (Status, Name, RAM Amount, IP Address, Operating System, etc.)
Clicking the “Add Server” button will first bring us to a page where we select a base-image containing the operating system we want to install. There are several Linux and Windows options available, but for this tutorial we will go with Arch Linux (side note: Windows and Red Hat Enterprise Linux options have additional license fees; be aware).
Now we want to give our server a name and select a size for the virtual machine instance. The available options are listed along with their hourly rates. Select the first/cheapest (256MB RAM with 10GB disk), then click “Create Server”. Now we’re taken to the Server Details Page where the status will indicate the system is building. This may take up to a few minutes but it is generally very fast, depending on their overall load and other factors. Give it just a moment and after the server builds we’ll be given randomly generated root password for the system. Then we’ll be able to log into the machine via ssh and start setting up the LAMP stack.
Once the status becomes Active and we are given the root password, we can connect to the system. The web-based console will work but performance is lackluster, so I recommend using ssh, putty, or whatever terminal client you prefer. Unfortunately I’m on a Windows box today so we’ll be using Putty. Get the IP Address to your server from the details overview page and connect to it. Log-in as root using the provided password and you’ll get a nice prompt. The first thing we want to do is update the system, which may cause a bit of trouble if your experience is anything like mine; not to worry, we’ll get through it. Run pacman -Syy first, to sync up repository databases. Next we need to update pacman, initialize our keyring, import package keys, and then do a system update.
#pacman -S pacman
#pacman-key --populate archlinux
#pacman -Syu --force
You may experience complaints about existing files related to glibc when you run pacman -S pacman:
glibc: /usr/bin/tzselect exists in filesystem
glibc: /usr/sbin/zdump exists in filesystem
glibc: /usr/sbin/zic exists in filesystem
Renaming those files one by one before running pacman -S pacman does the trick without issue:
#mv /usr/bin/tzselect /usr/bin/tzselect.bak
#mv /usr/sbin/zdump /usr/sbin/zdump.bak
#mv /usr/sbin/zic /usr/sbin/zic.bak
One thing to know is that pacman-key –init depends on entropy in the system to randomize seed input and generate keys – this can take hours if you do not have a busy system. Open a second ssh session in another terminal and run commands like ls -alR / over and over to cause disk and cpu activity on the system and speed up the process to a couple of minutes or less. After the key is generated, run pacman-key –populate archlinux and answer yes to the prompts about signing with the 5 master keys.
Now run pacman -Syu –force. Pacman may complain about mtab and other filesystem related files due to changes in structure from versions of Arch. Adding the –force to pacman -Syu should resolve this. The system upgrade will prompt about replacing some packages with others. Select Yes [y] to each of these, and wait for it to finish. If you experience issues here, consult the Arch wiki, forums, or IRC channe l#archlinux on irc.freenode.net. Rackspace has free 24/7 live-chat support that is very helpful also.
Edit & Warning: the above steps may potentially break the system and render it useless by breaking the package manager and filesystem due to changes in recent system updates. Before following these system update instructions, please read the following links:
And as always, check archlinux.org for the latest news, updates, and upgrade information before performing system updates. Thanks to Scott Dunlap (@swdunlop) for pointing out this issue.
Now it’s time to install our LAMP server packages. Run the following:
#pacman -S apache php php-apache mysql
We now have the LAMP server components installed! All that is left is to configure them.
and look for the line under NETWORKING that says HOSTNAME=”…” which is probably set by the rackspace configuration as the name you gave the virtual server. Now we need to apply that hostname to our localhost in /etc/hosts.
Find the lines that looks like
127.0.0.1 localhost.localdomain localhost
::1 localhost.localdomain localhost
and add the value in HOSTNAME from /etc/rc.conf on the end of those two lines (the second is for ipv6). So if, for example, your hostname is test, they will now look like
127.0.0.1 localhost.localdomain localhost test
::1 localhost.localdomain localhost test
Now save the file and run
#rc.d restart httpd
to start Apache. Hopefully you get a nice bright “DONE” and now you are running.
Open a browser and put in the IP address of your server, you should get an empty directory listing. Put your html and other files inside /srv/http to view them via the web using your servers IP address.
Stay tuned for part 2, where we will setup a free .tk domain name and use DNS configuration to map it to our server. Also, we will setup php and mysql, and use a more secure and robust configuration for Apache. Thanks for reading. Here are some useful links: