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

Commit 59a2836

Browse files
author
Alexander Paliarush
committed
- Added support of EE linked to CE using symlinks on *nix hosts
- Added ${MAGENTO_ROOT} environment variable, which stores installation path on the guest
1 parent d74d70c commit 59a2836

6 files changed

+61
-51
lines changed

README.md

+4-5
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ Web access:
6767
- Magento admin user/password: `admin/123123q`
6868
6969
Codebase and DB access:
70-
- Path to your Magento installation on the VM: `/var/www/magento2ce`
70+
- Path to your Magento installation on the VM:
71+
- Can be retrieved from environment variable: `echo ${MAGENTO_ROOT}`
72+
- On Windows hosts: `/var/www/magento2ce`
73+
- On Mac, \*nix hosts: the same as on host
7174
- MySQL DB host: `localhost` (not accessible remotely)
7275
- MySQL DB name: `magento`, `magento_integration_tests`
7376
- MySQL DB user/password: just use `mysql` with no user and password (`root/password` will be used by default)
@@ -112,7 +115,3 @@ XDebug is already configured to connect to the host machine automatically. So ju
112115
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
113116
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)
114117
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

+17-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ module OS
77
end
88
end
99

10+
require 'pathname.rb'
11+
host_magento_dir = Pathname.new(Dir.pwd + '/../magento2ce').realpath.to_s
12+
1013
# All Vagrant configuration is done below. The "2" in Vagrant.configure
1114
# configures the configuration version (we support older styles for
1215
# backwards compatibility). Please don't change it unless you know what
@@ -22,23 +25,31 @@ Vagrant.configure(2) do |config|
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

3136
config.vm.provision "install_environment", type: "shell" do |s|
3237
s.path = "install_environment.sh"
33-
s.args = [OS.is_windows ? "1" : "0"]
38+
s.args = [
39+
OS.is_windows ? "1" : "0",
40+
guest_magento_dir
41+
]
3442
end
3543

3644
if OS.is_windows
37-
config.vm.provision "deploy_magento_code", type: "file", source: '../magento2ce', destination: '/var/www'
45+
config.vm.provision "deploy_magento_code", type: "file", source: host_magento_dir, destination: '/var/www'
3846
end
3947

4048
config.vm.provision "install_magento", type: "shell" do |s|
4149
s.path = "install_magento.sh"
42-
s.args = [OS.is_windows ? "1" : "0"]
50+
s.args = [
51+
OS.is_windows ? "1" : "0",
52+
guest_magento_dir
53+
]
4354
end
4455
end

bin/magento_clear_cache

+6-8
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

+12-10
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,23 @@
44
set -ex
55

66
is_windows_host=$1
7+
guest_magento_dir=$2
78

89
apt-get update
910

1011
# Determine external IP address
1112
set +x
12-
IP=`ifconfig eth1 | grep inet | awk '{print $2}' | sed 's/addr://'`
13-
echo "IP address is '${IP}'"
13+
ip=`ifconfig eth1 | grep inet | awk '{print $2}' | sed 's/addr://'`
14+
echo "IP address is '${ip}'"
1415
set -x
1516

1617
# Determine hostname for Magento web-site
17-
HOST=`hostname -f`
18-
if [ -z ${HOST} ]; then
18+
host=`hostname -f`
19+
if [ -z ${host} ]; then
1920
# Use external IP address as hostname
2021
set +x
21-
HOST=${IP}
22-
echo "Use IP address '${HOST}' as hostname"
22+
host=${ip}
23+
echo "Use IP address '${host}' as hostname"
2324
set -x
2425
fi
2526

@@ -28,12 +29,13 @@ apt-get install -y apache2
2829
a2enmod rewrite
2930

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

3334
# Enable Magento virtual host
3435
apache_config="/etc/apache2/sites-available/magento2.conf"
3536
cp /vagrant/magento2.vhost.conf ${apache_config}
36-
sed -i "s/<host>/${HOST}/g" ${apache_config}
37+
sed -i "s|<host>|${host}|g" ${apache_config}
38+
sed -i "s|<guest_magento_dir>|${guest_magento_dir}|g" ${apache_config}
3739
a2ensite magento2.conf
3840

3941
# Disable default virtual host
@@ -91,8 +93,8 @@ if [ -f ${composer_auth_json} ]; then
9193
fi
9294

9395
# Declare path to scripts supplied with vagrant and Magento
94-
magento_dir="/var/www/magento2ce"
95-
echo "export PATH=\$PATH:/vagrant/bin:${magento_dir}/bin" >> /etc/profile
96+
echo "export PATH=\$PATH:/vagrant/bin:${guest_magento_dir}/bin" >> /etc/profile
97+
echo "export MAGENTO_ROOT=${guest_magento_dir}" >> /etc/profile
9698

9799
# Set permissions to allow Magento codebase upload by Vagrant provision script
98100
if [ ${is_windows_host} -eq 1 ]; then

install_magento.sh

+20-20
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,32 @@
66
set -ex
77

88
is_windows_host=$1
9+
guest_magento_dir=$2
910

1011
# Determine external IP address
1112
set +x
12-
IP=`ifconfig eth1 | grep inet | awk '{print $2}' | sed 's/addr://'`
13-
echo "IP address is '${IP}'"
13+
ip=`ifconfig eth1 | grep inet | awk '{print $2}' | sed 's/addr://'`
14+
echo "IP address is '${ip}'"
1415
set -x
1516

1617
# Determine hostname for Magento web-site
17-
HOST=`hostname -f`
18-
if [ -z ${HOST} ]; then
18+
host=`hostname -f`
19+
if [ -z ${host} ]; then
1920
# Use external IP address as hostname
2021
set +x
21-
HOST=${IP}
22-
echo "Use IP address '${HOST}' as hostname"
22+
host=${ip}
23+
echo "Use IP address '${host}' as hostname"
2324
set -x
2425
fi
2526

26-
magento_dir="/var/www/magento2ce"
27-
cd ${magento_dir}
27+
cd ${guest_magento_dir}
2828

2929
# Clear cache
3030
magento_clear_cache
3131

3232
# Remove configuration files
33-
rm -f "${magento_dir}/app/etc/config.php"
34-
rm -f "${magento_dir}/app/etc/env.php"
33+
rm -f "${guest_magento_dir}/app/etc/config.php"
34+
rm -f "${guest_magento_dir}/app/etc/env.php"
3535

3636
# Create DB
3737
db_names=("magento" "magento_integration_tests")
@@ -40,15 +40,15 @@ for db_name in "${db_names[@]}"; do
4040
done
4141

4242
# Install Magento application
43-
cd ${magento_dir}
43+
cd ${guest_magento_dir}
4444

4545
admin_frontame="admin"
4646
install_cmd="./bin/magento setup:install \
4747
--db-host=localhost \
4848
--db-name=magento \
4949
--db-user=root \
5050
--backend-frontname=${admin_frontame} \
51-
--base-url=http://${HOST}/ \
51+
--base-url=http://${host}/ \
5252
--language=en_US \
5353
--timezone=America/Chicago \
5454
--currency=USD \
@@ -61,7 +61,7 @@ install_cmd="./bin/magento setup:install \
6161
--use-rewrites=1"
6262

6363
# Configure Rabbit MQ
64-
if [ -f "${magento_dir}/app/code/Magento/Amqp/registration.php" ]; then
64+
if [ -f "${guest_magento_dir}/app/code/Magento/Amqp/registration.php" ]; then
6565
install_cmd="${install_cmd} \
6666
--amqp-host=localhost \
6767
--amqp-port=5672 \
@@ -73,19 +73,19 @@ chmod +x bin/magento
7373
php ${install_cmd}
7474

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

7878
if [ ${is_windows_host} -eq 1 ]; then
79-
chown -R vagrant:vagrant ${magento_dir}
79+
chown -R vagrant:vagrant ${guest_magento_dir}
8080
fi
8181

8282
set +x
8383
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}/
84+
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}/
8787
88-
Don't forget to update your 'hosts' file with '${IP} ${HOST}'"
88+
Don't forget to update your 'hosts' file with '${ip} ${host}'"
8989

9090
if [ ${is_windows_host} -eq 1 ]; then
9191
echo "
@@ -94,5 +94,5 @@ if [ ${is_windows_host} -eq 1 ]; then
9494
(this directory should already contain Magento repository cloned earlier)
9595
9696
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"
97+
to set up synchronization in PhpStorm (or using rsync) with ${guest_magento_dir} directory"
9898
fi

magento2.vhost.conf

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<VirtualHost *:80>
2-
DocumentRoot "/var/www/magento2ce"
2+
DocumentRoot <guest_magento_dir>
33
ServerName magento2.vagrant
4-
<Directory /var/www/magento2ce>
4+
<Directory <guest_magento_dir>>
55
Options Indexes FollowSymLinks
66
AllowOverride All
77
Require all granted

0 commit comments

Comments
 (0)