Patrick J Waters

  • sites
  • mobile
  • résumé
  • about
  • contact
  • blog

Home

My favorite web server setup, Ubuntu Server, LAMP, Webmin, and Virtualmin.

patrick — Wed, 07/13/2011 - 20:33

Over the past few years I have experimented with different web server setups. I have found that the combination Ubuntu,  LAMP (Linux, Apache, Mysql, and PHP), Webmin, and finally Virtualmin provide many advantages in my day to day workflow as a web developer. This setup provides me with an easy to use and easy to maintain web server that lessens the time spent configuring the server and increases my time programming. Here are my step by step instructions for setting up my favorite server configuration. 

Step 1: Install Ubuntu Server

Download and install Ubuntu Server edition. At the time of writing this 11.04 was the most current version. I prefer to use the most Current LTS release, so I will choose 10.04 for my install. When installing Ubuntu you can choose to install the LAMP stack if you wish and skip step 2. Just as a side note, the first time I set this up was on Ubuntu 8.04 and the steps have not really changed sense. 

Step 2: Install LAMP

First change to the root user by typing the following and entering your password.

patrick@ubuntu:~$ sudo su

Then to install the LAMP package type the following

root@ubuntu:/# tasksel

This will prompt you with a screen like the this

Use the the arrow keys to highlight the LAMP Package and press space bar. Next hit tab to jump to the ok button and press enter.

During this process you will be prompted to enter a root mysql password. I recommend choosing a mysql root password different than your current root/user password. That is pretty much it for installing LAMP. 

 

Step 4: Installing Webmin

Next we are going to install webmin. Webmin is a free peace of software that give you a web based interface for controlling different parts of your server. For example, if you wanted to change some php settings, you don't have to ssh into the server and edit you php.ini. You can do it all through webmin. I am not going to give a thorough tutorial on webmin, but I do recommend poking around in it, once it's installed. 

So first step to installing webmin is adding it's repo's to the ubuntu. It doesn't come in the prepackaged repos. So you are going to want to edit the file /etc/apt/source.list like so.

root@ubuntu:/# nano /etc/apt/sources.list

This will open a simple text editor. Use the arrow keys to get to the bottom of the file and add the following lines

deb http://download.webmin.com/download/repository sarge contrib
deb http://webmin.mirror.somersettechsolutions.co.uk/repository sarge contrib

Then hit cntrl-x and they y and then enter, to save the file.

Next run the following

root@ubuntu:/# cd /root/
root@ubuntu:~# wget http://www.webmin.com/jcameron-key.asc
root@ubuntu:~# apt-key add jcameron-key.asc
root@ubuntu:~# apt-get update
root@ubuntu:~# apt-get install webmin

This will now install webmin to your server. Once webmin is installed you can access it at https://YOUR.IP.ADDRESS:10000 (ex. https://192.168.1.100:10000) take note of the https. You will probably get a warning about the certificate note being trusted, this is ok. This happen because your https certificate is not signed by a company like veri-sign. Now go the that url and you should get a screen like so

You are going to now login with your root user and password. Note that Ubuntu does not set a password for the root user by default. You can do that by changging to the root user and typing 'passwd' and setting your password.

Once you log in you will get a screen like so

 

You have no successfully installed webmin! Click around there a lot of awesome features!

 

Step 5: Install Virtualmin

Next we are going to install a webmin module called Virtualmin. Virtualmin is a module that turns your server into a multi domain hosting platform. It organizes your websites files and folders automatically. It does a whole bunch of configuration automatically for you, like creates the necessary apache host files, creates a mysql database, and creates a linux user with ssh access. This is the module that I use the most. I rarely need to ssh into the server to mess with configuration. I can setup websites in seconds, it's a big time saver. So here is how you install Virtualmin. I have to admit the first time I installed it, it was a bit tricky, but I have done it so many times now, that I know all of the gotcha's and I hope this will make the process smooth for others as well.

Alright so you need to be logged into webmin and at the home screen. You will need to go and click on and expand 'wbemin' in top left hand corner and then click on 'Webmin Configuration' like so.

Next click on the 'Webmin Module'

Now go to this link http://www.webmin.com/vdownload.html and look for the 'Webmin Module Format' link. It will be a link that looks like this, but the version may have changed http://download.webmin.com/download/virtualmin/virtual-server-3.87.gpl.wbm.gz.

Once you have that link you are going to want to go back to the webmin configuration page you were at before and check the radio button labeled 'From ftp or http URL' and paste the link in the corresponding text field and click 'Install Module'.

 

Step 6: Configure Virtualmin

Virtualmin is now installed but needs to be configured. First we need to install apache2-suexec-custom. You need this so virtualmin can change apache's default directory to /home

root@ubuntu:~# apt-get install apache2-suexec-custom
root@ubuntu:~# cd /etc/apache2/suexec
root@ubuntu:/etc/apache2/suexec# nano www-data

replace the line "/var/www" with "/home" (without "" ). hit control-x then y then enter

root@ubuntu:/etc/apache2/suexec# apache2ctl restart

 

Next we need to set the MySQL root password in webmin. if you click on Servers > MySQL Database Server on the left hand side and enter 'root' for the login and your mysql password. Remember this is not your linux password, it's your mysql password that you set when installing LAMP.

 

Next we need to turn on some apache modules. Goto to Servers > Apache Webserver. You will see a 3 tabs click on 'Global configuration' and then lastly click on 'Configure Apache Module'. Now you are going to want to make sure you check 'actions', 'suexec', and 'rewrite' and click 'Enabled Selected Modules'.

 

Next you are going to want to click on Servers > Virtualmin Virtual Servers (GPL). This will take you to a Post Installation Wizard. You do not want to run through the wizard.  You are going to want to push cancel. This will take you to a screen like so and you are going to want to push 'Manage Enabled Features and Plugins'

Next we are going to turn OFF some features of Virtualmin. I have found that I only use a few key features and other features require further configuration. Uncheck  'BIND DNS domain', 'Mail for domain',  and 'Webalizer reporting'.

Finally click save and you will be taken to the new Vitualmin Configuration screen. You have now successfully installed Virtualmin!

Step 7: Setting up a website with Virtualmin

The next thing to do is add a new website/virtual server with virtualmin. Navigate to Server > Virtualmin Virtual Server (GPL). Next look for a button that says 'Add New Virtual Server Owned By:' and click that. 

 

This will bring you to a new screen with a form. Enter in the domain you want to host on your server, without the www, and enter an administrator password. This is all that is required, you can thumb through the other options, but you do not need to change anything else. Once you have the form filled out click 'Create Server;.

When you clicked create server Virtualmin did the following

-Created a new linux user on your server that you use to ssh and sftp into.

-Created a mysql database named the same as your domain without the '.com' or '.org' etc.  For example if the domain you created was test.com, then Virtualmin would create a database called 'test'.

-Created a new folder structure on the server. For example if you created test.com, you can navigate to /home/test/. Here you will find a folder called 'public_html'. This is your web root folder. 

 

Well thats it, let me know if you find any errors in my tutorial so I can correct them. I hope my tutorial help shed some light on a decent web server setup.

  • Share this
  • Tweet

Thank you!

Anonymous — Thu, 07/28/2011 - 15:45
I just wanted to take a moment to thank you for your work in putting together this excellent tutorial. It worked!! Please know that your efforts are very appreciated by at least one person out there! :o)
  • reply

I really have to second this!

Anonymous — Sun, 06/03/2012 - 20:08
Thanks so much for this write up, I really feel like I am starting to understand my ubuntu VPS now!
  • reply

Thanks You too

Anonymous — Fri, 07/29/2011 - 08:07
Hi, After scratching my head and scouring linode forums, your blog saved the day. props to you.
  • reply

Hello, thanks for this tutorial

Anonymous — Mon, 08/08/2011 - 10:10
You save my day... thanks... I create a domain following all your steps... i have some cuestions: *where i can modify a dns record? *i have 2 static ip... i can configure ip1--domain1 and ip2---domain2? thank you very much... greetings
  • reply

You need to install BIND9 on

patrick — Mon, 08/08/2011 - 11:00

You need to install BIND9 on your server. Webmin can manage bind as well. I will do a blog post on that soon hopefully,

  • reply

Install BIND9

Anonymous — Sat, 12/17/2011 - 13:26
like this :-) root@server: apt-get install bind9
  • reply

hi

Anonymous — Mon, 08/08/2011 - 15:02
hi thanks very much for for the tutorial rarely have i come across a tutorial on the web that is so logical 1 2 3 4 do this so that this happens then do this . Brilliant it worked a treat It has enabled me to get my ( virtukl V{PS server up and running with web min and virtual min installed ok One question tho my domain " example.co.uk " how do i point that to the correct place / do i point it to 1 the IP address of the VPS that WEbmin and virtual min are running under /on or 2 to the name servers of the company that supplying my VPS have given me ? (rackspace ) 3 or somehwere else ...... that relates to the locations tha virtual min has created ??
  • reply

You have two options, One is

patrick — Mon, 08/08/2011 - 15:14

You have two options, One is you can create your own name servers, or you can just point the domain at the ip address. Like I said above I need to add more to this tutorial about setting up name servers. Hopefully in a week or two I will expand on it.

  • reply

hello thanks for respond..

Anonymous — Mon, 08/08/2011 - 16:20
i install bind9.. finally i can configure ip1--domain1 and ip2---domain2... but i have problems with postfix, i cant send email with domain... the email send by hostname... its posible configure to send by domain1 and domain2 separatly? Forgive my english.... again thank you... greetings
  • reply

You are talking mail server

patrick — Mon, 08/08/2011 - 16:23

You are talking mail server configuration now, you can install postfix and webmin will allow you to controll the setting in postfix, but think you have stepped out side my confort zone. Check out this tutorial on setting a postfix mail server. http://www.howtoforge.com/virtual-users-domains-postfix-courier-mysql-squirrelmail-ubuntu9.04

  • reply

thank you again patrick

Anonymous — Mon, 08/08/2011 - 16:44
i read now a tutorial of postfix... greetings
  • reply

Thankssss

Anonymous — Tue, 08/16/2011 - 02:25
Thanks for very useful information
  • reply

How to access the newly created site?

Anonymous — Wed, 09/21/2011 - 03:39
This is my first time ever doing anything server related. I've followed your steps and everything is working -- or so it seems. I've created a new virtual server (in this instance test.com), but how do I access that from the browser on another computer on the local network? And, how can I access it with an ftp-client? This might be pretty obvious stuff but as I said, this is my first time ever doing anything server related and all I really want is just an easy testing environment :)
  • reply

access on local network

Anonymous — Thu, 03/08/2012 - 19:44
This may not be my place to post, but I couldn't resist. Go to your newly created webserver and type ifconfig at the command line. Near the top is usually the local ip address ie 192.168.2.8 Type this into a web browser on a local network machine and you should see the default page: Something like "It works" this is NOT your public ip address and will only work on the local network. To access your server from outside the local network is the subject of another tutorial - I hope. ciao Mike
  • reply

Changing root password

Anonymous — Wed, 10/26/2011 - 03:11
To change/create the root password the command should be "passwd"
  • reply

FTP access

Anonymous — Thu, 10/27/2011 - 15:42
I've played around with this and got just about everything running except for FTP. I'm running off of Amazon AWS, which probably makes things a little more difficult because of their additional security. Any suggestions?
  • reply

sudo apt-get install ftp

patrick — Thu, 10/27/2011 - 15:49
sudo apt-get install ftp
  • reply

super! what a time saver

Anonymous — Thu, 10/27/2011 - 15:55
after a few years of having a LAMP development env. on a ubunto desktop version, I finally got around to to do it right. Now it is server OS, LAMP, Webmin and Virtualmin a seemingly exact replica of my host. good bye to silly file rights issues! or the headaches of setting up a new client. seriously setting this up is as simple as typing a username and password. Ok I realize you don't truly deserve the credit for virtualmin or other software but wow was this quick and easy to set up with your instructions. Thanks a lot. Bart
  • reply

FTP access

Anonymous — Thu, 10/27/2011 - 16:45
LOL... I guess I deserved that for not being more precise... I meant that I needed to install an FTP server on the Virtualmin box. Virtualmin seems to like ProFTPd, and appears to set up the virtual user accounts to work nicely with ProFTPd. I've never set that up to work with Virtualmin, and was just fishing to see if you had an idiot's guide for that part of the installation as well...
  • reply

I'm pretty sure that if you

patrick — Thu, 10/27/2011 - 16:51
I'm pretty sure that if you have ftp installed on your server and you create a new site with virtualmin, is will create an ftp account for them. I know have gotten it to work in the past. You might have to play with the virtualmin server template.
  • reply

May GOD Bless You !

Anonymous — Sat, 11/12/2011 - 23:51
You have done a FANTASTIC job in documenting this to enable multi-domains on an Ubuntu server! I will be recommending this to anybody who needs it .... :-) Thanks ever so much! Forrest Ward fwward2011@gmail.com
  • reply

Just Brilliant!

Anonymous — Sat, 12/10/2011 - 02:43
Amazing work. This has to be one of the very best tutorials i have read/used and successfully completed using. I am a big fan of "it just works".. and this did! Incase anyone had the same issue as me.. At the end of step 6 when removing the Virtualmin features and plugins, when i pressed save i got an error.. "Failed to save enabled features : Apache configuration file /etc/apache2/mods-enabled/php5.conf contains SetHandler lines that PHP from running with domain owner permissions. These lines must be removed." The fix is to edit /etc/apache2/mods-available/php5.conf and remove all SetHandler lines. Thanks you Dale of Aldinga Media @aldingamedia
  • reply

bingo! good advice

Anonymous — Mon, 05/07/2012 - 20:56
bingo! good advice
  • reply

Great Tutorial! Using CGI?

Anonymous — Wed, 12/21/2011 - 22:52
Thanks for putting this together. I had this running very quickly and everything appears to be working well. When I create new domains they are set up exactly like my VPS however I run into file permission issues and I have to CHMOD files and directories to 777. To avoid this I changed the Default Execution Mode (System Settings -> Server Templates -> Default Settings (dropdown)Apache website) to CGI wrapper (also tried FCGId with same results) but this gave me the '403 Forbidden You don't have permission to access /cgi-bin/ on this server' error when I navigate to the domain. I suspect the issue is with the default script that generates the domain's .conf file. I've googled the issue and found several suggestion fixes but still can't get it to work. Should I be experiencing the file permission issues using mod_php? Anyone else have CGI execution running correctly?
  • reply

Sethandler Error

Anonymous — Mon, 01/23/2012 - 20:47
@aldinga you can find the fix to the sethandler error here: http://www.virtualmin.com/node/20646
  • reply

error

Anonymous — Tue, 02/07/2012 - 10:19
Failed to save enabled features : Apache configuration file /etc/apache2/mods-enabled/php5.conf contains SetHandler lines that PHP from running with domain owner permissions. These lines must be removed.
  • reply

:D

Anonymous — Wed, 02/08/2012 - 09:10
Appreciate the awesome setup you've shared. Hit a little snag with PHP5 but all you have to do is go back into ubuntu and type: nano ../mods-enabled/php5.conf Then just comment out the 2 SetHandler lines by typing "#" and hit control-x, y, then return. All's good!
  • reply

No what?

Anonymous — Tue, 02/21/2012 - 00:43
OK I followed it. Now what? I can't FTP in I can't http in HTTP gives me 403 Forbidden FTP just bombs I dont think there is an ssh server running? How do I get in ????
  • reply

Now what

Anonymous — Tue, 02/21/2012 - 00:46
and Putty gives me "Network error. Connection Refused" When I try to SSH in on port 22
  • reply

Security

Anonymous — Tue, 02/21/2012 - 05:46
Hi and thanks for a great tutorial! I have a question on the security aspect. Will a home server based on this configuration be secure enough for hosting a webshop or other web sites? Any further steps you can take to make it more secure?
  • reply

Awesome

Anonymous — Mon, 02/27/2012 - 01:26
This was a really big help for me. I was able to get this all set up today running on a VirtualMachine in Windows7 and DNS via dyndns.org. Incredibly, it all worked out and I have you to thank. Without this tutorial I would have had NO idea what I was doing. Many thanks.
  • reply

Thank you

Anonymous — Mon, 03/05/2012 - 10:57
After trying win 2008r2 and giving up and switching to ubuntu, I followed your instructions line by line and I have my web hosting up! Thank you SO MUCH for putting this together... you have saved so much frustration.
  • reply

public ip address

Anonymous — Thu, 03/08/2012 - 21:38
This was a very cool tutorial thanks. Especially webmin - that rocks. I'd like to see a couple more tuts if you're feeling ambitious. 1. A simple way to make your webserver public. Mine is on a Windows network with 3 other windows machined all of which hide behind a belkin router. When I go to whatismyip.com it just gives the routers ip not the computers. 2. Since a home server is most probably very low bandwidth I thought of installing a WordPress blog on it. That would be a cool tutorial too ciao Mike
  • reply

Thank you very much

Anonymous — Fri, 03/09/2012 - 07:33
Just installed a server on amazon aws ec2 and this just rocks, brilliant tutorial in all aspects
  • reply

Thanks...

Anonymous — Sat, 03/17/2012 - 18:47
You make it seem so easy! and it was!!
  • reply

Awesome! But one error...

Anonymous — Mon, 03/19/2012 - 08:22
Simply fantastic tutorial! However I ran into the following error during the last part of the Apache plug-in setup: Failed to save enabled features : Apache configuration file /etc/apache2/mods-enabled/php5.conf contains SetHandler lines that PHP from running with domain owner permissions. These lines must be removed. Any help?
  • reply

Next

Anonymous — Mon, 03/26/2012 - 06:15
Great tutorial really hellped me can you add one more step what group permisions does the domain need to be in. The default seems to be user domain group domain my Joomla users create a media directory which is crfeated as mode 700 then can not be used till I set diretory 755.
  • reply

Website preview

Anonymous — Wed, 03/28/2012 - 23:04
Awesome post.... With this configuration how would I provide a preview url for a domain before the DNS is resolved? http://username.mydomain.tld or http://www.mydomain.com/~username
  • reply

Help please...

Anonymous — Thu, 03/29/2012 - 01:46
cannot turn OFF some features of Virtualmin.. Failed to save enabled features : The Suexec command on your system is configured to only run scripts under #/var/www, but the Virtualmin virtual server home directory is /home. CGI and PHP scripts run as domain owners will not be executed.
  • reply

Phewh..

Anonymous — Thu, 03/29/2012 - 01:51
nano www-data not just adding # on #/var/www, but delete it
  • reply

FYI on error

Anonymous — Sun, 04/01/2012 - 19:57
I did had an error on saving after this step Next we are going to turn OFF some features of Virtualmin. I have found that I only use a few key features and other features require further configuration. Uncheck 'BIND DNS domain', 'Mail for domain', and 'Webalizer reporting'. It told me that i had to removed a line from etc/apache2/mods-enabled/php5.conf I removed them and it work great. I have to say thank you and you have no idea how bad I was looking for this since I was using WAMP developer in wimdows and I want to start with linux. tank you you made the transfer much easier
  • reply

Accessing virtual servers locally?

Anonymous — Sat, 04/14/2012 - 14:57
I've followed through the tutorial (awesome job by the way!) and have everything functioning. Hoping this resolves my issue of using the url for some basic dynamic navigation needs. It works great on my public server, but my local test server it wasn't. So my question is this, I am using a local computer with Ubuntu Server (and now Virtualmin) as my development server. How do I access each of these virtual domains? If I created a virtual server called somedomain.com on my server with a local IP address of 192.168.1.50 what do I use as a url to access the pages? I originally had setup /var/www with subdirectories and each of my domains listed in their own directory there so I would just type in 192.168.1.50/somedomain.com and I would see that website. In my web dev software I would setup an ftp to the server with /var/www/somedomain.com as the project directory. Thanks again, not sure if because of how I was using the system before I now have some other configurations to modify, but think this will be a much better dev server once I get it all figured out. Greg
  • reply

i am having the same problem.

Anonymous — Wed, 04/25/2012 - 11:09
i am having the same problem. did you figure it out?
  • reply

Edit your host file

Anonymous — Fri, 05/04/2012 - 22:16
Edit your host file /etc/hosts and add a new host like so 127.0.0.1 www.myfakedomain.com Then you can have any domain point locally on your computer.
  • reply

Access to virtual server website

Anonymous — Mon, 05/07/2012 - 04:19
Even when editing the host file I still don't know how to access a website om my local server. Do I type address/website name ? (i.e. 192.168.1.xxx/website.com). Please help. Thanks.
  • reply

Same question, what is the address to use in the web browser?

Anonymous — Sun, 06/17/2012 - 13:59
I have the same problem/question. What does it help to change the hosts file if you have two domains? And when i type server ip address I only get to the general it works page anyway, Someone who can tell what to do, including all the details:), like if the change is on the server, client etc.
  • reply

Ok if you are running this

patrick — Mon, 06/18/2012 - 10:16
Ok if you are running this locally here is what you have to do. 1. Setup domain in virtualmin with domain mydomain.com 2. sudo nano /etc/hosts add the following lines 127.0.0.1 mydomin.com 127.0.0.1 www.mydomina.com 127.0.0.1 somesubdomain.mydomain.com hit ctrl x and save the file Now when accessing mydomin.com on your local machine DNS will resolve locally and access /home/mydomain/public_html Thats it.
  • reply

IP address not pointing to /home/.../public_html/

Anonymous — Sun, 05/06/2012 - 22:40
Thanks for the great tut! But the IP address of my server still points to the /var/www/ folder and not the /home/.../pulblic_html/ folder. I changed the line in suexec. What did I do wrong? Thanks a ton for your work on this article.
  • reply

Accessing website at /home

Anonymous — Mon, 05/07/2012 - 04:20
Did you figure it out ?
  • reply

I wonder too...

Anonymous — Mon, 06/18/2012 - 10:10
Have you found the answer yet?
  • reply
  • 1
  • 2
  • next ›
  • last »

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

patrick's tweets

  • Recent Project: Converting the BMJ (British Medical Journal) to Drupal http://t.co/6sTLhMFZ — 1 year 9 hours ago
  • Climate Change http://t.co/wuPwyIan — 1 year 21 weeks ago
see more
  • sites
  • mobile
  • résumé
  • about
  • contact
  • blog