Ahsaniqbalkmc

Access A Website Created Locally On A Virtual Machine From The Host Machine

Recommended Posts

I have set up an environement where I have used vmware to install ubuntu on host windows 7 system. I wanted to play around with ubuntu. I have created a local server on the virtual machine (ubuntu). I have created a test website which I can access from within the virtual machine. The problem is that I don't know how to access the same website (that is hosted on virtual machine) from the host machine (windows 7).

Share this post


Link to post
Share on other sites

The problem accessing the virtual machine is the same you will face accessing another machine. You have two completely different machine, a ubuntu machine and a windows machine.Your website can be accessed from the ubuntu machine and not from another machine. This is because your ubuntu apache server (I guess it's apache) is listening to the local machine and not the network machine.So, you have to find the apache configuration file (I guess it's named httpd.conf or a similar name) on your ubuntu server, have a look at the LISTEN instruction, and ask to LISTEN your IP address (if it's a fixed IP) or your hostname. And stop/start your apache server (apachectl stop and then start, or reboot your ubuntu server).Then, you will be able to reach your webserver from another system, namely your windows machine.

Share this post


Link to post
Share on other sites

What if I want to access the website on the host machine from an entirely different computer. I want to behave the website as if it is hosted on a separate server and accessible throughout the internet. Though it is just for testing purposes but I want it to operate this way. Is this possible then?

Share this post


Link to post
Share on other sites

If you want to access it from any pc in the network then there are two things you want to do:1) change your VMWare network configuration so that you use a "bridged interface" instead of NAT. This means that your virtual machine will act as if it has a network card on it's own which is directly connected to your switch (if it's set to NAT, the your 'real' computer will forward all the messages to the virtual machine and your network will be unaware of the virtual machine). If you use a bridged interface then your virtual machine should have an IP-adress which is in the same range as your 'real' computer.2) configure your Ubuntu firewall. If it's for testing purposes only, disable it, otherwise it's best to look up some guide on the internet to configure the firewall in Ubuntu to allow incoming data on port 80 and port 443. If you want to access FTP you'll also have to open port 21 and 22.

Share this post


Link to post
Share on other sites

If you're using XAMPP or Cherecoo then you have to get dynamic IP if i am not wrong. Your VM configuration needs to be changed as well. As noted by WUTSKE above, NAT doesn't work for the local IP sharing. You have to use the bridged interface in order to test the virtual machine website on host. As for firewall, I never had issue that way, so not sure if that has to be done. Port 80 and 443 was accessible for me when I did that. So you can follow his instruction in that case if anything goes wrong. By the way you can use ampps.com or Xampp on windows for much better performance. Using virtual machine for this type of work is painfully slow, atleast it was slow for me. just my 2 cents contrib.

Share this post


Link to post
Share on other sites

The speed is not the current problem. The virtual machine is here just in order to test a Linux website on a Windows host. Vmware is there in order to have simultaneously a second operating system on a single keyboard-mouse computer. And I remain pretty sure that you will have to set the LISTEN parameter, else apache will listen to the localhost machine and will ignore all remote queries.By the way, starscream is right, you would get better performances with a local portable WAMPP setup on your windows machine, than dividing your cpu power between your windows host and your Linux VM. You should try this portable WAMPP things, if you don't like it you simply remove the concerned folder.

Share this post


Link to post
Share on other sites

As i understand you just want to access that website using your webbrowser nothing more any complicated task. If am i right, as the other user has posted that the guest machine must have a internal IP address as you of in same range of your host machine. To get internal IP of your guest machine on Ubuntu "ifconfig /all" which is similar to the ipconfig command in windows. But everytime whenever you restart your guest machine or router this internal IP may be changed, So you need to check cofiguration on guest eachtime or you can set fixed LAN ip for your guest machine.

 

Now, i assume that you got guest machines internal IP that may some like 192.168.*.* . For example i take your guest IP is 192.168.1.7, So now on your host machine webbrowser just simply typ 192.168.1.7, now you can access your website homepage it is in root otherwise use subdirectory.

 

Hope i am right and may resolve your auery.

Share this post


Link to post
Share on other sites

If you want to access it from any pc in the network then there are two things you want to do:

1) change your VMWare network configuration so that you use a "bridged interface" instead of NAT. This means that your virtual machine will act as if it has a network card on it's own which is directly connected to your switch (if it's set to NAT, the your 'real' computer will forward all the messages to the virtual machine and your network will be unaware of the virtual machine). If you use a bridged interface then your virtual machine should have an IP-adress which is in the same range as your 'real' computer.

2) configure your Ubuntu firewall. If it's for testing purposes only, disable it, otherwise it's best to look up some guide on the internet to configure the firewall in Ubuntu to allow incoming data on port 80 and port 443. If you want to access FTP you'll also have to open port 21 and 22.

 

I did some research on the internet before coming to the forum again and found that if I type in the IP address of the guest os, I can get access the the server hosted on it. Then I did further research on how to find the IP of the guest OS (as I am completely new to linux and haven't ever used it before). Luckily I found the terminal command ifconfig. I don't know what else this command can be used for but it did the job for me. The IP of the guest OS was some 192.168.xxx.xxx (I don't remember the exact value now). When I gave the IP address in my browser on the Host OS, it did work but there I discovered a new problem. It appeared as if the PHP was not working. I can tell this because the website hosted on my Guest OS is set up on wordpress and the theme gets the stylesheet through the php. I am not sure if it is PHP or something else but I did some research online and found that PHP can cause issues in such scenarios. When I tried to log into the wp-admin, the server stopped responding. I mean to say that the server is not allowing me to log into the wordpress admin area. This is kind of strange as I have no clue for what the reason could be.

I checked the network settings of the vmware and found that it bridged interface is selected by default. I think that is why I can visit the website hosted on the Guest OS. I also tried disabling the ubuntu firewall. I used some "sudo ufw disable" command if I remember it correctly but this didn't change anything. I can still visit the website but the sytles won't load and I cannot login to the admin area of the wordpress website.

I also did some research on "Listen 80". According to my research, I should add this command to the httpd.conf file so that port 80 is opened. But when I did this, the apache server showed me error which was something like "IP address already in Use, cannot assigne 0.0.0.0:80" (forgive me for my weak memory). So I deleted the LIsten command from the httpd.conf file. What this problem did was that now I don't know how to make the server on guest OS allow FTP connection from host os Basically I don't even know what address, username, password to use to get FTP access even if the server allowed it. So I would like to have your help on this.

 

If you're using XAMPP or Cherecoo then you have to get dynamic IP if i am not wrong. Your VM configuration needs to be changed as well. As noted by WUTSKE above, NAT doesn't work for the local IP sharing. You have to use the bridged interface in order to test the virtual machine website on host.

 

As for firewall, I never had issue that way, so not sure if that has to be done. Port 80 and 443 was accessible for me when I did that. So you can follow his instruction in that case if anything goes wrong.

 

By the way you can use ampps.com or Xampp on windows for much better performance. Using virtual machine for this type of work is painfully slow, atleast it was slow for me. just my 2 cents contrib.

 

@starscream, I am very glad to hear from you. I thought you left the forum (as I didn't get any replies from you). I did use wamp on my current host os, which is Windows ultimate 64 bit. I had some past experience with xampp, but I failed to find a 64 bit version of it so I installed wampserver 2.0. The installation and configuration was flawless and everything worked so well, but a few days ago, for unknown reason. the localserver started to respond extremely slow. I had to wait about a couple of minutes just to load the homepage of the website hosted on that local server. I did have the option of reinstalling the server and making all the settings but I wanted to experience the a server set up on linux (as I have heard a lot of praise). I didn't want to change my primary OS for the sole reason that I had no experience with linux and I didn't want myself to hang. So I created a virtual machine and installed ubuntu on it. From my short experience, I have become a fan of both ubuntu and vmware. Previously, I have oracle's virtualbox, but the results never satisfied me from that virtual environment. The machines created with it were always very slow and laggy. I tried xubuntu on it just to see how it looked but it never impressed me. But I have to say the vmware is way way better. I have give 2.5 gigs of ram and 2 cores of my processor to the virtual machine and it runs flawlessly. It doesn't even make me feel that it is a virtual environement and not a real one. And I liked ubuntu as well. The only big issue I am having currently is that I cannot edit, copy, cut, move files from the root through the GUI. I signed in with the username and password I gave during installation but still it won't give me root access. I tried the username root but no password matches it (not even an empty file). Consequently, I have to do every such task through the terminal and I hate doing it this way. But despite this issue, I have come to realize that Linux is a powerful OS.

I don't know much about ports, (don't even know what port 80 and 443 mean) but when I tried to add LIsten to the httpd.conf file, it gave me error so I guess there is something I need to learn and understand first before making additions.

My virtual machine is not slow at all. The only pain for me is that all the programs like photoshop etc which I use to create stuff for my website are on host os and since I cannot use Linux GUI to move files to root of guest os, I have to use the terminal and it gives me more trouble than anything else.

 

The speed is not the current problem. The virtual machine is here just in order to test a Linux website on a Windows host. Vmware is there in order to have simultaneously a second operating system on a single keyboard-mouse computer. And I remain pretty sure that you will have to set the LISTEN parameter, else apache will listen to the localhost machine and will ignore all remote queries.

By the way, starscream is right, you would get better performances with a local portable WAMPP setup on your windows machine, than dividing your cpu power between your windows host and your Linux VM. You should try this portable WAMPP things, if you don't like it you simply remove the concerned folder.

 

One of the main reason I set up a linux virtual machine was that I wanted to test linux as well as servers operating on virtual environments. Believe me, it was very educational and I have learned alot in these fiew days. I like linux now and I think I would switch to it when I get some basic problem (a couple of which I discussed above) fixed. It is a really nice OS.

The wamp server on windows was much easier to operate than operating apache, php and mysql thought the linux terminal. But I guess I have more control on my server through the terminal than provided by the wamp in windows, but I might be wrong.

I was really concerned about dividing the power and memory of my cpu between two machines. But I am amazed by the efficiency of the vmware. Both machines run simultaneously without a flaw. They are seamless and I don't even notice any drop in performance.

 

As i understand you just want to access that website using your webbrowser nothing more any complicated task. If am i right, as the other user has posted that the guest machine must have a internal IP address as you of in same range of your host machine. To get internal IP of your guest machine on Ubuntu "ifconfig /all" which is similar to the ipconfig command in windows. But everytime whenever you restart your guest machine or router this internal IP may be changed, So you need to check cofiguration on guest eachtime or you can set fixed LAN ip for your guest machine.

 

Now, i assume that you got guest machines internal IP that may some like 192.168.*.* . For example i take your guest IP is 192.168.1.7, So now on your host machine webbrowser just simply typ 192.168.1.7, now you can access your website homepage it is in root otherwise use subdirectory.

 

Hope i am right and may resolve your auery.

 

Well, the main purpose of all this set up is to learn new stuff. I don't just want to host a test site. Yes I want to improve my developer skills and test new stuff on that server, but I also want to learn how servers operate and how virtual machines run. I think this knowledge will help me understand the nature of websties and webhosts better. I am planning to go deep into this stuff step by step because this thing interests me more than my medical books.

As I have mentioned above, I can access the website by putting in the IP of the guest machine, but all the features don't appear to work. The stylesheet doens't appear to have loaded and I cannot access the wp-admin area. So there is something wrong and I need to fix it.

Share this post


Link to post
Share on other sites

did similar setup a-while back... with a LinuxMint running a Windows XP on Virtualbox with WAMPServer on... all i needed was to setup WIndows XP to connect to the Router/Modem... so just entered it's IP on browser and loads up the WAMPServer index/default page

Edited by manuleka

Share this post


Link to post
Share on other sites

did similar setup a-while back... with a LinuxMint running a Windows XP on Virtualbox with WAMPServer on... all i needed was to setup WIndows XP to connect to the Router/Modem... so just entered it's IP on browser and loads up the WAMPServer index/default pageI did run Wordpress on the Guest and had same problem with stylesheet not working, at first i thought it was a VBox Host/Guest issue so i decided to run wordpress on local LinuxMint Server and visit the site locally from another machine on the network but the problem persists... i tried researching for a possible solution but didn't reach one...I hope you will get this issue resolved as i am quite interested

Share this post


Link to post
Share on other sites

To make the guest listen to ANY IP on port 80 or http port, just add this on your configListen 80Instead of adding Listen xxx.xxx.xxx.xxx:80 which while only listen on the same exact IP that you provided.In order to make wordpress work, you need apache server, Php interpreter and lastly is a mySQL server.Forget one of them and the whole wordpress system wont work.Take note that in apache and all linux/unix base system, filenames are case sensitive making "folder" not equal to "Folder" hence producing "file not found" errors which in turn can hang the whole system.

Share this post


Link to post
Share on other sites

To make the guest listen to ANY IP on port 80 or http port, just add this on your configListen 80

Instead of adding Listen xxx.xxx.xxx.xxx:80 which while only listen on the same exact IP that you provided.

In order to make wordpress work, you need apache server, Php interpreter and lastly is a mySQL server.
Forget one of them and the whole wordpress system wont work.
Take note that in apache and all linux/unix base system, filenames are case sensitive making "folder" not equal to "Folder" hence producing "file not found" errors which in turn can hang the whole system.

My problem is a bit different. Though without styles, but I can access the website from the host machine. This should mean that the apache server and the mysql server all are working fine. I could have gone deep into this issue but it is not the primary one. The primary issue is that I cannot login to the administrator section of the website. And I don't have any idea why I am unable to. If this was something related to apache or mysql, the site shouldn't be available for viewing. I can view it (without styles) but I cannot log in to the admin section. And this is making me crazy..

Before attempting other things on that server, I added the Listen 80 line to the httpd.conf file. But after I made the edit, the server failed to start. It gave me some error (I don't remember exactly what that error was) but I remember that when I did some research for the matter, I found that that particular error was generated because of duplicated entries. Simply, it meant that Listen 80 was already added to some configuration file (other than httpd.conf), so I guess I don't need to play around with this issue.

Share this post


Link to post
Share on other sites

i still don't get... pages are being sent but with out their style! i've had this issue un-resolved on my local setup...first computer runs apache... second computer connected directly (cabled) to it... visit the standard the servers default page and everything seems fine, when i hit the php link (or folder) the page goes simple html with no style.. but my setup was with a Linux Server so have you tried running wordpress from Windows VM or Machine running WAMP Server?

Edited by manuleka

Share this post


Link to post
Share on other sites

Unfortunately, I was also unable to resolve he same issue on my setup. So eventually, I ended up instally wamp on my primary OS (windows 7) and then I shifted all of my work to it. Now all my development is going on in the primary OS.Your case seems different. I was working with virtual machines but you appear to be working with actual machines so you got to resolve this issue. I will be very interested in knowing how you resolve it, as it might help me big time for my future needs.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now