How to sync Google Drive storage on Ubuntu with Rclone

Recommended Ubuntu book

There is no official Google Drive sync for Linux at the moment and we needed samba drive to backup files to Google Drive. To accomplish the goal, we decided to use Rsync.

Following installation instructions (https://rclone.org/install/), we execute the following commands.

Download:


curl -O https://downloads.rclone.org/rclone-current-linux-amd64.zip

Since its a new ubuntu installation, we need to install unzip package:


sudo apt install unzip

Unzip and navigate to new directory:


unzip rclone-current-linux-amd64.zip
cd rclone-*-linux-amd64

Copy the binary file and change permissions:


sudo cp rclone /usr/bin/
sudo chown root:root /usr/bin/rclone
sudo chmod 755 /usr/bin/rclone

Install manpage


sudo mkdir -p /usr/local/share/man/man1
sudo cp rclone.1 /usr/local/share/man/man1/
sudo mandb

Configure rclone:


rclone config

Enter “n” for new remote since its a new remote and name it “remote” (following the guide at https://rclone.org/drive/).

“Google Drive” is under point 10, so we enter “10” and press Enter. It then asks for “client_id”, “client_secret” and “service_account_file”, which we leave empty and press Enter.

Then we enter “n” for auto config. It gives us a link to open which we open and get the auth code. Paste it in and continue. Press “n” for team drive, “y” to confirm configuration and press “q” to exit config.

 

Create a bash script:


cd ~
sudo mkdir cron
cd cron
sudo vi google_drive_push.sh

Add this script (change folder name as needed and make sure it exists in Google Drive):


#!/bin/bash
if pidof -o %PPID -x "google_drive_push.sh"; then
exit 1
fi
rclone sync /home/MyShareFolder/ remote:MyShareFolder/ -v -u --checkers 1 --transfers 1 --log-file=/home/user/cron/rclone-upload.log
exit

Make it executable


sudo chmod a+x google_drive_push.sh

run


sudo sh google_drive_push.sh

How to delete all lines in vi or vim editor

Recommended Ubuntu book

To delete all the lines of the file in vi or vim, makes sure you have your file opened in the command mode (esq) and not the input mode (i). It takes two steps:

  1. Go to the top of the file by pressing “gg”.
  2. Press “dG” (notice capital “G”, “d” followed by “Shift+g”).

That’s it. You can now save the empty file with “ZZ”.

E: Unable to locate package mongodb-org

Recommended Ubuntu book

I got this error “E: Unable to locate package mongodb-org” when following installation instructions from mongodb.com

Solution was pretty simple, instead of


sudo apt-get install -y mongodb-org

try


sudo apt-get install mongodb

Command to find Ubuntu version

Recommended Ubuntu book

In order to find out which version of ubuntu, open Ubuntu command line and type


lsb_release -a

This command should output something like


No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.10
Release: 16.10
Codename: yakkety

Increasing php 5.6 performance of ec2 instance with opcache and php-fpm

Recommended Ubuntu book

We have installed Apache 2.4 and php 5.6 while migrating from windows server to aws and things have been running pretty good on t2.micro instance for the web server and RDS instance for the database. However, it can run better and this is where opcache and php-fpm come into play.

To install php-fpm and opchache for php 5.6 on amazon linux, simply run:


sudo yum install php56-fpm
sudo yum install php56-opcache

You would need to have proxy and proxy_fcgi for php-fpm, check if those are enabled:


httpd -M | grep proxy

if not, enable:


sudo a2enmod proxy proxy_fcgi

To enable php-fpm we had to edit our vhosts to include this configuration:


vi /etc/httpd/conf.d/vhost.conf


<FilesMatch \.php$>
SetHandler "proxy:fcgi://127.0.0.1:9000"
</FilesMatch>

For reference, more details on configuration here.

start php-fpm, restart apache


sudo service php-fpm restart
sudo service httpd restart

Opcache gave us a significant performance boost.

How to migrate website to Amazon EC2 and RWS

Recommended Ubuntu book

We have just migrated a site from Windows Server to Amazon RDS and EC2. Basically, we needed to move to the cloud separating database from the web server. RDS now runs MySQL 5.7 and EC2 runs on Amazon Linux with Apache. Before the start, on our Windows server, we installed putty to be able to connect to the web server and WinSCP to transfer all the files.

Initial desicion was to keep MySQL, but when choosing between Linux distributions, Amazon Linux seemed like a good option. It is based on CentOS, however, it has been heavily modified to suit AWS. After reading quite a bit about it and looking at different benchmark case studies, it looked like a good choice. It is fast and responsive. It is built and maintained by Amazon for better integration with management tools pre-installed. It is getting updated on a 6-month release cycle and upgrading usually goes without any problems. However, this may be not the best option if you need special packages and community support. It took us some time to decide between AL and Ubuntu.

Step 1, Set Up and Adding Security Groups.

Reference http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_SettingUp.html if needed to sign up, create user and login. Once logged in, select the region where our servers will reside in the top right corner, in our case, Oregon.  We now need to create two security groups, one used for RDS database instance and one for EC2 web instance. Click home button and navigate to “VPC” under “Networking”.

Go to “Security Groups” -> “Create Security Group” to create new security group for our RDS instance. Give it a name and description, such as site-name-rds. Select VPC and click create.

Select created group and edit inbound rules. We need to add ip address from which we will be connecting, which is the server we will be transferring database from.

Your ip will be masked as XXX.XXX.XXX.XXX, replace as needed.  Select MySQL/Aurora (3306), add XXX.XXX.XXX.XXX/32 ip address. It is followed by /32 for exact match ip. Use XXX.XXX.XXX.0/24 for a range of all ip addresses in the subnet.

We will later add one more ip of EC2 web instance to this group.

Once again, go to “Security Groups” -> “Create Security Group” to create new security group for our EC2 instance. Give it a name and description, such as site-name-web. Select VPC and click create.

To allow all incoming traffic over HTTP and HTTPS lets add:

HTTP(80) 0.0.0.0/0 and HTTPS(443) 0.0.0.0/0.

Next, we need to be able to SSH, so lets add:

SSH(22) XXX.XXX.XXX.XXX/32

Save.

Step 2, Set Up RDS Instance.

Reference http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_GettingStarted.CreatingConnecting.MySQL.html if needed.

Make sure that the right region where our servers will reside is selected in the top right corner, in our case, Oregon. Click home button and navigate to “RDS” under “Database”.

Click Launch DB Instance. Select MySQL and then MySQL version. We will use 5.7.11, db.t2.small that will give us 1 vCPU and 2Gib RAM. Since this is a production instance, we will use Multi-AZ Deployment for maximum availability. We will also use 12GB on General Purpose SSD for our databases.

Next, we name our insance site-name-cloud-db, chose db username and password and proceed to “Next Step”. Here we pick the right VPC, Subnet Group, leave it publicly accessible and pick our site-name-rds security group. We leave everything else as is, changing only backup window to 14 days.

Launch DB Instance. It is now being created. You can click “View Your DB Instances” and watch the status. Once changed to “available”, we can start using it.

Step 3, Set Up EC2 Instance.

Reference http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Tutorials.WebServerDB.CreateWebServer.html if needed.

Make sure that the right region where our servers will reside is selected in the top right corner, in our case, Oregon. Click home button and navigate to “EC2” under “Compute”.

Before we begin, lets get a key pair that we will need to connect to the server once it is set up. For reference, use http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/get-set-up-for-amazon-ec2.html#create-a-key-pair . On the left side menu, under “network & security” click “Key Pairs”. Click create key pair, give it a name, such as my-site-key-pair, click create and it will be automatically downloaded. Save it in the safe location on your machine.

Next, click on “Instances” on the left menu and click “Launch Instance”.

Select Amazon Linux AMI. For our simple server we pick t2.micro with 1 vCPU and 1GiB of Memory.

Click “Next” to configure instance details, where we left everything default. On the next screen we changed the storage to suit our needs, which is 100GiB general purpose SSD. On the next screen we create a tag of site-name-web and move forward. Next screen gives us an option to pick existing security group site-name-web create earlier.

Click Launch, verify that information is correct, pick key pair created earlier and click “Launch Instances”. It is now being created. Click “View Instances” and watch the status. Once changed to “running”, we can start using it.

Step 4, Add ip of new EC2 Instance to RDS Security Group.

Run this command on EC2 server to get the ip address and get ip in inet addr under eth0

ifconfig

Edit security group for your site-name-rds and add ip or subnet as:

MySQL/Aurora (3306) 172.XX.X.0/24

Save.

Step 5, Set Up putty and Connect.

Launch PuTTYgen. Make sure SSH-2-RSA option is checked. Click “Load”, in the drop down option select “All Files”, locate the .pem file downloaded earlier after creating Key Pairs, “save private key” with the same name and .ppk extension.

Now you need to get your public dns name. Once EC2 instance is loaded, click on it and in the “Description” below copy Public DNS.

Start putty. In the Host Name field enter user@public-dns, such as ec2-user@ec2-XX-XX-XXX-XX.us-west-2.compute.amazonaws.com. Amazon Linux instances get created with ec2-user by default. Confirm that selected port is 22 and connection type is SSH.

Enter the name in “saved sessions”, such as site-name-aws and click save.

On the left hand side menu in putty navigate to Connection – SSH – Auth. Click Browse and locate .ppk key created using PuTTYgen earlier. Go back to “Session” menu, click save and then open. Click “Yes” if it displays a message and you should be on the server and ready to configure.

Step 6, Set Up Web Server.

First, lets update the packages

sudo yum update -y

Next, install apache, php 5.6 and mysql driver

sudo yum install -y httpd24 php56 php56-mysqlnd

Next, additional packages, if needed. For instance, we use gd image library and need to add it

sudo yum install php56-gd

Soap package:

sudo yum install php56-soap

Imagick, which requires php devel, php pear and a few others

sudo yum install kernel-devel gcc gcc-c++

sudo yum install php56-devel

sudo yum install php-pear # This line installs pecl as well as pear

sudo yum install ImageMagick-devel

sudo pecl install imagick

which requires us to open php.ini and append a line at the end of the file to load the library

sudo vi /etc/php.ini

press “i” to edit the file, add this line at the end

extension=imagick.so

click “esc” and “zz” while holding “shift” to save.

Lets start apache

sudo service httpd start

Change config to autostart on boot

sudo chkconfig httpd on

Add www group and current user to that group along with apache group

sudo groupadd www

sudo usermod -a -G www ec2-user

Lets change permissions on www folder, exit the server and re-login

sudo chown -R root:www /var/www

exit

This is it for the web server, however, we host a couple websites on it. We will create virtual hosts next

cd /var/www/

sudo mkdir vhosts

cd vhosts

sudo mkdir site-1(actual name of the site)

sudo mkdir site-2(actual name of the site)

sudo chown -R root:www /var/www

sudo chmod 2775 /var/www

find /var/www -type d -exec sudo chmod 2775 {} \;

find /var/www -type f -exec sudo chmod 0664 {} \;

cd /etc/httpd/conf.d

sudo touch vhost.conf

sudo vi /etc/httpd/conf.d/vhost.conf

paste and replace site-1.com and site-2.com with actual sites:


<VirtualHost *:80>

# Leave this alone. This setting tells Apache that

# this vhost should be used as the default if nothing

# more appropriate is available.

ServerName default:80

# REQUIRED. Set this to the directory you want to use for

# your “default” site files.

DocumentRoot /var/www/html

# Optional. Uncomment this and set it to your admin email

# address, if you have one. If there is a server error,

# this is the address that Apache will show to users.

#ServerAdmin you@example.com

# Optional. Uncomment this if you want to specify

# a different error log file than the default. You will

# need to create the error file first.

#ErrorLog /var/www/vhosts/logs/error_log

</VirtualHost>

 

<VirtualHost *:80>

# REQUIRED. Set this to the host/domain/subdomain that

# you want this VirtualHost record to handle.

ServerName site-1.com

# Optional. You can specify additional host names that

# serve up the same site. This can be top-level, domains,

# sub-domains, and can even use wildcard subdomains such

# as *.yourdomain.com – just separate each host name

# with a single space.

ServerAlias www.site-1.com

# REQUIRED. Set this to the directory you want to use for

# this vhost site’s files.

DocumentRoot /var/www/vhosts/site-1

# Optional. Uncomment this and set it to your admin email

# address, if you have one. If there is a server error,

# this is the address that Apache will show to users.

#ServerAdmin you@example.com

# Optional. Uncomment this if you want to specify

# a different error log file than the default. You will

# need to create the error file first.

ErrorLog /var/www/vhosts/logs/site-1_error_log

# REQUIRED. Let’s make sure that .htaccess files work on

# this site. Don’t forget to change the file path to

# match your DocumentRoot setting above.

<Directory /var/www/vhosts/site-1>

AllowOverride All

</Directory>

</VirtualHost>

 

<VirtualHost *:80>

# REQUIRED. Set this to the host/domain/subdomain that

# you want this VirtualHost record to handle.

ServerName site-2.com

# Optional. You can specify additional host names that

# serve up the same site. This can be top-level, domains,

# sub-domains, and can even use wildcard subdomains such

# as *.yourdomain.com – just separate each host name

# with a single space.

ServerAlias www.site-2.com

# REQUIRED. Set this to the directory you want to use for

# this vhost site’s files.

DocumentRoot /var/www/vhosts/site-2

# Optional. Uncomment this and set it to your admin email

# address, if you have one. If there is a server error,

# this is the address that Apache will show to users.

#ServerAdmin you@example.com

# Optional. Uncomment this if you want to specify

# a different error log file than the default. You will

# need to create the error file first.

ErrorLog /var/www/vhosts/logs/site-2_error_log

# REQUIRED. Let’s make sure that .htaccess files work on

# this site. Don’t forget to change the file path to

# match your DocumentRoot setting above.

<Directory /var/www/vhosts/site-2>

AllowOverride All

</Directory>

</VirtualHost>

Next, lets create log directory

cd /var/www/vhosts/

sudo mkdir logs

Restart apache

sudo service httpd restart

Step 7, Set Up SSL Keys and SSL Virtual Directories.

Download and install WinSCP and import connection configuration from Putty.

Export current certificates from existing site. In our case it was windows server and we used this resource for reference – https://www.sslshopper.com/move-or-copy-an-ssl-certificate-from-a-windows-server-to-an-apache-server.html that gave us site.pfx file. Upload the file to /home/ec2-user via WinSCP.

Now, in our ssh session (putty) we need to convert and store the keys:

cd /home/ec2-user/

openssl pkcs12 -in estoresbyzome.pfx -out estoresbyzome.txt -nodes

copy each key and certificate from and including opening —- , to and including closing of each section while pasting it into site.key, site.crt, and if there is more than 2 – intermidiateCA.crt. Then move them to private folder and change permissions.

sudo cp site.key /etc/pki/tls/private/site.key

sudo cp site.crt /etc/pki/tls/private/site.crt

sudo cp intermediateCA.crt /etc/pki/tls/private/intermediateCA.crt

cd /etc/pki/tls/private/

sudo chmod 600 site.key

sudo chmod 600 site.crt

sudo chmod 644 intermediateCA.crt

Install mod ssl for apache and restart

sudo yum install -y mod24_ssl

sudo service httpd restart

Next, we need to change ssl certificate and key in ssl.conf

sudo vi /etc/httpd/conf.d/ssl.conf

to


SSLCertificateFile /etc/pki/tls/private/site.crt

SSLCertificateKeyFile /etc/pki/tls/private/site.key

sudo service httpd restart

Add virtual host entries:

cd /etc/httpd/conf.d/

sudo vi vhost.conf

At the end of the file add:


<VirtualHost *:443>

ServerName site-1.com

ServerAlias www.site-1.com

DocumentRoot /var/www/vhosts/site-1

SSLEngine on

SSLCertificateFile /etc/pki/tls/private/site.crt

SSLCertificateKeyFile /etc/pki/tls/private/site.key

ErrorLog /var/www/vhosts/logs/site-1_error_log

</VirtualHost>

 

<VirtualHost *:443>

ServerName site-2.com

ServerAlias www.site-2.com

DocumentRoot /var/www/vhosts/site-2

SSLEngine on

SSLCertificateFile /etc/pki/tls/private/site.crt

SSLCertificateKeyFile /etc/pki/tls/private/site.key

ErrorLog /var/www/vhosts/logs/site-2_error_log

</VirtualHost>

Save and restart apache, this should be it

sudo service httpd restart

Step 8, Display Maintenance Message on Live Site.

Since our site uses the same header, displaying maintenance message is as easy as pasting html and php exit at the top of it:


&lt;!doctype html&gt;
&lt;title&gt;Site Maintenance&lt;/title&gt;
&lt;style&gt;
body { text-align: center; padding: 150px; }
h1 { font-size: 50px; }
body { font: 20px Helvetica, sans-serif; color: #333; }
article { display: block; text-align: left; width: 650px; margin: 0 auto; }
a { color: #dc8100; text-decoration: none; }
a:hover { color: #333; text-decoration: none; }
&lt;/style&gt;

&lt;p&gt;&lt;img src="img/logo.gif" alt="Site" title="Site" width="150" height="100" align="left"&gt;&lt;/p&gt;
&lt;article&gt;
&lt;h1&gt;We&amp;rsquo;ll be back soon!&lt;/h1&gt;
&lt;div&gt;
&lt;p&gt;Sorry for the inconvenience but we&amp;rsquo;re performing some maintenance at the moment. We&amp;rsquo;ll be back online shortly!&lt;/p&gt;
&lt;p&gt;&amp;mdash; Site-1 Team&lt;/p&gt;
&lt;/div&gt;
&lt;/article&gt;
&lt;?php
exit;
?&gt;

Step 9, Backup Database.

Stop the production db and start with locked tables if exit in the header doesn’t stop complete access before the backup.

mysqldump -u root -p -h 127.0.0.1 site-1-db > c:\Backups\site-1-db(build_date).sql

mysqldump -u root -p -h 127.0.0.1 site-2-db > c:\Backups\site-2-db(build_date).sql

Step 10, Stop Production Database.

Since we are running a Windows server, run this command in command line

net stop mysql

Step 11, Create, Restore the Database and Update Schema.

mysql -u zome -p -h site-cloud-db.your-database-endpoint.us-west-2.rds.amazonaws.com

create database site-2;

exit;

mysql -u zome -p -h site-cloud-db.your-database-endpoint.us-west-2.rds.amazonaws.com site-1-db < c:\Backups\right_backup.sql

mysql -u zome -p -h site-cloud-db.your-database-endpoint.us-west-2.rds.amazonaws.com site-2-db < c:\Backups\right_backup_2.sql

We also had a couple of MyISAM tables and converted them to InnoDB, connect to instance

mysql -u zome -p -h site-cloud-db.your-database-endpoint.us-west-2.rds.amazonaws.com

login and check if there are any MyISAM

use INFORMATION_SCHEMA;

SELECT * FROM `TABLES` where engine = 'MyISAM' and (TABLE_SCHEMA = 'site-1-db' OR TABLE_SCHEMA = 'site-2-db’ ) ORDER BY `ENGINE` DESC

use site-1-db;

ALTER TABLE `myisam-table1` ENGINE=INNODB;

ALTER TABLE `myisam-table2` ENGINE=INNODB;

etc.

Step 12, Transfer Files and change db connections.

Login via WinSCP and transfer all the files to the right vhost directories. Change site configurations to point to the new database.

Step 13, change permissions to write directories for apache.

To make directories writable to apache execute the following command on the directories that need write access:
sudo chown -R root:apache directory-name

Step 14, Test.

To test before going live edit the c:\windows\system32\drivers\etc\hosts file on local machine to point to the right server by specifying ip address:
XXX.XXX.XXX.XXX site-1.com www.site-1.com
XXX.XXX.XXX.XXX site-2.com www.site-2.com

Step 15, Change DNS to Point to the New Site.

If you are using AWS for DNS, navigate to Route 53, if not, point your domain A record to the new ip address. Perform the last set of testing and the site in now on AWS.

This is it

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

Recommended Ubuntu book

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

Recommended Ubuntu book

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

Recommended Ubuntu book

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

Recommended Ubuntu book

 

<edit> 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.