Monday, 27 February 2012

How to delete a Virtual Server using Virtualmin

Deleting a Virtual Server from your server  - Replacing the default site domain on a server with an IP address


The other day I talked about how you can setup a website for testing on your LINUX server using host headers so that you can test it before purchasing a domain name.

Now I did this on one PC and gave the virtual server a particular name in the hosts file so I could access it but because I was at work and behind a proxy it wouldn't allow me to access the website by the desired hostname. Therefore to get to the site I just put in my servers IP address e.g http://174.34.34.114.

However on my home laptop I changed my mind about the name I wanted to use for the new site and instead of editing the existing virtual server I created a new one with a new domain name (again one I hadn't purchased yet).

However because I wasn't behind an office proxy my local hosts file allowed me to access the website by the domain name I had given it in my file with a command like so e.g:

174.34.34.114 www.robsnewblog.com

However now I am back in the office and want to access the new site but due to the proxy issue when I enter the IP address I am met with the old site as that is the default site for the server. Changing the host file has no effect due to the issue with the Proxy. Therefore I cannot access my new domain www.robsnewblog.com either by the IP address OR the hosts file command.

Therefore the solution is to delete the old Virtual Server from my host in Virtualmin and reset the new site as the default server so that I can access it by the hosts IP address alone.

To do this you need to do the following:

1. Login to your host e.g https://myhostname.blah.com:10000/
2. Choose the virtual server you want to delete from the drop down box on the left e.g robstestdomain.
3. Extend the "Disable and Delete" menu option on the left menu and choose "Delete Virtual Server"
4. The main section will list all the services and files that will be deleted. Confirm that you want to delete the server.
5. You will be given an output like the following:


Delete Server
In domain robstestdomain.com
Deleting mail aliases ..
.. done
Deleting AWstats configuration file and Cron job ..
.. done

Removing password protection for AWstats ..
.. done

Deleting MySQL database robstestdomain ..
.. done

Deleting MySQL login ..
.. done

Disabling log file rotation ..
.. done

Deleting scheduled Webalizer reporting ..
.. done

Deleting virtual website ..
.. done

Deleting Apache log files ..
.. done

Removing from email domains list ..
.. done

Deleting home directory ..
.. done

Deleting administration user ..
.. done

Deleting administration group ..
.. done

Deleting server details for robstestdomain.com ..
.. done

Applying web server configuration ..
.. done

6. The virtual server will now have been deleted. A quick test by going to the domain or IP will show you the site cannot be accessed anymore and if you try to FTP to the site you will get an error trying to connect.

7. As you haven't bought a domain for the new site and if like me you are behind a proxy that is preventing you from using your hosts file to access the new domain then you will want to access the site from the IP address alone.

If this is the case and your hosts file is not working (after editing, and re-starting your browser) then you need to ensure that the Virtual Server you want to use is set as the default by going into VirtualMin, editing the Server, choosing "Server Configuration" from the menu and then "Website Options" and then making sure the "Default website for IP address?" radio button is ticked if it isn't already. This will ensure all requests to the IP address are forwarded to the Virtual Server in question.

7. Restart Apache - From WebMin (which you should have installed when you setup the server if you prefer graphical interfaces to using the SSH console) you can do this by going to System > Bootup and Shutdown. Tick the Apache2 box and then at the bottom hit the "Restart" button. Either that or use the command line and this command: /etc/init.d/apache2 restart.

8. If you have any problems go to System Settings and choose the "Re-Check Configuration" option to see if any errors appear or run apache2ctl configtest from the command line to ensure all configuration files are correct.


9. Go to the IP address of your site and hopefully it will now load up. Obviously if you are using an IP address to access the site but the website is set-up with a non existent domain name then paths to scripts and CSS files will not load correctly as they will be pointing to places that don't exist.


To fix this you will need to edit your database either in VirtualMin or through a MySQL management tool like PHPMyAdmin or Navicat and go through the wp_options table editing every row that currently points to your domain name to your IP address. The main ones will be:

  • siteurl
  • home
  • dashboard_widget_options



Obviously if you have custom plugins that have added their own data into the database you might need to change those as well. A quick SQL query will help you hunt any rows down


SELECT  *
FROM    wp_options
WHERE  option_value = 'http://www.robstestdomain.com';


Where you would obviously replace the URL with the domain you want to replace with your IP address.


This should now let you see the website on your PC even a proxy is blocking your hosts file commands.

5 comments:

spd said...

Dear friend,

I made a blunder. Using virtualmin from webmin, to clean garbage I deleted a domain. I guess, since user of the domain was myself (spd), the server deleted all my home directory (/home/spd).

Now I can't access any thing. I was still at experimental stage, so did not do backup.

Where does deleted data does Virtualmin keep. Iif I know, I shall try to recover.

PLEASE HELP URGENTLY.
spd

Rob Reid said...

Well I'm not an expert in VirtualMin and WebMin but I presume unless you made a backup of your whole virtual server (e.g in rackspace cloud server managment - done an image) or setup a backup in VMin I dont think their will be a backup.

Like most applications unless you specify a backup it won't do one. But I could be wrong so don't quote me on that.

evanseasyspace said...

Setting up anything is a lot easier than taking it down. Virtual servers are no different, however now we can use this blog that provides a step by step instruction to easily remove any virtual server.

Phil Taping said...

I totally messed up when I was first setting up the site, I'm my domain name I switched the names around by accident, and now I'm trying to delete the error I made, i'm gonna go look for this delete button, I did look for it earlier but couldn't find it, i'm gonna have to look again I guess lol.

IvanS said...

Thanks.

I'm new on VPS and I have just deleted one of my sites I don't want to use anymore. This post was helpful ...