📜 ⬆️ ⬇️

Stack of web developer in a virtual machine with FreeBSD

I was terribly tired from switching from one computer to another and from one system to another to raise the environment for development. I write mostly in PHP / Python, so the classic bundle (M / W / L) AMP is usually used. I heard a long time ago that some developers moved to virtual machines, but he didn’t take that step, but now I had some free time and I raised the stack for web development and now use the VirtualBox virtual machine, with a full system - FreeBSD, as close as possible to production.

In a virtual machine, the system works without windows and in a minimal configuration, due to which it requires a minimum of resources. Even 64Mb of RAM is enough. Ports for http, ssh are forwarded out. As a result, I have a full-fledged server in a box, and outside in a real system I use a full-fledged IDE (NetBeans / Eclipse) with a browser, debugger and terminal that access the virtual machine.

So, then I will tell you how to collect all this and give a link to the finished image for VirtualBox, the second step is to configure the IDE.
')

I will skip all the details of creating a virtual machine and installation, there is nothing interesting in this, and the environment is individual for each. The image of FreeBSD i386 8.1 Stable was taken on freebsd.org, loaded into a virtual machine, after which the installation went.

FreeBSD Setup


After installation, the first thing is to forward SSH outside for access from the local machine. And I issue ip through DHCP virtual machine. There should be something like this in /etc/rc.d:
ifconfig_em0 = "DHCP"
sshd_enable = "YES"

Then I indicated that the ip address on the em0 interface we receive via DHCP from VirtualBox. The rest is the start of the necessary demons.

Configure VirtualBox


In the virtualbox settings, I go to Network-> Port Forwarding and do this:



The host IP is the IP address of my local machine where VirtualBox is installed, the guest IP is the address that DHCP issued, you can peep it by commanding ifconfig.

For convenience, I allow root access over SSH, to do this, add the line PermitRootLogin yes to / etc / ssh / sshd_config

Now you can connect from the local machine to VirtualBox. In putty or iTerm, depending on your desktop, we command # ssh 192.168.1.101 -p 2222 -l root and we are inside FreeBSD.

Then the ports and the AMP bundle are installed and updated, after which you can proceed to the IDE configuration.

Debugger setup


The subtle point is debugging, which needs to be accessed from the desktop. Everything is solved very simply. In the VM from the ports I put xdebug for PHP, and in the php.ini config I just add:

zend_extension = / usr / local / lib / php / 20090626 / xdebug.so
xdebug.remote_enable = on
xdebug.remote_log = "/ var / log / xdebug.log"
xdebug.remote_host = 192.168.1.101
xdebug.remote_handler = dbgp
xdebug.remote_port = 9000

Where, remote_host is equal to the ip address of my desktop, on which IDE will listen on port 9000.

In Netbeans, everything works out of the box, Eclipse will have to deliver plugins. Therefore, I’ll tell you how I work in Netbeans IDE.

Configuring NetBeans IDE


First of all, I create a project and specify the local folder where the files will be stored, I go to its properties -> Run Configuration and select the launch as Remote Web Site (FTP, SFTP), indicate the Project Url and Index File (the debugger will be needed).



In Remote Connection it is driven in Port: 2222, Login: root and its password. Initial Directory points to the folder that Apache accesses for virtual hosts.



Total


1) The main system is not crammed with any unnecessary demons.
2) I always have a full-fledged console and all the benefits of the system (ports, cron, etc.)
3) The environment for my code is as close as possible to the combat conditions.
4) Easy portability of the environment from one machine to another.
5) Everything works very fast.

As an additional element of the elegance of the solution, my home router works. If I need to show the customer the project I'm working on right now, then it’s enough to forward port 80 to my home machine from my home router — 192.168.1.101:8080.

Download the finished image here . The image includes current stable versions of Apache / PHP + Extensions / Python / Mysql / Phpmyadmin / ZendFramework and others. SSH login: root, password: toor; MySQL login: admin, password: nimda. Do not forget to rewrite the virtual hosts, or edit / etc / hosts, because my domain and ip addresses are set by default.

Happy New Year 2011!

UPD: Filled new ahiv, now the image with maximum compression weighs 259Mb, the link is updated.

Source: https://habr.com/ru/post/110910/


All Articles