How to set up magento 2 with sample data using Vagrant box on Windows 10 with Ubuntu guest

I have been trying different configurations to set up magento 2 with sample data using Vagrant within the last few days. I am using Windows 10 as host machine and now successfully running Ubuntu 14.04 Trusty Tahr on a guest machine with magento 2 and sample data.

Basically, you will need to set up virtual environment first, download VitualBox and Vagrant. VirtualBox lets you create and run virtual machine within your environment, so head to https://www.virtualbox.org/wiki/Downloads, download and install the latest release first. Vagrant lets you create scripts to preinstall and configure all the packages on a virtual machine. Once configured, you can run a virtual machine with the same configuration from anywhere, destroy and re-create a box that suits your development needs in one simple command. So head to https://www.vagrantup.com/downloads.html to download and install Vagrant.

Next comes the configuration part. We have tried many. Magento 2 is complicated, resource hungry and slow as is. Our goal was to set up a shared folder that we can use for development and a virtual box to run the beast. After tinkering around different file systems and configurations, we have found a simple solution with minimal configuration that gave us satisfactory results. We also need to deploy magento 2 sampledata package, which provides some sample data to play with. It was not possible to get it installed with out of the box configurations due to dependency issues, so we made a little adjustment as explained below.

Basically, vagrant-magento2-apache-base by Alan Kent gave us a headstart on the configuration. Please follow https://github.com/alankent/vagrant-magento2-apache-base and clone the repository but do not start Vagrant with vagrant up yet as we need to make additional changes to the configuration. Using default settings resulted in the following error message when trying to install  sampledata package:


[ReflectionException]
Class Magento\Catalog\Model\ResourceModel\Product\Attribute\Backend\Media does not exist

Instead of using magento2 folder that has a copy of magento2 from the repo, we will get a fresh copy from official repo.magento.com. In order to do so, you need to be registered or register with magento connect – https://www.magentocommerce.com/magento-connect/. Login, go to “My Account” -> “Developers” -> “Secure Keys”. Get your public and private keys that are used as a username and password to access Magento GitHub repository.

Next, default configuration that we used, has /magento2 folder with magento code. We are not going to use it. Instead, we need to create a new folder to which we will install the latest magento 2 from the repo from the vagrant machine. Create a new folder in the same folder where you placed /magento2 and /vagrant-magento2-apache-base using Alan’s sample configuration. We will call it /magento_code, but feel free to change the name as you wish.

First, lets update vagrant configuration. Go to /vagrant-magento2-apache-base and open configuration – Vagrantfile in text editor. Replace:


config.vm.synced_folder "../magento2", "/var/www/magento2", :mount_options => ["dmode=777","fmode=666"]

with


config.vm.synced_folder "../magento_code", "/var/www/magento2", :mount_options => ["dmode=777","fmode=666"]

respectively to reflect the changes we made to switch shared folder to a blank folder where magento 2 will be installed during the first vagrant setup run.

While we are here, we need to make additional changes to actually install magento 2 on startup. At the end of the file, right after:


config.vm.provision "shell", path: "scripts/install.sh"

add these two lines, changing your repo.magento.com username (public key) and password (private key). Also, head to github.com and grab your github oauth, as you will need it as well:


config.vm.provision "shell", inline: "echo '{\"http-basic\": {\"repo.magento.com\": {\"username\": \"your_magento_connect_username\",\"password\": \"your_magento_connect_password\"}}, \"github-oauth\": {\"github.com\": \"your_github_oauth\"}}' >> /root/.composer/auth.json"
config.vm.provision "shell", inline: "composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition /var/www/magento2/"

This will install magento2 on startup into /var/www/magento2, which is linked to your empty folder /magento_code

One other change I had to make is adding php5-5.6 repository to vagrant-magento2-apache-base/scripts/install.sh as it is required to run magento2.

Open the file in the text editor and add:


#edit for php 5.6
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:ondrej/php5-5.6
sudo apt-get update

right before #Install MySQL.

Next, open deploy.sh in the same /config folder and add –use-sample-data at the end of install command for magento2, your file should look something like:


#!/bin/sh


# Show what we execute
set -x


cd /var/www/magento2/

# Wipe out all caches
/bin/rm -rf var/*

# Set up, rebuilding database from scratch.
# Port 8080 must match what you expose via Vagrantfile.
php bin/magento setup:install \
--cleanup-database \
--db-host=localhost \
--db-name=magento \
--db-user=magento \
--db-password=secret \
--backend-frontname=admin \
--base-url=http://127.0.0.1:8080/ \
--language=en_US \
--timezone=America/Los_Angeles \
--currency=USD \
--admin-lastname=Smith \
--admin-firstname=John \
--admin-email=john.smith@example.com \
--admin-user=admin \
--admin-password=admin123 \
--use-secure=0 \
--use-sample-data

This is it for configuration. We now follow instructions as described on sample config page and install additions. Open command line, go to /vagrant-magento2-apache-base and enter:


vagrant up

Once the machine is built:


vagrant ssh

Once you are logged in, type:


sudo sh /vagrant/scripts/deploy.sh

This should deploy everything we have predefined.

Next are the set of commands to set up magento 2 as we need it:


cd /var/www/magento2/
php bin/magento setup:static-content:deploy

to deploy static content if the default images on localhost:8080 do not load. Next:


php bin/magento sampledata:deploy

to actually deploy the sample data package. Next:


composer update

to update the dependencies. Next:


php bin/magento setup:upgrade

to upgrade the magento 2 installation with sample data.

This is it. You now should have a fresh magento 2 install with sample data and a virtual box ready for development. Enjoy!

How to show images on new magento 2 installation in Ubuntu

On a new magento 2 install sometimes images and javascript files do not load. To fix it, one of the options is to redeploy static content.

Here is the command to execute from magento2 install directory:

vagrant@vagrant-ubuntu-trusty-64:/var/www/magento2$ php bin/magento setup:static-content:deploy

How to replace Windows new line characters in Ubuntu

I have tried executing a bash script edited in Windows, which gave me an error:

vagrant@vagrant-ubuntu-trusty-64:/var/www/magento2$ sh /vagrant/scripts/deploy.sh
: not foundripts/deploy.sh: 2: /vagrant/scripts/deploy.sh:
/vagrant/scripts/deploy.sh: 4: set: Illegal option -

I tried executing it with bash, which gave me more details showing windows new line character as a problem:

vagrant@vagrant-ubuntu-trusty-64:/var/www/magento2$ bash /vagrant/scripts/deploy.sh
/vagrant/scripts/deploy.sh: line 2: $'\r': command not found
: invalid option/deploy.sh: line 4: set: -

To solve this problem, I replaced Windows new lines with Linux:

sed -i 's/\r$//' /vagrant/scripts/deploy.sh

If you have this problem, replace filename with the name of your file:

sed -i 's/\r$//' filename

Linux Web Hosting

 

 I have purchased Web Hosting Deals site several years ago, just couldn’t get to it yet. Still in it’s original form. I am planning to redo the whole site at some point, sign up with more hosting companies and do complete feature reviews of linux hosting companies.

Meanwhile, please feel free to comment and let us know which Linux hosts you use and why.

How to fix flashing screen after nvidia driver update in Ubuntu

Just tried updating to the latest nvidia drivers and the screen was flashing after reboot. I have tried reinstalling drivers from other repositories but nothing worked. Had to use nouveau to get back to boot and still looking for a solution to get my desktop back to previous state. Anyhow, here is how to switch to nouveau:

At the flashing screen press “Ctrl + Alt + F1” to get to terminal at Ubuntu log in screen.

Log in using your credentials.

Stop X11 by entering this command:

sudo stop lightdm

Remove all nvidia packages by entering this command:

sudo apt-get purge nvidia-*

Install nouveau package by entering this command:

sudo apt-get install xserver-xorg-video-nouveau

Restart:

sudo reboot

or

sudo shutdown -r now

Hope it helps!

How to find files within daterange in Ubuntu

I got a virus that hit all php files on one of my servers and had to find all the files that got affected withing the date of the attack. There are a few methods that you can use:

1) To find the files modified within the last day, type:

find /directory_path -mtime -1 -print

where -1 is 24 hours, -2 – 48, and so on.

2) To find the files within modified date range is trickier. You have to create 2 files with start and end dates like listed below, just replace 20111110 and 20111120 with needed dates.

touch -t 201111101059 /tmp/file1
touch -t 201111201200 /tmp/file2
find . -newer /tmp/file1 -a ! -newer /tmp/file2

That’s it.

How to install gitweb in Ubuntu

After being told that I live in the stone age for using svn, I decided to try out git. Finally I got some time to continue learning git and setting the new environment. As a step one, we learned how to install git on Ubuntu. Then, I decided that I wanted to host my own repositories and we learned how to set up gitosis on Ubuntu. Now, after updating to Ubuntu 11.10 – Oneiric Ocelot, I am ready to continue setting up everything I need to start conveniently using git. So, in this post, I will be setting up the gitweb and documenting the process.

Gitweb is a convenient GUI that allows us to quickly see the project and diffs right in the browser. Before we move on to installing git web, make sure you have installed apache. Now, lets move on to installing gitweb:

sudo apt-get install gitweb

Now lets look in our /var/www folder:

cd /var/www

ls

I didn’t have gitweb folder here, so I created it:

sudo mkdir /var/www/gitweb

gitweb files should be in /usr/share/gitweb and we need them in our /var/www/gitweb, so lets create a symbolic link that will point to the files:

cd /var/www/gitweb

sudo ln -s /usr/share/gitweb/* .

To check if these are symbolic links, you can type:

ls -l

it should show what these files are linked to.

Next, locate the path to your git repositories. As per our install, we have it in /home/git/repositories. So, lets edit gitweb config to point to the right directory:

sudo gedit /etc/gitweb.conf

and replace:

$projectroot = "/var/cache/git";

to our path to git repositories, /home/git/repositories in my case to:

$projectroot = "/home/git/repositories";

Save the file and lets move on to next step – editing apache configuration. Open apache config for gitweb:

sudo gedit /etc/apache2/conf.d/gitweb

And edit it as follows (replace the paths if yours are different):

    RewriteEngine on
    RewriteRule ^/gitweb/([a-zA-Z0-9_\-]+\.git)/?(\?.*)?$ /cgi-bin/gitweb.cgi/$1 [L,PT]

    Alias /gitweb /home/git/repositories

    Options Indexes FollowSymlinks ExecCGI
    DirectoryIndex /cgi-bin/gitweb.cgi
    AllowOverride None

and save. Now its time to restart apache to apply the changes:

sudo /etc/init.d/apache2 restart

I got an error at first saying:

Syntax error on line 1 of /etc/apache2/conf.d/gitweb:
Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
Action 'configtest' failed.
The Apache error log may have more information.
...fail!

Which was because I needed to add rewrite package to apache:

sudo a2enmod rewrite

This time apache started with no errors.

Now you should be able to go to http://localhost/gitweb and see the gitweb page. If you have no public repositories yet, you may see “404 – No projects found” notice. To test it out, I went to my repo folder:

cd /home/git/repositories/

and changed the permissions on my gitosis-admin.git:

sudo chmod -R 755 gitosis-admin.git

Refresh the localhost/gitweb and ta-da! It shows a repository where I could click around and check things out. Since I didn’t want this repo to show publicly, I had to change the permissions back to:

sudo chmod -R 750 gitosis-admin.git

This is it for now. In the next git series posts I will try to go over creating new repositories, adding users, general git usage, installing redmine for project management and anything else I may find useful.

How to restore Unity when it disappears in Ubuntu 11.10

Well, after playing around the compizConfig Setting Manager I somehow screwed up the whole system. Unity along with any kind of menu was gone. Terminal Windows did not come up when pressing ALT+F# and even ctrl+alt+delete were not working. The only way terminal was able to come up was by pressing Ctrl+Alt+T . I did

unity --reset

but it did not work. What worked for me was typing:

ccsm

and enabling it again, disabling everything else that was conflicting. Hope this helps in case you are looking for the solution. :)

How to configure Unity in Ubuntu 11.10

I have been poking around the new Unity settings in Oneiric Ocelot.

First, check if you have compizconfig settings manager. If not, install by typing the following command in the terminal window:


sudo apt-get install compizconfig-settings-manager

Then go to unity dash and start typing compiz – it should show you the settings manager. Click it and go to “Desktop” options. I guess unity is a part of compiz now and this is where you can find “Ubuntu Unity Plugin” settings to edit the appearance.

I am kind of upset to see that there is no option to move the dock around. :(

Ubuntu Oneiric Ocelot – 11.10 review

Ububtu Oneiric Ocelot - 11.10

Ububtu Oneiric Ocelot - 11.10

As you all may know, the new version of Ubuntu was released on October 13, 2011, which is just over a week ago as of the time of writing this post. I wanted to upgrade right away, but decided to wait a bit for the user response as upgrades don’t always go smooth. Well, this one worked like a charm for me.

It took a little over an hour to perform the full upgrade. I made a backup just in case, which I also recommend doing. So far just a few programs need to be reinstalled. A ton of packages got deleted, but it’s mostly because they have a newer and improved versions.

As for the changes, the first thing I noticed was the desktop. It does look a lot better due to improved unity shell. I remember how much I hated it with the last upgrade when it just got added to Ubuntu and I am still not a big fan of it. It is, however, a lot more convenient and clean. I went from “definitely removing” to “may be I’ll poke around and keep it for a while”. I also don’t like the dock sitting on the right side, but I still have to look if I can relocate and change the size of it. The dash interface became a lot more usable too.

There are a few other small, but noticeable improvements, such as a new gnome login screen, login manager now uses LightDM.  Overall performance got slightly improved. Default mail client is now mozilla Thunderbird. Ubuntu now has a better support of 32 bit apps on 64 bit systems. It has a new backup client, which I still have to look into as it looks like they give you 5gb of online storage for free. Improved software center looks a lot better. These are just a few changes that I was pleased with.

There are other changes, but I think these are the biggest ones, at least for me. I like where it is going and will be waiting patiently for the next release. I want to see more improvements to unity as it looks like they put more focus on it now and it is here to stick.