Hello and welcome to the very first article on the site. I will show you how to install Magento 2 on Vagrant-based VM. There’s a great guide on Magento official docs, but it’s very time-consuming and it forces you to install a lot of pieces manually. I want to make it quick and easy as much as possible.
To start off, please check if you have
installed on your computer.
Linux (only!) users will need to install nfs system packages with the following command:
sudo apt-get install nfs-common nfs-kernel-server
and vagrant-bindfs plugin:
vagrant plugin install vagrant-bindfs
Windows (only!) users, I recommend installing Git Bash so you can follow the tutorial using unix-based commands. Also, make sure to run it as administrator since it’s required for this tutorial.
Download files for your system
I used PuPHPet to prepare a fully configured VM for Magento 2 development:
Setting Up Virtual Machine
Once you’re done with previous step:
- Extract the downloaded zip file
- Open up a terminal window and go to the extracted folder (the one that contains Vagrantfile)
- Run vagrant up and go grab a coffee
The last step will automatically install many things for you:
- Ubuntu Trusty 14.04 LTS x64
- Apache web server (2.4.12)
- PHP (5.6), XDebug and modules (php5-gd, php5-curl, mcrypt)
- MySQL (5.6) with predefined user root/root and magento2 database
- virtual host mage2.dev (document root will be /var/www/html/mage2)
However, you’ll need to be patient since it will take some time. While you wait, you can update hosts file on your system. For Mac/Linux users, it’s located under /etc/hosts, and on Windows, it is C:\Windows\system32\drivers\etc\hosts.
192.168.56.101 mage2.dev www.mage2.dev
Installing Magento and its dependencies
When you see that vagrant up has been finished, you can login to your VM via SSH
Make sure that you are in the right folder:
git clone https://github.com/magento/magento2.git .
Now we can install all dependencies with the following command:
COMPOSER_PROCESS_TIMEOUT=2000 composer install
Enabling Sample Data
I highly recommend installing sample data, since it will drastically save your time later. To enable sample data, you must update composer.json in the Magento root installation directory to provide the location of the sample data package. So, open up composer.json file in your favourite text editor and add “minimum-stability”: “beta”, before license. A snippet follows:
"name": "magento/magento2ce", "description": "Magento 2 (Community Edition)", "type": "project", "version": "0.74.0-beta8", "minimum-stability": "beta", "license": [ "OSL-3.0", "AFL-3.0" ],
Now enter the following command to reference Magento packages in composer.json:
composer config repositories.magento composer http://packages.magento.com
and enter the following command to require the current version of the sample data package:
composer require magento/sample-data:<version>
where <version> should be replaced by the exact value. At the moment, the right version is 0.74.0-beta9, but you can always check it on this site. This command will take some time, so be patient.
Finally, start the installer from command line
We reached the final point, where we are quite ready to run the installer.
It’s up to you to choose between web-based or command-line installer. For some reason, I couldn’t make web-based installer to work for me, due to the following error: [ERROR] exception ‘Exception’ with message ‘Warning: fopen(): Filename cannot be empty in /var/www/mage2/dev/tools/Magento/Tools/SampleData/Helper/Csv/Reader.php on line 64’ in /var/www/mage2/lib/internal/Magento/Framework/App/ErrorHandler.php:59. I didn’t want to spend too much time debugging this issue, since I am quite new to Magento 2. That’s why I tried command line installer, and it worked like a charm!
Make sure that you are in the root Magento 2 directory.
Once there, run the installer
php bin/magento setup:install --base-url=http://mage2.dev/ \ --backend-frontname=admin \ --db-host=localhost --db-name=magento2 --db-user=root --db-password=root \ --admin-firstname=YOUR_FIRSTNAME --admin-lastname=YOUR_LASTNAME --firstname.lastname@example.org \ --admin-user=ADMIN_USER --admin-password=ADMIN_PASS --language=en_US \ --currency=USD --timezone=America/Chicago --use-sample-data --use-rewrites=1
Make sure to review the snippet and change it according to your local settings. This process is the longest one, and it took around 15-20 mins on my computer.
Once it’s completed, you should be able to go to http://mage2.dev and start playing with Magento 2!
Magento Doesn’t Load Styles
This may happen. We’ve explained how to fix the issue.
Bonus Tip: Accessing MySQL Database
The very last thing that I want to cover is about accessing MySQL. I am attaching screenshots with necessary settings for my favourite DB management tools called Sequel Pro (Mac OS) and MySQL Workbench (Linux and Windows). If you are using a different tool, please make sure it does support connecting to MySQL through SSH tunnel.
Everything should be self explanatory. Private key is coming within PuPHPet, and this is the right location: puphpet/files/dot/ssh/id_rsa.