Skip to content

Commit 5d6a24b

Browse files
committed
Merge pull request #3 from paliarush/develop
Develop
2 parents d8b0d27 + b05fe94 commit 5d6a24b

File tree

8 files changed

+128
-103
lines changed

8 files changed

+128
-103
lines changed

README.md

Lines changed: 24 additions & 21 deletions
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,32 +59,27 @@ 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:
70-
- Path to your Magento installation on the VM: `/var/www/magento2ce`
73+
**Codebase and DB access**:
74+
- Path to your Magento installation on the VM:
75+
- Can be retrieved from environment variable: `echo ${MAGENTO_ROOT}`
76+
- On Windows hosts: `/var/www/magento2ce`
77+
- On Mac, \*nix hosts: the same as on host
7178
- MySQL DB host: `localhost` (not accessible remotely)
7279
- MySQL DB name: `magento`, `magento_integration_tests`
7380
- MySQL DB user/password: just use `mysql` with no user and password (`root/password` will be used by default)
7481
75-
### GitHub Limitations
82+
### GitHub limitations
7683
7784
Be aware that you may encounter GitHub limits on the number of downloads (used by Composer to download Magento dependencies).
7885
@@ -112,7 +119,3 @@ XDebug is already configured to connect to the host machine automatically. So ju
112119
1. Set XDEBUG_SESSION=1 cookie (e.g. using 'easy Xdebug' extension for Firefox). See [XDebug documentation](http://xdebug.org/docs/remote) for more details
113120
1. Start listening for PHP Debug connections in PhpStorm. See how to [integrate XDebug with PhpStorm](https://www.jetbrains.com/phpstorm/help/configuring-xdebug.html#integrationWithProduct)
114121
1. Set beakpoint or set option in PhpStorm menu 'Run -> Break at first line in PHP scripts'
115-
116-
## Related Repositories
117-
118-
- https://github.com/buskamuza/magento2-product-vagrant

Vagrantfile

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ module OS
77
end
88
end
99

10+
require 'pathname.rb'
11+
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'
14+
1015
# All Vagrant configuration is done below. The "2" in Vagrant.configure
1116
# configures the configuration version (we support older styles for
1217
# backwards compatibility). Please don't change it unless you know what
@@ -15,30 +20,45 @@ Vagrant.configure(2) do |config|
1520
config.vm.box = "ubuntu/trusty64"
1621

1722
config.vm.provider "virtualbox" do |vb|
18-
vb.memory = 2048
23+
vb.memory = 3072 # Around 3Gb is necessary to be able to run tests
1924
end
20-
config.vm.network :private_network, ip: '192.168.10.11'
21-
config.vm.hostname = "magento2.vagrant"
2225

2326
config.vm.synced_folder '.', '/vagrant'
2427
if OS.is_windows
25-
config.vm.synced_folder '../magento2ce/var/generation', '/var/www/magento2ce/var/generation'
26-
config.vm.synced_folder '../magento2ce/app/etc', '/var/www/magento2ce/app/etc'
28+
guest_magento_dir = '/var/www/magento2ce'
29+
config.vm.synced_folder host_magento_dir + '/var/generation', guest_magento_dir + '/var/generation'
30+
config.vm.synced_folder host_magento_dir + '/app/etc', guest_magento_dir + '/app/etc'
2731
else
28-
config.vm.synced_folder '../magento2ce', '/var/www/magento2ce', type: "nfs"
32+
guest_magento_dir = host_magento_dir
33+
config.vm.synced_folder host_magento_dir, guest_magento_dir, type: "nfs"
2934
end
3035

36+
shell_script_args = [
37+
OS.is_windows ? "1" : "0",
38+
guest_magento_dir,
39+
magento_host_name
40+
]
3141
config.vm.provision "install_environment", type: "shell" do |s|
3242
s.path = "install_environment.sh"
33-
s.args = [OS.is_windows ? "1" : "0"]
43+
s.args = shell_script_args
3444
end
3545

3646
if OS.is_windows
37-
config.vm.provision "deploy_magento_code", type: "file", source: '../magento2ce', destination: '/var/www'
47+
config.vm.provision "deploy_magento_code", type: "file", source: host_magento_dir, destination: '/var/www'
3848
end
3949

4050
config.vm.provision "install_magento", type: "shell" do |s|
4151
s.path = "install_magento.sh"
42-
s.args = [OS.is_windows ? "1" : "0"]
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
4363
end
4464
end

bin/magento_clear_cache

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@
22

33
echo "Clearing Magento cache..."
44

5-
magento_path=/var/www/magento2ce
6-
7-
rm -f ${magento_path}/app/etc/paths.php
5+
rm -f ${MAGENTO_ROOT}/app/etc/paths.php
86
#clear var
9-
for dir in `ls ${magento_path}/var` ; do
10-
rm -rf ${magento_path}/var/${dir}/* ;
7+
for dir in `ls ${MAGENTO_ROOT}/var` ; do
8+
rm -rf ${MAGENTO_ROOT}/var/${dir}/* ;
119
done
1210
#clear pub/statics
13-
cd ${magento_path}/pub && mv static/.htaccess static_htaccess.back && rm -rf static/* && mv static_htaccess.back static/.htaccess
11+
cd ${MAGENTO_ROOT}/pub && mv static/.htaccess static_htaccess.back && rm -rf static/* && mv static_htaccess.back static/.htaccess
1412
#clear integration tests tmp
15-
cd ${magento_path}/dev/tests/integration && mv tmp/.gitignore tmp_gitignore.back && rm -rf tmp/* && mv tmp_gitignore.back tmp/.gitignore
13+
cd ${MAGENTO_ROOT}/dev/tests/integration && mv tmp/.gitignore tmp_gitignore.back && rm -rf tmp/* && mv tmp_gitignore.back tmp/.gitignore
1614
#clear unit tests tmp
17-
cd ${magento_path}/dev/tests/unit && rm -rf tmp/*
15+
cd ${MAGENTO_ROOT}/dev/tests/unit && rm -rf tmp/*
1816

1917
echo "Magento cache cleared."

install_environment.sh

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,23 @@
44
set -ex
55

66
is_windows_host=$1
7+
guest_magento_dir=$2
8+
magento_host_name=$3
79

810
apt-get update
911

10-
# Determine external IP address
11-
set +x
12-
IP=`ifconfig eth1 | grep inet | awk '{print $2}' | sed 's/addr://'`
13-
echo "IP address is '${IP}'"
14-
set -x
15-
16-
# Determine hostname for Magento web-site
17-
HOST=`hostname -f`
18-
if [ -z ${HOST} ]; then
19-
# Use external IP address as hostname
20-
set +x
21-
HOST=${IP}
22-
echo "Use IP address '${HOST}' as hostname"
23-
set -x
24-
fi
25-
2612
# Setup Apache
2713
apt-get install -y apache2
2814
a2enmod rewrite
2915

3016
# Make suer Apache is run from 'vagrant' user to avoid permission issues
31-
sed -i 's/www-data/vagrant/g' /etc/apache2/envvars
17+
sed -i 's|www-data|vagrant|g' /etc/apache2/envvars
3218

3319
# Enable Magento virtual host
3420
apache_config="/etc/apache2/sites-available/magento2.conf"
3521
cp /vagrant/magento2.vhost.conf ${apache_config}
36-
sed -i "s/<host>/${HOST}/g" ${apache_config}
22+
sed -i "s|<host>|${magento_host_name}|g" ${apache_config}
23+
sed -i "s|<guest_magento_dir>|${guest_magento_dir}|g" ${apache_config}
3724
a2ensite magento2.conf
3825

3926
# Disable default virtual host
@@ -68,19 +55,40 @@ sed -i '/\[client\]/a \
6855
user = root \
6956
password =' /etc/mysql/my.cnf
7057

58+
# Install git
59+
apt-get install -y git
60+
7161
# Setup Composer
7262
if [ ! -f /usr/local/bin/composer ]; then
7363
cd /tmp
7464
curl -sS https://getcomposer.org/installer | php
7565
mv composer.phar /usr/local/bin/composer
7666
fi
7767

68+
# Configure composer
69+
composer_auth_json="/vagrant/local.config/composer/auth.json"
70+
if [ -f ${composer_auth_json} ]; then
71+
set +x
72+
echo "Installing composer OAuth tokens from ${composer_auth_json}..."
73+
set -x
74+
if [ ! -d /home/vagrant/.composer ] ; then
75+
sudo -H -u vagrant bash -c 'mkdir /home/vagrant/.composer'
76+
fi
77+
cp ${composer_auth_json} /home/vagrant/.composer/auth.json
78+
fi
79+
7880
# Declare path to scripts supplied with vagrant and Magento
79-
magento_dir="/var/www/magento2ce"
80-
echo "export PATH=\$PATH:/vagrant/bin:${magento_dir}/bin" >> /etc/profile
81+
echo "export PATH=\$PATH:/vagrant/bin:${guest_magento_dir}/bin" >> /etc/profile
82+
echo "export MAGENTO_ROOT=${guest_magento_dir}" >> /etc/profile
8183

8284
# Set permissions to allow Magento codebase upload by Vagrant provision script
8385
if [ ${is_windows_host} -eq 1 ]; then
8486
chown -R vagrant:vagrant /var/www
8587
chmod -R 755 /var/www
8688
fi
89+
90+
# Install RabbitMQ (is used by Enterprise edition)
91+
apt-get install -y rabbitmq-server
92+
rabbitmq-plugins enable rabbitmq_management
93+
invoke-rc.d rabbitmq-server stop
94+
invoke-rc.d rabbitmq-server start

install_magento.sh

Lines changed: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,17 @@
66
set -ex
77

88
is_windows_host=$1
9+
guest_magento_dir=$2
10+
magento_host_name=$3
911

10-
# Determine external IP address
11-
set +x
12-
IP=`ifconfig eth1 | grep inet | awk '{print $2}' | sed 's/addr://'`
13-
echo "IP address is '${IP}'"
14-
set -x
15-
16-
# Determine hostname for Magento web-site
17-
HOST=`hostname -f`
18-
if [ -z ${HOST} ]; then
19-
# Use external IP address as hostname
20-
set +x
21-
HOST=${IP}
22-
echo "Use IP address '${HOST}' as hostname"
23-
set -x
24-
fi
25-
26-
magento_dir="/var/www/magento2ce"
27-
cd ${magento_dir}
12+
cd ${guest_magento_dir}
2813

2914
# Clear cache
3015
magento_clear_cache
3116

3217
# Remove configuration files
33-
rm -f "${magento_dir}/app/etc/config.php"
34-
rm -f "${magento_dir}/app/etc/env.php"
18+
rm -f "${guest_magento_dir}/app/etc/config.php"
19+
rm -f "${guest_magento_dir}/app/etc/env.php"
3520

3621
# Create DB
3722
db_names=("magento" "magento_integration_tests")
@@ -40,25 +25,15 @@ for db_name in "${db_names[@]}"; do
4025
done
4126

4227
# Install Magento application
43-
cd ${magento_dir}
44-
github_token="/vagrant/local.config/github.oauth.token"
45-
if [ -f ${github_token} ]; then
46-
set +x
47-
echo "Installing GitHub OAuth token from ${github_token}..."
48-
composer config -g github-oauth.github.com `cat ${github_token}`
49-
set -x
50-
composer install
51-
else
52-
composer install --prefer-source
53-
fi
28+
cd ${guest_magento_dir}
5429

5530
admin_frontame="admin"
5631
install_cmd="./bin/magento setup:install \
5732
--db-host=localhost \
5833
--db-name=magento \
5934
--db-user=root \
6035
--backend-frontname=${admin_frontame} \
61-
--base-url=http://${HOST}/ \
36+
--base-url=http://${magento_host_name}/ \
6237
--language=en_US \
6338
--timezone=America/Chicago \
6439
--currency=USD \
@@ -69,23 +44,31 @@ install_cmd="./bin/magento setup:install \
6944
--admin-password=123123q \
7045
--cleanup-database \
7146
--use-rewrites=1"
47+
48+
# Configure Rabbit MQ
49+
if [ -f "${guest_magento_dir}/app/code/Magento/Amqp/registration.php" ]; then
50+
install_cmd="${install_cmd} \
51+
--amqp-host=localhost \
52+
--amqp-port=5672 \
53+
--amqp-user=guest \
54+
--amqp-password=guest"
55+
fi
56+
7257
chmod +x bin/magento
7358
php ${install_cmd}
7459

7560
# Enable Magento cron jobs
76-
echo "* * * * * php ${magento_dir}/bin/magento cron:run &" | crontab -u vagrant -
61+
echo "* * * * * php ${guest_magento_dir}/bin/magento cron:run &" | crontab -u vagrant -
7762

7863
if [ ${is_windows_host} -eq 1 ]; then
79-
chown -R vagrant:vagrant ${magento_dir}
64+
chown -R vagrant:vagrant ${guest_magento_dir}
8065
fi
8166

8267
set +x
8368
echo "
84-
Magento application was deployed in ${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}'"
69+
Magento application was deployed to ${guest_magento_dir} and installed successfully
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 "
@@ -94,5 +77,5 @@ if [ ${is_windows_host} -eq 1 ]; then
9477
(this directory should already contain Magento repository cloned earlier)
9578
9679
2. Use instructions provided here https://github.com/paliarush/vagrant-magento/blob/master/docs/phpstorm-configuration-windows-hosts.md
97-
to set up synchronization in PhpStorm (or using rsync) with ${magento_dir} directory"
80+
to set up synchronization in PhpStorm (or using rsync) with ${guest_magento_dir} directory"
9881
fi

local.config/.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
/*
2-
!/.gitignore
2+
!/.gitignore
3+
!/composer
4+
/composer/*
5+
!/composer/auth.json.dist

0 commit comments

Comments
 (0)