RSS
 

Setting up a basic web server using Ubuntu 9.10 (Desktop)

12 Nov

Ubuntu LogoI have been using Ubuntu 9.10 for a while and wanted to see how it performs as a web server. The GUI interface is very slick and it is an ideal OS for beginners and advanced users alike. I suspect that many people will want to use it as the basis for their webservers.

I suggest creating a virtual machine with something like VirtualBox for this. It is much more flexible that way, and you can move it to a more powerful machine if you decide you need to.

Phase 1. Install required applications:

  1. Open ‘Synaptic package manager’ from the System/Administration menu.
  2. Click the ‘Search’ button.
  3. Enter ‘Apache’ and press return.
  4. You will see an item called ‘Apache2′ in the list of results. Click the box to the left to mark it as something you want to install.
  5. Repeat this process for:
    • Php5
    • MySql
    • Php5-mysql
  6. Click the ‘Apply’ button on the toolbar.
  7. This will start the installation process, during which you will be prompted to provide a password for the MySQL root account. Supply a strong password and make sure you do not forget it.
  8. It worked!When everything has finished installing, I suggest rebooting. There are ways of starting the servers without rebooting, but a reboot works just as well and is much easier.
  9. After you have logged back in to Ubuntu, open up Firefox and visit http://localhost.
  10. You should see a page that says “It works!” which means that your webserver is now working.

Phase 2: Configure Virtual Hosts (So you can have more than one site on your server)

I have chosen to use the command line to do much of this phase rather than the GUI. For me, it is much easier to access protected system files from the shell rather than use a GUI. However, should you want to use a GUI, you will need to be running with root privileges. You can do this by entering: sudo nautilus in to a command line (and enter your password). However, the instructions below are for using the shell.

Any time you see the sudo command, that means that you will run the command as root (administrator). Linux is much more secure than Windows thanks to it being locked down by default with a standard set of permissions. It might seem like hassle to keep having to switch to be administrator but it makes things much safer. Deal with it!

  1. Open a new Terminal from Applications / Accessories in the menus.
  2. In the terminal, enter the following commands and review the results so you know what you are doing.
  3. cd /etc/apache2/sites-enabled (this moves you to the folder where you can define different websites)
  4. ls (lower case LS: this will show you a list of files)
  5. sudo cp 000-default 001-mysite (this will copy the default config file so you can use it as the basis for your new site)
  6. Enter your password when prompted (this should only happen once, but if you are prompted again – just re-enter it)
  7. sudo gedit 001-mysite (this will use the gedit text editor to open and allow you to edit the new site config file)
  8. Change the ServerAdmin row to use your email address. ie. ServerAdmin sam@mysite.net
  9. Add a row below with the tag: ServerName followed by the name of your site. I will continue to use mysite.local throughout. ie. ServerName mysite.local
  10. Edit the row DocumentRoot so that the new path is a sub-folder of www called 001-mysite. ie. /var/www/001-mysite
  11. Edit the row <Directory…> so that the new path is also used. ie. <Directory /var/www/001-mysite>
  12. Save the file and closed GEdit.
  13. A working PHP virtual hostWe now need to let your computer know that it IS mysite.local. The easiest way to do this is to edit your hosts file. There is plenty of information online about what this file does.
  14. From the terminal, type: sudo gedit /etc/hosts
  15. Add a new row below 127.0.0.1    localhost that reads: 127.0.0.1     mysite.local (spaces are tabs).
  16. Save the file and close GEdit.
  17. Now we need to create the file structure for where the sites files will live.
  18. Enter: sudo mkdir /var/www/001-mysite (this will create a new folder that will store your php/html files etc)
  19. cd /var/www/001-mysite
  20. sudo gedit index.php (this will open the text editor again and will allow you to create the index page for your site).
  21. In the text editor, enter the following bold text (including all the punctuation): <?php phpinfo(); ?>
  22. Save the file and close.
  23. sudo /etc/init.d/apache2 restart (this restarts the Apache service so that the new virtual host is available)
  24. Now open firefox and visit your new site: http://mysite.local
  25. You should see a whole load of information about your server, and more specifically about your PHP installation.
  26. Thats it! Repeat this phase to add as many virtual hosts as you like.

You will now almost certainly want to secure your server. If you have got this far then you can at least get your site(s) up and running on your local machine. Ill cover securing your server in another post.

  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • MySpace
  • Twitter
  • RSS
  • StumbleUpon
 

Tags: , , , , ,

Leave a Reply

 
 
  1. tApacheLogInput: Apache Logfiles in TOS einlesen - Dijit

    November 12, 2009 at 6:39 pm

    [...] GET DOWN TONIGHT – Setting up a basic web server using Ubuntu 9.10

     
  2. Sam

    November 16, 2009 at 5:31 pm

    Just found this great video setting up a webserver using the tasksel command in Ubuntu 9.10 on YouTube.

    http://www.youtube.com/watch?v=J8y51yESHyU