Install and Configure Ubuntu Server as a Web Server

I have recently started looking into Ubuntu server. All my experience has been with Microsoft and I have never really gone “out of the box” so to speak. I have installed Ubuntu desktop on a laptop before and configured compiz and a few basic things but never really looked at it as a server.

We are currently looking at hosting some “microsites” in the office, these are for news stories that appeared on the front page of the Firms website, that were then replace by another more recent story, our “"Well rounded views”. so the request came to IT to look at creating and maintaining these “microsites”. We did not want to put it with the company that was hosting our main website as that would incur an extra fee and for what it was they didn’t really want to spend any extra money, so I thought we could potentially use Ubuntu Server to host it, that way there is no licensing cost and we can run several websites/microsites on the one box.

So I downloaded the latest version of Ubuntu Server from www.ubuntu.com and installed it on a spare HP Compaq D530 desktop that I had under my desk. The install wasn’t a GUI install like Ubuntu Desktop but reminded me of the early days of when I started looking into Linux, although more straight forward than then!

Apache, MySQL and SSH Server was installed with the server install so that was all ready to rock ‘n’ roll.

I decided to split this post in to several parts:

  1. Remote Access to the server
  2. installing and configuring FTP
  3. Creating new websites
  4. MySQL admin
  5. Other

 

1. Remote Access to the Server

The next step was what do I do now? First things first I downloaded putty from: http://www.chiark.greenend.org.uk/~sgtatham/putty/ this is a free Telnet/SSH Client this mean I could run the commands from my desktop instead of having to use the physical console on the server:

2.Installing and configuring FTP

imageNow putty was connected I could run the commands I needed to run.

My first thought was, if I have this as a website, how am I to upload the files on to it? Answer ftp so I needed to install ftp on the box. Simple command to install vsftpd on Ubuntu is:

sudo apt-get install vsftpd

It will then ask you for your root password this is the password you use with your user account when you log in.

The next thing you need to do is allow access to authenticated system users to allow them to upload files. for this you need to edit the vsftpd.conf file. this can be done by typing in:

sudo nano /etc/vsftpd.conf

again enter in your admin password if you are prompted to and then a text editor will load with the vsftpd.conf file open for editing. make the following two changes:

local_enable=YES

write_enable=YES

Save and exit from nano by pressing ctrl + x. now you need to restart vsftpd. this is done by the following command:

sudo /etc/init.d/vsftpd restart

you are now ready to use your favourite ftp client to upload files to your server.

I created a folder in my user home directory for websites, as I was so used to IIS I named it to wwwroot mainly without thinking, but it is pretty descriptive.

The thing I noticed initially was that I was unable to view the folders and files I uploaded later on once I had created the website. This was down to the file and folder permissions. So what I needed to do on the server was set the permissions on the wwwroot folder by:

sudo chown -R andyk /home/andyk/wwwroot/

sudo chmod u=rwX,g=rX,o=rX /home/andyk/wwwroot

I only did this the once. On the top level

I then when I either create a new folder or upload new files have to set the permissions to 755 through my FTP client on the folder in question and all sub folders and files, this is a pain but hey its gets it all working.

3.Creating new websites

Now that I could upload files on to the server I needed to actually be able to create webistes. I was so used to IIS where it is just a case of right click and select create new website. I was thinking I was getting in to this a little too much and “in over my head” as they say. but to my surprise it was quite straight forward! The way the sites work is they are based on a configuration file that hold the info about them. the way to create a new site was to copy the existing site that was there by default and then edit the copied site, simple!

sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/newsitename

once you have done that all you need do is make a few changes in the newsitename file through nono:

sudo nano /etc/apache2/sites-available/newsitename

Then, under the ServerAdmin you will need to put the following:

ServerAlias newsitename

ServerAlias www.newsitename.com

the file will also handle wild cards so if you have registered .com, .co.uk,net etc… then you could use:

ServerAlias www.newsitename.*

The DocumentRoot should be where the folder was created in your ftp uploads in my case it will be:

/home/andyk/wwwroot/newsitename

You will need to do the same with the <Directory /var/www/> line so mine looks like:

<Directory /home/andyk/wwwroot/newsitename/>

Press Ctrl + x to save and exit from nano and then type the following:

sudo a2ensite newsitename

This will then enable the site ready for you to use it.

4.MySQL Admin

I tried creating a database using the mysqladmin command but to no avail. jsut as I was about to give up I discovered the phpmyadmin. This is a Web Interface that enables you to manage your MySQL databases and create and delete DB’s. To install all you need type is:

sudo apt-get phpmyadmin

follow all the prompts and enter in the credentials for MySQL when prompted to. and hwy presto, that’s it you can now do everything from the Web Interface: http://servername/phpmyadmin and entering your log on credentials there to start creating, deleting and managing your MySQL Databases.

image

5.Other

Now I have my server up and running I have started to play around with open source products like wordpress and drupal. Wordpress is a very straight forward blog engine that enables you to create a blog and change the style and theme very easily. Drupla is a more powerfull CMS that I am still learning to use.

Both these can be freely downloaded from the internet.

Bookmark and Share

Comments

Gravatar # re: Install and Configure Ubuntu Server as a Web Server
Posted by ubuntuguy on 08/01/2010 16:13
you should use webmin for managing ubuntu server also your file permissions dont look save

Post Comment

Title *
Name *
Email
Url
Comment *  

Please add 3 and 7 and type the answer here: