linuxcentosvagrantlampdedicated-server

Set up Vagrant box exactly like production server


I'm trying to learn how to use Vagrant with the idea of setting up a development environment that should be exactly (if possible) to an already existing production server.

The question here is: what is the easiest way to accomplish that?

I'm a developer and I have full access to the production server, but it's not managed by me. I just know my way around the server a bit to set up websites, work with cPanel, some WHM, etc...

The server runs CentOS 6.5 with Apache, MySQL and PHP.

Is there a way I can "export" that server's configuration with all the applications it has, modules, versions, etc... and use that to create a Vagrant Box? Or is it a matter of manually analyzing everything and writing it down?

If the way to go is the second option, can I get any advice on how to do that without missing anything?


Solution

  • I don't think there is a direct way to export an existing server configuration into a Vagrant box, which essentially, requires you to clone the server into a VM format supported by one of Vagrant's providers (such as an OVA file for Virtualbox).

    AFAIK, you may have to do this manually unfortunately. The way I will go about it (at least at the application level) is:

    1. Re-use one of the predefined CentOS 6.5 LAMP boxes in the Vagrant Cloud to avoid re-installing all the software from scratch.
    2. Install Virtualbox if haven't already done so, since it is Vagrant's default provider.
    3. Make a copy of your production apache conf/httpd.conf, conf/extra and modules (I think these are the major ones), and import them into the apache server in your Vagrant box.
    4. Take a dump of your production MySQL database using mysqldump. Then import the schema and data into the MySQL database in your Vagrant box. Use the --no-data option to exclude data export if your production database is too big for your development needs. (Table 4.9 on that link I shared provides a comprehensive list of options.)
    5. Re-deploy your PHP application.
    6. Once you are satisfied with all the tweaks in your Vagrant box, use Virtualbox to clone the new VM as a baseline.

    As mentioned, these are only application-level set-ups and configurations. There are probably other configurations in your production server related to firewalls, SSH keys, user permissions etc. which you may or may not need to duplicate in your development environment.

    Hope this helps.