Well I found myself changing the LAMPP stack with a virtual server now. So I want to show you how I do it so you can learn from my mistakes.
These two are too easy so I will not explain more than say to you download it and clic it to install it.
After intalling those check that you have the command “vagrant -v” using it in the terminal.
Installing Vagrant with a Ubuntu 14.04 Box (Don’t worry it’s easy)
I will explain how I want to create my directories, you can do it differently of course!
In my home directory I create a folder named “workspace” with in two other folders “vagrant” and “www”. In my workspace/www folder I’m going to put in folders the projects that I am currently working on and in the workspace/vagrant guess what I’m going to put.
1. Create the directories
mkdir ~/workspace ~/workspace/vagrant ~/workspace/www
2. Now just open the vagrant directory if you have another well, open it.
3. As a platform I decided to use ubuntu/trusty64 meaning Ubuntu 14.04 Server because I already have a real server using it and DigitalOcean has this available. So create the new box. Well boxes refers to something like images of Operationg Systems
vagrant box add ubuntu/trusty64
4. Wait for the files to download and now we are going to create a Vagrantfile that contains the configurations for the Vagrant System that we are using. Make sure that you’re in the desired folder in my case ~/workspace/vagrant
vagrant init ubuntu/trusty64
5. Now we are going to tweak a little our configuration file so open it with your editor of preference, mine it’s vim but surenly you can use gedit, subl, etc…
Locate the line 29 or the one with config.vm.network “private_network” and remove it’s hashtag to uncomment it. This line assigns a IP address to our new virtual machine I change the default ip to one more memorable like 192.168.200.200 you can do it or not but just remember it.
We are going to change other things but for now this works, save it.
6. Now this is when the magic happens. run this command (that is how you start it, you need to be in this folder when you do it, or that’s what I understood)
7. Now after it boots up we have ourselfs a Virtual Server running but so far it contains almost nothing so we are goint to open the shell on the virtual machine with the following command
You can check that you’re now in another pc, for that your “real” machine concerns it’s another completly different pc (That’s the reason for all this.)
8. We are on the vagrant shell so let’s install some things. first of all run an apt-get update and install the things, these are two commands and the second one it’s just a line
sudo apt-get update
sudo apt-get install apache2 php5 php5-cli phpunit nodejs nodejs-legacy npm mysql-server phpmyadmin php5-mysql php5-curl git php5-xdebug php5-json curl rake
We will be prompted for a password to the mysql root user, to select what (Apache2, or lighthttp) select Apache2 and OK, and once again for the mysql root password to phpmyadmin. just give them and no problem.
10. Remeber that I told you that we need to return to edit the Vagrantfile, well now it’s a good moment. So exit from the Vagrant Box.
That “vagrant halt” command shutdowns our virtual machine.
Vagrant allow us to sync folders between our “real” machine and the virtual one (That’s another of the reason we’re doing this) so let’s sync that ~/workspace/www folder that we previously create. So now every time that we work on our local machine it will be reflected to the virtual one.
11. Uncomment (remove the hashtag) to the line 40 on the file and change it for this one:
config.vm.synced_folder "../www", "/var/www", owner: "vagrant", group: "www-data", mount_options: ["dmode=775,fmode=664"]
We are making it to replace the /var/www on the virtual server for our folder www and setting it up to make it readable to Apache so save the file and close it.
12. Run again the virtual machine with “vagrant up” and that’s all to check that it’s working just create a dummy index.php file in your local ~/workspace/www directory and put the IP address of the virtual machine in the browser.
Well this is already a really big post so I will explain to you in another post how to setup virtual hosts within your server to allow different projects with, let’s say, custom fake domains, for example to type “myapp.dev” and that runs on your server and in a custom folder.
I hope this post help you and if not, just tell me why and I will try to help you.