Skip to content

Instantly share code, notes, and snippets.

@okovalov
Last active August 24, 2017 02:53
Show Gist options
  • Save okovalov/88d23294b01c0da513fd357917e60d61 to your computer and use it in GitHub Desktop.
Save okovalov/88d23294b01c0da513fd357917e60d61 to your computer and use it in GitHub Desktop.
Pre-reqs
a) install VirtualBox and Vagrant
b) add homestead box (once vagrant is installed) - vagrant box add laravel/homestead
1) create local directory (source code would be placed there)
mkdir ~/prj/Commer/v2/lac2-magento.dev
1.a) cd ~/prj/Commer/v2/lac2-magento.dev/
1.b) git init
1.c) git remote add origin git@git-as-commer:CommerGroup/lac-magento2.git
NOTE: git-as-commer is an alias from ssh config
$ cat ~/.ssh/config
Host git-as-commer
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_okovalov_commer
IdentitiesOnly yes
basically I have two different github accounts, so those are authorized on github by different rsa keys, so this particular repo
is accessed by id_rsa_okovalov_commer. with that being said , you might need to adjust the config with your ssh alias name
1.d) git fetch
NOTE: You should see a list of branches - smth like that
* [new branch] 30179_outbound_subsciber -> origin/30179_outbound_subsciber
* [new branch] 30228_listeners_refactoring -> origin/30228_listeners_refactoring
* [new branch] 30390_Shipstation -> origin/30390_Shipstation
* [new branch] 30409_bambora -> origin/30409_bambora
* [new branch] 30455_auto_brands -> origin/30455_auto_brands
* [new branch] 30474_order_listener -> origin/30474_order_listener
* [new branch] 30494_bambora_schogini_beanstream -> origin/30494_bambora_schogini_beanstream
* [new branch] 30545_customer_export -> origin/30545_customer_export
* [new branch] feature/OK-30496-expose-attribute-set -> origin/feature/OK-30496-expose-attribute-set
* [new branch] feature/OK-30623-styles-prereq-attr -> origin/feature/OK-30623-styles-prereq-attr
* [new branch] feature/OK-30624-redifine-product-api -> origin/feature/OK-30624-redifine-product-api
* [new branch] frontend -> origin/frontend
* [new branch] live -> origin/live
* [new branch] mantis_29796 -> origin/mantis_29796
* [new branch] mantis_30122 -> origin/mantis_30122
1.e) git checkout live
2) create local directory for the homestead box
mkdir ~/Boxes/HomesteadLac2Magento
2.a) cd ~/Boxes/HomesteadLac2Magento
git clone https://github.com/laravel/homestead.git ./
2.b) bash init.sh (for Windows init.bat) - will create Homestead.yaml
2.c) replace Homestead.yaml content with following config
-----
ip: "192.168.10.12"
memory: 2048
cpus: 1
provider: virtualbox
mariadb: true
name: homestead-lac2-magento
authorize: ~/.ssh/id_rsa.pub ### NOTE here is your pub file should come
keys:
- ~/.ssh/id_rsa_okovalov_commer ## NOTE - your private key should be used and path changed accordingly
folders:
- map: ~/Code # create this folder on your host machine - not mandatory but would be nice to have for file exchange
to: /home/vagrant/Code
- map: /home/oleks/prj/Commer/v2/lac2-magento.dev ## Full path to the magento source folder from #1
to: /home/vagrant/prj/Commer/v2/lac2-magento.dev
sites:
- map: lac2-magento.dev ## the hostname to access in the browser once magento is installed. must match with the from from magento install command- see below
to: /home/vagrant/prj/Commer/v2/lac2-magento.dev
php: "7.0"
params:
- key: MAGE_ROOT
value: /home/vagrant/prj/Commer/v2/lac2-magento.dev
- key: MAGE_MODE
value: developer
databases:
- magentodb
-----
2.d) vagrant up
2.e) ssh to your vagrant box - vagrant ssh
3) check your magento website in the browser - open http://lac2-magento.dev (you should see Autoload error since we have not run composer install yet)
you also might need to update your /etc/hosts file - depends whater you have certain vagrant plugins installed
4) inside your box
4.a) configure ngnix vhost file
4.b) sudo su
4.c) cp /etc/nginx/sites-available/lac2-magento.dev /etc/nginx/sites-available/lac2-magento.dev.backup
4.d) replace content of /etc/nginx/sites-available/lac2-magento.dev with following content
-----
upstream fastcgi_backend {
server unix:/var/run/php/php7.0-fpm.sock;
}
server {
listen 80;
server_name lac2-magento.dev;
set $MAGE_ROOT /home/vagrant/prj/Commer/v2/lac2-magento.dev;
set $MAGE_MODE developer;
access_log /var/log/nginx/lac2-magento.dev-access.log;
error_log /var/log/nginx/lac2-magento.dev-error.log;
include /home/vagrant/prj/Commer/v2/lac2-magento.dev/nginx.conf.sample;
}
-----
4.e) systemctl restart nginx
5) configure maria db
5.a) mysqladmin -u root password mypassword
5.b) mysql_secure_installation (after running this you will see a prompt with several Y/n questions) - take a look at this example and simply repeat it as it is
root@homestead:/home/vagrant# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none): ##### HERE YOU SHOULD ENTER mypassword - from the previous step #5.a
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
You already have a root password set, so you can safely answer 'n'.
Change the root password? [Y/n] n
... skipping.
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y
... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
root@homestead:/home/vagrant#
5.c) test mysql login
mysql -u root -p (you will be prompted for the password - enter which is mypassword)
you should see
root@homestead:/home/vagrant# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 10.1.25-MariaDB-1~xenial mariadb.org binary distribution
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
5.d) a few commands to run in mysql console
MariaDB [(none)]> create database magentodb;
ERROR 1007 (HY000): Can't create database 'magentodb'; database exists
MariaDB [(none)]>
MariaDB [(none)]> CREATE USER 'magentouser'@'localhost' IDENTIFIED BY 'magentopassword';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> grant all privileges on magentodb.* to magentouser@localhost identified by 'magentopassword';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> \q
Bye
6) Install vendors
exit from sudo mode
root@homestead:/home/vagrant# exit
exit
vagrant@homestead:~$
6.a) cd /home/vagrant/prj/Commer/v2/lac2-magento.dev/
6.b) before running 'composer install' you need to switch to php7.0
vagrant@homestead:~/prj/Commer/v2/lac2-magento.dev$ sudo update-alternatives --set php /usr/bin/php7.0
update-alternatives: using /usr/bin/php7.0 to provide /usr/bin/php (php) in manual mode
vagrant@homestead:~/prj/Commer/v2/lac2-magento.dev$ sudo update-alternatives --set phar /usr/bin/phar7.0
update-alternatives: using /usr/bin/phar7.0 to provide /usr/bin/phar (phar) in manual mode
vagrant@homestead:~/prj/Commer/v2/lac2-magento.dev$ sudo update-alternatives --set phar.phar /usr/bin/phar.phar7.0
update-alternatives: using /usr/bin/phar.phar7.0 to provide /usr/bin/phar.phar (phar.phar) in manual mode
vagrant@homestead:~/prj/Commer/v2/lac2-magento.dev$
6.c) install ext-mcrypt
sudo apt-get install php7.0-mcrypt
that will fetch a few more extensions
vagrant@homestead:~/prj/Commer/v2/lac2-magento.dev$ sudo apt-get install php7.0-mcrypt
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
php7.0-bcmath php7.0-cli php7.0-common php7.0-curl php7.0-dev php7.0-fpm php7.0-gd php7.0-imap php7.0-intl php7.0-json php7.0-mbstring php7.0-mysql php7.0-opcache php7.0-pgsql php7.0-readline
php7.0-soap php7.0-sqlite3 php7.0-xml php7.0-zip
The following NEW packages will be installed:
php7.0-mcrypt
The following packages will be upgraded:
php7.0-bcmath php7.0-cli php7.0-common php7.0-curl php7.0-dev php7.0-fpm php7.0-gd php7.0-imap php7.0-intl php7.0-json php7.0-mbstring php7.0-mysql php7.0-opcache php7.0-pgsql php7.0-readline
php7.0-soap php7.0-sqlite3 php7.0-xml php7.0-zip
19 upgraded, 1 newly installed, 0 to remove and 131 not upgraded.
Need to get 5,237 kB of archives.
6.d) update php.ini files
sudo vim /etc/php/7.0/fpm/php.ini
sudo vim /etc/php/7.0/cli/php.ini
and increase the memory limit and php execution time and turn on zlib compression by adding the following lines at the end of the files:
memory_limit = 512M
max_execution_time = 1800
zlib.output_compression = On
6.e) restart php fpm
sudo systemctl restart php7.0-fpm
6.f) composer install -v
7) Install magento
Here we will use a long console command.
A few things to take a look at :
backend-frontname = the admin page for our magento site, we use 'adminlogin'.
Key = our magento keys, we can generate it, or find it random on http://randomkeygen.com/.
Base-url = make sure it is same with virtual host configuration.
db-name , user and password = are from mysql config step
so the command is:
bin/magento setup:install --backend-frontname="adminlogin" \
--key="biY8vdWx4w8KV5Q59380Fejy36l6ssUb" \
--db-host="localhost" \
--db-name="magentodb" \
--db-user="magentouser" \
--db-password="magentopassword" \
--language="en_US" \
--currency="USD" \
--timezone="America/New_York" \
--use-rewrites=1 \
--use-secure=0 \
--base-url="http://lac2-magento.dev" \
--base-url-secure="https://lac2-magento.dev" \
--admin-user=adminuser \
--admin-password=admin123@ \
[email protected] \
--admin-firstname=admin \
--admin-lastname=user \
--cleanup-database
At the end of the installation procedure you should see these lines:
[SUCCESS]: Magento installation complete.
[SUCCESS]: Magento Admin URI: /adminlogin
8) Set developer mode for convenience
bin/magento deploy:mode:set developer
9) Make it easier to rebuild magento after switching branches
vagrant@homestead:~/prj/Commer/v2/lac2-magento.dev$ mkdir ~/bin
vagrant@homestead:~/prj/Commer/v2/lac2-magento.dev$ vim ~/bin/rebuild_magento.sh
paste there
-----
echo "Starting.. Go and grab a coffee.."
echo "Step 1 - Flushing cache"
php bin/magento cache:flush;
php bin/magento cache:clean;
echo "Step 2 - Upgrading Setup"
php bin/magento setup:upgrade;
echo "Step 3 - Recompiling DI"
php bin/magento setup:di:compile;
echo "Step 4 - Running re-index"
php bin/magento indexer:reindex;
echo "Step 5 - Deploying generic static content"
php bin/magento setup:static-content:deploy
echo "Step 6 - Deploying static content for en_CA"
php bin/magento setup:static-content:deploy en_CA
echo "Step 7 - Deploying static content for fr_CA"
php bin/magento setup:static-content:deploy fr_CA
echo "Step 8 - Deploying generic themes"
php bin/magento dev:source-theme:deploy
echo "Step 9 - Deploying themes for locale en_CA"
php bin/magento dev:source-theme:deploy --locale="en_CA"
echo "Step 10 - Deploying themes for locale fr_CA"
php bin/magento dev:source-theme:deploy --locale="fr_CA"
echo "All is done"
-----
vagrant@homestead:~/prj/Commer/v2/lac2-magento.dev$ chmod a+x ~/bin/rebuild_magento.sh
From now on, after switching magento branch, you could simply type in rebuild_magento.sh , press enter and wait untill all is done
PS - regrading xdebug + phpstorm - once you run debugger in phpstorm, you would need to set up a project mapping between local project files location and its remote location (on a guest machine)
/home/oleks/prj/Commer/v2/lac2-magento.dev -> /home/vagrant/prj/Commer/v2/lac2-magento.dev/pub
othervise it wont know where bootstrap is located
Just in case - here is xdebug.ini config as it is now
---
zend_extension=xdebug.so
xdebug.remote_enable = 1
xdebug.remote_connect_back = 1
xdebug.remote_port = 9000
xdebug.max_nesting_level = 512
#xdebug.remote_handler=dbgp
#xdebug.remote_mode=req
#xdebug.remote_host=lac2-magento.dev
#xdebug.var_display_max_depth = -1
#xdebug.var_display_max_children = -1
#xdebug.var_display_max_data = -1
xdebug.idekey = "PHPSTORM"
------
PPS - there is one bug (what I am aware of) - once you restart your vm, your ngnix is not starting for some reason.. despite the fact it is set in autoload.
so to fix that, simply manually restart it once your vm is booted up
systemctl restart nginx
@westpole-commer
Copy link

Also it would be useful to expend a list with sudo npm install to enable Front-End tools.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment