Apache local servers
Here's the problem; you're responsible for maintaining a website (or maybe more than one), but you want to test out changes before you unleash them on the unsuspecting world.
With gNewSense GNU/Linux you have an incredibly powerful and flexible system which you can use to test and develop websites. One of the great things about running gNewSense on your desktop is that you can test and develop in essentially the same environment that most of the internet runs on.
If you follow this article then you should end up with one or more local virtual servers to develop your websites on with local and meaningfull URLs.
What you will need.
gNewSense GNU/Linux installed on your computer. This how-to is based on gNewSense 1.1.
You will need to install the Apache webserver. You can use a package managerlike Synaptic, or simply type the following in Terminal.
sudo apt-get install apache2
You will be asked for your password, this will be the same one that you use to log into gNewSense. This assumes that you have admin rights on your computer and that you are connected to the internet.
To complete the instructions in this article you will only need Apache, though of course there are database servers, PHP, PERL and many other things available in gNewSense.
What you will end up with.
You should end up with the Apache webserver running on your computer with one or more test websites for you to experiment with.
You will be able to access your test websites using an easily remembered URL. eg. for my live website I put the following into my web browser:
http://www.andrew-wigglesworth.co.uk
My local test site (ie. not on the internet) is at:
http://wwww.andrew-wigglesworth.loc
Decide where you want your test sites on your computer.
First need to create directories for your test sites. This is where you will eventually place the HTML, PHP etc. for your test websites.
Where you put the test sites is up to you. However, they should be directories somewhere in your home directory so that you have all the correct permissions and can find them easily.
For example, on my computer they are at:
/home/ecadre/websites
With each test website in a directory below that. eg.
/home/ecadre/websites/site1/home/ecadre/websites/site2/home/ecadre/websites/site3Configuring Apache.
Next Apache needs to be set up. Editing the Apache configuration is a bit complicated, but still reasonably easy.
The Apache webserver configuration files are in the following directory:
/etc/apache2
What you are going to do now is to create what is known as a "Virtual Server". Virtual Servers are separate websites run from the same Apache webserver installation. For this it is easiest to open up a Terminal session and do the configuration on the comand line. If you've never used the command line, take a deep breath, this is where much of the power of gNewSense GNU/Linux lies.
Open up Terminal if you are using the Gnome desktop or Konsole if you are using KDE. First, cd (change directory) to the directory that you need to work in:
cd /etc/apache2/sites-available
Type the above into Terminal and press the enter key.
In this directory there is a file named "default", you need to make a copy of that file under a new name. This will be the configuration file for your new Virtual Server.
sudo cp default site1
You need to use "sudo" comand since this is a system directory outside of your home directory. You need superuser privileges to work with system files and directories.
After entering the command, you will be asked for a password. Type in your user password (the one that you use when you log in to gNewSense) and then press "enter". Please note that you will not be able to see your password on screen as you type; this is a security feature.
cp is the instruction meaning "copy". You will now have a new file named "site1". You can name this file more memorably if you like. ie. reflecting what you are going to use your new Virtual Server for.
Remember to substitute that different name when following these instructions and don't leave any gaps in the name. ie. use "my_website", NOT "my website".
Nano is a simple text editor that you can use to edit this new configuration file. To open up "site1" in nano, use the following command:
sudo nano site1
The "sudo" comand means that you have opened up the file with root (or "super user") privileges. You need to do this since you are editing a file outside your home directory; in a gNewSense system directory.
After entering the command, you will be asked for a password. Type in your user password (the one that you use when you log in to gNewSense) and then press "enter". Please note that you will not be able to see your password on screen as you type; this is a security feature.
Whilst editing the site1 file, use the cursor keys to navigate and type as you would normally. If you make a mess of things press ctrl+x (hold down the ctrl key and press the x key) and answer "no" to saving the file. This will close the Nano editor without saving the file and you can start over again.
Editing the site1 Virtual Server configuration -- what to change.
Delete the first line;
NameVirtualHost *
Replace:
<VirtualHost *>
with
<VirtualHost 127.0.0.2>
Since this is the first Virtual Server that you are configuring, it's IP address will be "127.0.0.2". Subsequent Virtual Servers that you create will need to be numbered by changing the last number sequentially. ie.
127.0.0.3127.0.0.4127.0.0.5
and so on.
Change the line where it says
DocumentRoot /var/www/
so that it points at the site1 directory that you created earlier. The line will now read something along the lines of
/home/yourname/websites/site1/
Change the line where it says
<Directory /var/www/>
so that it also points at the site1 directory that you created earlier. The line will now read something along the lines of
<Directory /home/yourname/websites/site1/>
This is all you need to change in the configuration to get the basic test website going.
You've now finished editing the site1 file, so it can be saved and closed. In Nano, press ctrl+o (hold down the ctrl key and press the o letter key). You are then prompted for a file name to save as, however, this will be pre-filled with the name "site1". Therefore you just need to press "enter" to accept and save the file. Now you can press ctrl+x to close Nano.
OK, we're nearly there with the Apache configuration.
Enabling your new virtual server
The last thing to do for the Apache configuration is to enable the new Virtual Server. To do this you need to create a symbolic link to the site1 file. This symbolic link will be in the "/etc/apache2/sites-enabled" directory.
To make the symbolic link, do the following. In your Terminal session, change directories to the "sites-enabled" directory:
cd /etc/apache2/sites-enabled
Then use the following comand to create a symbolic link to the site1 file in the "sites-available" directory:
sudo ln -s /etc/apache2/sites-available/site1 000-site1
You may have to put your password in again. You've now created a symbolic link name 000-site1 that directs Apache to your site1 configuration file.
To get Apache to accept your new Virtual Server, you need to restart Apache:
/etc/init.d/apache2 restart
To test whether your Virtual Server is working, place an index.html file with some wording in it in your Virtual Server's DocumentRoot. This is the directory that you originally set up to hold your servers files.
Now, when you put:
http://127.0.0.2/index.html
into your web browser you should see your html file.
Go through the whole procedure for each of the sites that you wish to set up. Remember that you do not have to use site1, site2 etc. , these are just example names. Also remember that you need to use a different IP address for each site as detailed above.
Setting up memorable URLs instead of numerical IP addresses.
For this you will be using the command line and Nano again. The file that needs to be edited is the hosts file. This is where you can get particular domain names pointed at a particular IP address.
Open up your hosts file for editing by entering the following on the comand line in Terminal:
sudo nano /etc/hosts
All that you need to do is to add some extra lines. At the top of the hosts file, create a new line and enter the following:
127.0.0.2 site1.loc www.site1.loc
As noted earlier, you will probably want to enter your own name for your Virtual Server. In that case, replace "site1" with whatever you like. The ".loc" is also optional, but I think it it serves a purpose. It is not a top level domain that you will find on the internet and it reminds you where you are! In particular, that you are on your test server, not the internet.
For further Virtual Servers, add more along these lines:
127.0.0.3 site2.loc www.site1.loc127.0.0.4 site3.loc www.site1.loc127.0.0.5 site4.loc www.site1.loc127.0.0.6 site5.loc www.site1.loc
These are the same IP addresses that you set up in the corresponding Apache server configuration files.
Use ctrl+o (hold down the ctrl key and press the letter o) to save the hosts file and ctrl+x to exit Nano (see earlier in this article for more details about using Nano).
Now, when you put:
http://site1.loc
or
http://www.site.loc
into your web browser, your computer will fetch your test Virtual Server. Rather more memorable that typing 127.0.0.2.
More advanced configuration
These instructions will give you a simple virtual webserver that can show simple html files. This is enough for most websites, however, you may wish to try PHP or other technologies on your websites.
All this is possible but beyond the scope of this present article. See below for more help.
END
Got problems, or need more help?
Go to the gNewSense website: http://www.gnewsense.org. There you can use the Wiki or join the gNewSense mailing list
You can also try the #gnewsense IRC (internet relay chat) channel on Freenode.