Skip to content
This repository was archived by the owner on Oct 1, 2020. It is now read-only.

Commit b05fe94

Browse files
author
Alexander Paliarush
committed
- Integrated vagrant host manager plugin support to allow automatic /etc/hosts update
- Refined readme.md
1 parent 59a2836 commit b05fe94

File tree

4 files changed

+45
-64
lines changed

4 files changed

+45
-64
lines changed

README.md

+20-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Vagrant project for Magento 2 developers (optimized for Mac, Windows and \*nix hosts)
22

3+
* [What You get](#what-you-get)
4+
* [How to install](#how-to-install)
5+
* [Requirements](#requirements)
6+
* [Installation steps](#installation-steps)
7+
* [Default credentials and settings](#default-credentials-and-settings)
8+
* [GitHub limitations](#github-limitations)
9+
* [Day-to-day development scenarios](#day-to-day-development-scenarios)
10+
* [Reinstall Magento](#reinstall-magento)
11+
* [Clear magento cache](#clear-magento-cache)
12+
* [Debugging with XDebug](#debugging-with-xdebug)
13+
314
## What You get
415

516
It is expected that Magento 2 project source code will be located on the host and managed using [Composer](https://getcomposer.org/doc/00-intro.md).
@@ -14,18 +25,19 @@ With current configuration Vagrant will:
1425
1. Install and configure all software necessary for Magento 2
1526
1. Install the Magento 2 application
1627

17-
## Environment set up workflow
28+
## How to install
1829

1930
If you never used Vagrant before, read [Vagrant Docs](https://docs.vagrantup.com/v2/)
2031

21-
### Prerequisites
32+
### Requirements
2233
- [Vagrant](https://www.vagrantup.com/downloads.html) is installed and available globally in command line
34+
- [Host manager plugin for Vagrant](https://github.com/smdahlen/vagrant-hostmanager)
2335
- [VirtualBox](https://www.virtualbox.org/wiki/Downloads)
2436
- [Composer](https://getcomposer.org/doc/00-intro.md) is installed and is available globally in command line
2537
- Make sure you have SSH keys generated and associated with your github account, see [manual](https://help.github.com/articles/generating-ssh-keys/).
2638
:information_source: You can use another way of getting codebase instead of cloning, it does not matter for successful installation.
2739

28-
### To install the whole image from scratch
40+
### Installation steps
2941

3042
1. Run in command line from the directory which contains your projects:
3143
1. Prepare Magento codebase. This step is optional, just ensure you have 'magento2ce' directory with Magento code available.
@@ -47,26 +59,18 @@ If you never used Vagrant before, read [Vagrant Docs](https://docs.vagrantup.com
4759
cd vagrant-magento
4860
vagrant up
4961
```
50-
1. Add corresponding record to your `hosts` file on the host machine:
51-
52-
```
53-
192.168.10.11 magento2.vagrant
54-
```
5562
1. For **Windows hosts only**: after the installation is complete, [set up synchronization with PHP Storm](docs/phpstorm-configuration-windows-hosts.md)
5663
57-
### After installation
58-
59-
Upon a successful installation, you'll see the location and URL of the newly-installed Magento 2 application in console.
60-
See a list of [default credentials and settings](README.md#default-credentials).
61-
6264
### Default credentials and settings
65+
Upon a successful installation, you'll see the location and URL of the newly-installed Magento 2 application in console.
6366
64-
Web access:
67+
**Web access**:
6568
- Access storefront at `http://magento2.vagrant`
6669
- Access admin panel at `http://magento2.vagrant/admin/`
6770
- Magento admin user/password: `admin/123123q`
71+
- Rabbit MQ control panel: `http://magento2.vagrant:15672`, credentials `guest`/`guest`
6872
69-
Codebase and DB access:
73+
**Codebase and DB access**:
7074
- Path to your Magento installation on the VM:
7175
- Can be retrieved from environment variable: `echo ${MAGENTO_ROOT}`
7276
- On Windows hosts: `/var/www/magento2ce`
@@ -75,7 +79,7 @@ Codebase and DB access:
7579
- MySQL DB name: `magento`, `magento_integration_tests`
7680
- MySQL DB user/password: just use `mysql` with no user and password (`root/password` will be used by default)
7781
78-
### GitHub Limitations
82+
### GitHub limitations
7983
8084
Be aware that you may encounter GitHub limits on the number of downloads (used by Composer to download Magento dependencies).
8185

Vagrantfile

+19-10
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ end
99

1010
require 'pathname.rb'
1111
host_magento_dir = Pathname.new(Dir.pwd + '/../magento2ce').realpath.to_s
12+
magento_host_name = 'magento2.vagrant'
13+
magento_ip_address = '192.168.10.11'
1214

1315
# All Vagrant configuration is done below. The "2" in Vagrant.configure
1416
# configures the configuration version (we support older styles for
@@ -20,8 +22,6 @@ Vagrant.configure(2) do |config|
2022
config.vm.provider "virtualbox" do |vb|
2123
vb.memory = 3072 # Around 3Gb is necessary to be able to run tests
2224
end
23-
config.vm.network :private_network, ip: '192.168.10.11'
24-
config.vm.hostname = "magento2.vagrant"
2525

2626
config.vm.synced_folder '.', '/vagrant'
2727
if OS.is_windows
@@ -33,12 +33,14 @@ Vagrant.configure(2) do |config|
3333
config.vm.synced_folder host_magento_dir, guest_magento_dir, type: "nfs"
3434
end
3535

36+
shell_script_args = [
37+
OS.is_windows ? "1" : "0",
38+
guest_magento_dir,
39+
magento_host_name
40+
]
3641
config.vm.provision "install_environment", type: "shell" do |s|
3742
s.path = "install_environment.sh"
38-
s.args = [
39-
OS.is_windows ? "1" : "0",
40-
guest_magento_dir
41-
]
43+
s.args = shell_script_args
4244
end
4345

4446
if OS.is_windows
@@ -47,9 +49,16 @@ Vagrant.configure(2) do |config|
4749

4850
config.vm.provision "install_magento", type: "shell" do |s|
4951
s.path = "install_magento.sh"
50-
s.args = [
51-
OS.is_windows ? "1" : "0",
52-
guest_magento_dir
53-
]
52+
s.args = shell_script_args
53+
end
54+
55+
# Host manager plugin configuration
56+
config.hostmanager.enabled = true
57+
config.hostmanager.manage_host = true
58+
config.hostmanager.ignore_private_ip = false
59+
config.hostmanager.include_offline = true
60+
config.vm.define magento_host_name do |node|
61+
node.vm.hostname = magento_host_name
62+
node.vm.network :private_network, ip: magento_ip_address
5463
end
5564
end

install_environment.sh

+2-17
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,10 @@ set -ex
55

66
is_windows_host=$1
77
guest_magento_dir=$2
8+
magento_host_name=$3
89

910
apt-get update
1011

11-
# Determine external IP address
12-
set +x
13-
ip=`ifconfig eth1 | grep inet | awk '{print $2}' | sed 's/addr://'`
14-
echo "IP address is '${ip}'"
15-
set -x
16-
17-
# Determine hostname for Magento web-site
18-
host=`hostname -f`
19-
if [ -z ${host} ]; then
20-
# Use external IP address as hostname
21-
set +x
22-
host=${ip}
23-
echo "Use IP address '${host}' as hostname"
24-
set -x
25-
fi
26-
2712
# Setup Apache
2813
apt-get install -y apache2
2914
a2enmod rewrite
@@ -34,7 +19,7 @@ sed -i 's|www-data|vagrant|g' /etc/apache2/envvars
3419
# Enable Magento virtual host
3520
apache_config="/etc/apache2/sites-available/magento2.conf"
3621
cp /vagrant/magento2.vhost.conf ${apache_config}
37-
sed -i "s|<host>|${host}|g" ${apache_config}
22+
sed -i "s|<host>|${magento_host_name}|g" ${apache_config}
3823
sed -i "s|<guest_magento_dir>|${guest_magento_dir}|g" ${apache_config}
3924
a2ensite magento2.conf
4025

install_magento.sh

+4-21
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,7 @@ set -ex
77

88
is_windows_host=$1
99
guest_magento_dir=$2
10-
11-
# Determine external IP address
12-
set +x
13-
ip=`ifconfig eth1 | grep inet | awk '{print $2}' | sed 's/addr://'`
14-
echo "IP address is '${ip}'"
15-
set -x
16-
17-
# Determine hostname for Magento web-site
18-
host=`hostname -f`
19-
if [ -z ${host} ]; then
20-
# Use external IP address as hostname
21-
set +x
22-
host=${ip}
23-
echo "Use IP address '${host}' as hostname"
24-
set -x
25-
fi
10+
magento_host_name=$3
2611

2712
cd ${guest_magento_dir}
2813

@@ -48,7 +33,7 @@ install_cmd="./bin/magento setup:install \
4833
--db-name=magento \
4934
--db-user=root \
5035
--backend-frontname=${admin_frontame} \
51-
--base-url=http://${host}/ \
36+
--base-url=http://${magento_host_name}/ \
5237
--language=en_US \
5338
--timezone=America/Chicago \
5439
--currency=USD \
@@ -82,10 +67,8 @@ fi
8267
set +x
8368
echo "
8469
Magento application was deployed to ${guest_magento_dir} and installed successfully
85-
Access storefront at http://${host}/
86-
Access admin panel at http://${host}/${admin_frontame}/
87-
88-
Don't forget to update your 'hosts' file with '${ip} ${host}'"
70+
Access storefront at http://${magento_host_name}/
71+
Access admin panel at http://${magento_host_name}/${admin_frontame}/"
8972

9073
if [ ${is_windows_host} -eq 1 ]; then
9174
echo "

0 commit comments

Comments
 (0)