Nowadays we have vagrant for what we want to achieve here, but if your host operative system is Windows you may find a lot of problems if the project you are working with uses node or you have symlinks in your projects that you need.

Currently Windowns in any of it’s versions supports paths longer than 256 characters and of course it doesn’t support symlinks, and when you are using npm, the generated paths for files can be much longer than 256 so even using vagrant, as the shared folder is hosted in Windows you won’t be able to handle such files.

So in this cases is when you need a Virtual Box machine ready with it’s internal hard drive, and I am going to explain how to achieve that and accessing to that machine from our Windows host.

1. Getting Ubuntu server in your Virtual Box

I used Ubuntu server, but of course you can use your favourite distribution. This step is pretty straight forward, I created a VirtualBox machine with 4096 Mb of memory and 40GB hard drive.

2. Installing all your LAMP environment

Like in the step before, you can follow one of the thousand guides in google to install your environment. Where I say Apache you can install Nginx, lighthttpd or wathever you prefer, and of course this also works for node or any dev environment you need.

3. Port forwarding

That’s the important point. Once our machine is running with wathever we installed on it, just go to the VirtualBox window where you have the list of machines and all the options.

Right click the server you want to access and then Settings

Then go to network, and in the first tab where you should have NAT network adapter, click on advanced options and then Port Forwarding

This will open a new window that you can copy directly from my screenshot

At this point we should be able to access our VirtualHost Ubuntu via ssh username@127.0.1.1:2230 or on our web browser 127.0.1.1:8080, but probably you will get a «Connection refused» error if you didn’t installed ssh in your guest Ubuntu.

4. Setting up ssh and virtual hosts

Just install ssh and allow connections to the port 22 in your server

sudo apt-get install ssh
ufw allow 22

Finally create a virtual host in the guest

nano /etc/apache2/sites-enabled/mysite.conf

<VirtualHost *:80>
    ServerAdmin me@myserver
    DocumentRoot /var/www/html/mysite
    ServerName mysite.local
    ServerAlias www.mysite.local
    RewriteEngine On
    RewriteOptions inherit
    CustomLog /var/log/apache2/eubussines.com.log combined

<Directory /var/www/html/mysite>
    AllowOverride All
    Require all granted
    Allow from all
</Directory>
</VirtualHost>

Restart your apache service and finally add this to your hosts files in Windows

127.0.0.1    mysite.local

Now you should be able to access http://mysite.local:8080

Dejar respuesta

Please enter your comment!
Please enter your name here