Skip to content

Commit dc99015

Browse files
committed
Merge pull request #32 from paliarush/Guest-Configs
Access to Guest configs from host IDE
2 parents fd777b9 + 2ebe066 commit dc99015

16 files changed

+209
-57
lines changed

CHANGELOG.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,19 @@ This project adheres to [Semantic Versioning](http://semver.org/).
1212
### Changed
1313

1414
- Removed requirement for public github token due to Composer limitations (issue is fixed on Composer side)
15+
- Changed requirement for minimum box version from 1.0 to 1.1
1516

1617
### Fixed
1718

1819
- Fixed permissions during Magento installation on Windows hosts
20+
- Fixed issue with Magento compiler on Windows hosts
21+
- Fixed "stdin: is not a tty" warning
1922

2023
### Added
2124

2225
- Added host wrapper script for bin/magento command on guest
26+
- Added ability to modify guest config files (PHP, Apache etc) directly from host IDE
27+
- Added ability to choose if PhpStorm configs should be removed during project reinitialization
2328

2429
## [v2.0.0] - 2016-02-05
2530

@@ -49,18 +54,18 @@ This project adheres to [Semantic Versioning](http://semver.org/).
4954

5055
### Added
5156

52-
- Integrated vagrant host manager plugin to allow automatic /etc/hosts update
53-
- Added support of EE linked to CE using symlinks on *nix hosts
57+
- Integrated vagrant host manager plugin to allow automatic /etc/hosts update
58+
- Added support of EE linked to CE using symlinks on *nix hosts
5459
- Added ${MAGENTO_ROOT} environment variable, which stores installation path on the guest
5560
- Added support of Rabbit MQ
56-
- Added possibility to specify tokens for repo.magento.com composer repository
61+
- Added possibility to specify tokens for repo.magento.com composer repository
5762
- git is now installed on guest machine
58-
- Removed 'magento' MySQL user, password of 'root' user removed
59-
- Database for integration tests are created by default
60-
- Added script for clearing Magento cache from host command line
63+
- Removed 'magento' MySQL user, password of 'root' user removed
64+
- Database for integration tests are created by default
65+
- Added script for clearing Magento cache from host command line
6166
- Configured XDebug to allow remote debugging
62-
- Fixed max_nesting_level issue with XDebug enabled
67+
- Fixed max_nesting_level issue with XDebug enabled
6368
- Apache is run by 'vagrant' user
64-
- Enabled Magento cron jobs
69+
- Enabled Magento cron jobs
6570
- Enabled XDebug by default
6671
- Created vagrant configuration for Magneto 2 CE developer's environment installation

README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
* [Use Magento CLI (bin/magento)](#use-magento-cli-binmagento)
2020
* [Debugging with XDebug](#debugging-with-xdebug)
2121
* [Connecting to MySQL DB](#connecting-to-mysql-db)
22+
* [Accessing PHP and other config files](#accessing-php-and-other-config-files)
2223
* [Multiple Magento instances](#multiple-magento-instances)
2324
* [Reset environment](#reset-environment)
2425

@@ -210,14 +211,21 @@ To debug Magento Setup script, go to [Magento installation script](scripts/guest
210211

211212
Answer can be found [here](https://github.com/paliarush/magento2-vagrant-for-developers/issues/8)
212213

214+
### Accessing PHP and other config files
215+
216+
It is possible to view/modify majority of guest machine config files directly from IDE on the host. They will be accessible in [etc/guest](etc/guest) directory only when guest machine is running. The list of accessible configs includes: PHP, Apache, Mysql, Varnish, RabbitMQ.
217+
Do not edit any symlinks using PhpStorm because it may break your installation.
218+
219+
After editing configs in IDE it is still required to restart related services manually.
220+
213221
### Multiple Magento instances
214-
222+
215223
To install several Magento instances based on different code bases, just follow [Installation steps](#installation-steps) to initialize project in another directory on the host.
216224
Unique IP address, SSH port and domain name will be generated for each new instance if not specified manually in `etc/config.yaml`
217225

218226
### Reset environment
219227

220-
It is possible to reset project environment to default state, which you usually get just after project initialization. The following command will delete vagrant box, vagrant project settings and PhpStorm project settings. After that it will initialize project from scratch. Magento 2 code base (`magento2ce` directory) will stay untouched.
228+
It is possible to reset project environment to default state, which you usually get just after project initialization. The following command will delete vagrant box, vagrant project settings and PhpStorm project settings. After that it will initialize project from scratch. Magento 2 code base (`magento2ce` directory) and [etc/config.yaml](etc/config.yaml.dist) will stay untouched, but guest config files (located in [etc/guest](etc/guest)) will be removed.
221229

222230
Go to 'vagrant-magento' created earlier and run in command line:
223231

@@ -232,3 +240,11 @@ Go to 'vagrant-magento' created earlier and run in command line:
232240
```
233241
bash init_project.sh -fc
234242
```
243+
244+
To reset PhpStorm project configuration, in addition to `-f` specify `-p` option:
245+
246+
```
247+
bash init_project.sh -fp
248+
OR
249+
bash init_project.sh -fcp
250+
```

Vagrantfile

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,28 @@ guest_memory = config_data['guest']['memory']
3434
# NFS will be used for *nix and OSX hosts, if not disabled explicitly in config
3535
use_nfs_for_synced_folders = !OS.is_windows && (config_data['guest']['use_nfs'] == 1)
3636

37-
host_magento_dir = Dir.pwd + '/magento2ce'
37+
host_vagrant_dir = Dir.pwd + ''
38+
host_magento_dir = host_vagrant_dir + '/magento2ce'
3839

3940
VAGRANT_API_VERSION = 2
4041
Vagrant.configure(VAGRANT_API_VERSION) do |config|
4142
config.vm.box = "paliarush/magento2.ubuntu"
42-
config.vm.box_version = "~> 1.0"
43+
config.vm.box_version = "~> 1.1"
4344

4445
config.vm.provider "virtualbox" do |vb|
4546
vb.memory = guest_memory
4647
end
4748

4849
config.vm.synced_folder '.', '/vagrant', disabled: true
49-
config.vm.synced_folder './etc', '/vagrant/etc'
50+
config.vm.synced_folder './etc', '/vagrant/etc', mount_options: ["dmode=775,fmode=664"]
5051
config.vm.synced_folder './scripts', '/vagrant/scripts'
5152
config.vm.synced_folder './.idea', '/vagrant/.idea', create: true
5253
if use_nfs_for_synced_folders
5354
guest_magento_dir = host_magento_dir
5455
config.vm.synced_folder host_magento_dir, guest_magento_dir, type: "nfs", create: true
5556
else
5657
guest_magento_dir = '/var/www/magento2ce'
57-
config.vm.synced_folder host_magento_dir + '/var/generation', guest_magento_dir + '/var/generation', create: true
58+
config.vm.synced_folder host_magento_dir + '/var', guest_magento_dir + '/var', create: true
5859
config.vm.synced_folder host_magento_dir + '/app/etc', guest_magento_dir + '/app/etc', create: true
5960
end
6061

@@ -64,16 +65,27 @@ Vagrant.configure(VAGRANT_API_VERSION) do |config|
6465
magento_host_name, #3
6566
config_data['environment']['use_php7'], #4
6667
host_magento_dir, #5
67-
OS.is_windows ? "1" : "0" #6
68+
OS.is_windows ? "1" : "0", #6
69+
host_vagrant_dir #7
6870
]
6971

72+
config.vm.provision "fix_no_tty", type: "shell", run: "always" do |s|
73+
s.privileged = false
74+
s.inline = "sudo sed -i '/tty/!s/mesg n/tty -s \\&\\& mesg n/' /root/.profile"
75+
end
76+
7077
config.vm.provision "configure_environment", type: "shell" do |s|
7178
s.path = "scripts/provision/configure_environment.sh"
7279
s.args = shell_script_args
7380
end
7481

75-
config.vm.provision "export_env_variables", type: "shell", run: "always" do |s|
76-
s.path = "scripts/provision/export_env_variables.sh"
82+
config.vm.provision "configure_environment_recurring", type: "shell", run: "always" do |s|
83+
s.path = "scripts/provision/configure_environment_recurring.sh"
84+
s.args = shell_script_args
85+
end
86+
87+
config.vm.provision "export_env_variables_recurring", type: "shell", run: "always" do |s|
88+
s.path = "scripts/provision/export_env_variables_recurring.sh"
7789
s.args = shell_script_args
7890
end
7991

docs/phpstorm-configuration-windows-hosts.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This solution is applicable to any Vagrant configuration for Magento instance, s
77

88
```
99
Vagrant.configure(2) do |config|
10-
config.vm.synced_folder '../magento2ce/var/generation', '/var/www/magento2ce/var/generation'
10+
config.vm.synced_folder '../magento2ce/var', '/var/www/magento2ce/var'
1111
config.vm.synced_folder '../magento2ce/app/etc', '/var/www/magento2ce/app/etc'
1212
end
1313
```

etc/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
!/composer/auth.json.dist
66
!/config.yaml.dist
77
!/magento2_virtual_host.conf.dist
8+
!/guest

etc/guest/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/*

init_project.sh

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,21 @@ rm -f "${config_path}.back"
3737
# Clean up the project before initialization if "-f" option was specified. Remove codebase if "-fc" is used.
3838
force_project_cleaning=0
3939
force_codebase_cleaning=0
40-
while getopts 'fc' flag; do
40+
force_phpstorm_config_cleaning=0
41+
while getopts 'fcp' flag; do
4142
case "${flag}" in
4243
f) force_project_cleaning=1 ;;
4344
c) force_codebase_cleaning=1 ;;
45+
p) force_phpstorm_config_cleaning=1 ;;
4446
*) error "Unexpected option ${flag}" ;;
4547
esac
4648
done
4749
if [ ${force_project_cleaning} -eq 1 ]; then
4850
vagrant destroy -f
49-
rm -rf ${vagrant_dir}/.idea ${vagrant_dir}/.vagrant
51+
mv ${vagrant_dir}/etc/guest/.gitignore ${vagrant_dir}/etc/.gitignore.back
52+
rm -rf ${vagrant_dir}/.vagrant ${vagrant_dir}/etc/guest
53+
mkdir ${vagrant_dir}/etc/guest
54+
mv ${vagrant_dir}/etc/.gitignore.back ${vagrant_dir}/etc/guest/.gitignore
5055
if [ ${force_codebase_cleaning} -eq 1 ]; then
5156
rm -rf ${magento_ce_dir}
5257
fi
@@ -77,4 +82,26 @@ bash "${vagrant_dir}/scripts/host/composer.sh" install
7782
cd ${vagrant_dir}
7883
vagrant up
7984

80-
bash "${vagrant_dir}/scripts/host/configure_php_storm.sh"
85+
set +x
86+
echo "Configuring PhpStorm..."
87+
if [ ${force_project_cleaning} -eq 1 ] && [ ${force_phpstorm_config_cleaning} -eq 1 ]; then
88+
rm -rf ${vagrant_dir}/.idea
89+
fi
90+
if [ ! "$(ls -A ${vagrant_dir}/.idea)" ]; then
91+
bash "${vagrant_dir}/scripts/host/configure_php_storm.sh"
92+
fi
93+
94+
bold=$(tput bold)
95+
regular=$(tput sgr0)
96+
echo "
97+
${bold}[Important]${regular}
98+
Please use ${bold}${vagrant_dir}${regular} directory as PhpStorm project root, NOT ${bold}${magento_ce_dir}${regular}."
99+
100+
use_nfs=$(bash "${vagrant_dir}/scripts/get_config_value.sh" "guest_use_nfs")
101+
if [[ ${host_os} == "Windows" || ${use_nfs} == 0 ]]; then
102+
echo "
103+
${bold}[Optional]${regular}
104+
To verify that deployment configuration for ${bold}${magento_ce_dir}${regular} in PhpStorm is correct,
105+
use instructions provided here: ${bold}https://github.com/paliarush/magento2-vagrant-for-developers/blob/2.0/docs/phpstorm-configuration-windows-hosts.md${regular}.
106+
If not using PhpStorm, you can set up synchronization using rsync"
107+
fi

scripts/guest/link_configs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env bash
2+
3+
function process_configs () {
4+
configs_path=$1
5+
configs=$2
6+
for config in "${configs[@]}"
7+
do
8+
if [ ! -d /vagrant/etc/guest/${config} ] && [ ! -f /vagrant/etc/guest/${config} ]; then
9+
if [ -d ${configs_path}/${config} ] || [ -f ${configs_path}/${config} ]; then
10+
sudo rm -rf "${configs_path}/${config}.back"
11+
sudo cp -rp ${configs_path}/${config} "${configs_path}/${config}.back"
12+
sudo mv ${configs_path}/${config} /vagrant/etc/guest/${config}
13+
sudo ln -s /vagrant/etc/guest/${config} ${configs_path}/${config}
14+
fi
15+
fi
16+
done
17+
}
18+
19+
# Enable trace printing and exit on the first error
20+
set -ex
21+
22+
# Below configuration is required to allow managing mysql as a service
23+
if ! cat /etc/apparmor.d/local/usr.sbin.mysqld | grep -q '/vagrant/etc/guest' ; then
24+
echo "
25+
/vagrant/etc/guest/mysql/*.pem r,
26+
/vagrant/etc/guest/mysql/conf.d/ r,
27+
/vagrant/etc/guest/mysql/conf.d/* r,
28+
/vagrant/etc/guest/mysql/*.cnf r," >> /etc/apparmor.d/local/usr.sbin.mysqld
29+
fi
30+
31+
# Make guest configs visible and editable in the host IDE
32+
33+
# Configs located under /etc/*
34+
config_dir="/etc"
35+
# See unlink_configs script
36+
configs=( apache2 php mysql varnish rabbitmq )
37+
process_configs ${config_dir} ${configs}

scripts/guest/m-clear-cache

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ echo "Clearing Magento cache..."
44

55
rm -f ${MAGENTO_ROOT}/app/etc/paths.php
66
#clear var
7-
for dir in `ls ${MAGENTO_ROOT}/var` ; do
8-
rm -rf ${MAGENTO_ROOT}/var/${dir}/* ;
9-
done
7+
cd ${MAGENTO_ROOT} && mv var/.htaccess var_htaccess.back && rm -rf var/* var/.[^.]* && mv var_htaccess.back var/.htaccess
108
#clear pub/statics
11-
cd ${MAGENTO_ROOT}/pub && mv static/.htaccess static_htaccess.back && rm -rf static/* && mv static_htaccess.back static/.htaccess
9+
cd ${MAGENTO_ROOT}/pub && mv static/.htaccess static_htaccess.back && rm -rf static && mkdir static && mv static_htaccess.back static/.htaccess
1210
#clear integration tests tmp
13-
cd ${MAGENTO_ROOT}/dev/tests/integration && mv tmp/.gitignore tmp_gitignore.back && rm -rf tmp/* && mv tmp_gitignore.back tmp/.gitignore
11+
cd ${MAGENTO_ROOT}/dev/tests/integration && mv tmp/.gitignore tmp_gitignore.back && rm -rf tmp && mkdir tmp && mv tmp_gitignore.back tmp/.gitignore
1412
#clear unit tests tmp
15-
cd ${MAGENTO_ROOT}/dev/tests/unit && rm -rf tmp/*
13+
cd ${MAGENTO_ROOT}/dev/tests/unit && rm -rf tmp && mkdir tmp
1614

1715
echo "Magento cache cleared."

scripts/guest/m-reinstall

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ setupOptions[amqp_host]='localhost'
2525
setupOptions[amqp_port]='5672'
2626
setupOptions[amqp_user]='guest'
2727
setupOptions[amqp_password]='guest'
28+
setupOptions[amqp_virtualhost]='/'
2829

2930
cd ${MAGENTO_ROOT}
3031

@@ -62,11 +63,12 @@ install_cmd="./bin/magento setup:install \
6263
--use-rewrites=1"
6364

6465
# Configure Rabbit MQ
65-
if [ -f "${MAGENTO_ROOT}/app/code/Magento/Amqp/registration.php" ]; then
66+
if [ -f "${MAGENTO_ROOT}/app/etc/enterprise/di.xml" ] && [ -d "${MAGENTO_ROOT}/app/code/Magento/Amqp" ]; then
6667
install_cmd="${install_cmd} \
6768
--amqp-host=${setupOptions[amqp_host]} \
6869
--amqp-port=${setupOptions[amqp_port]} \
6970
--amqp-user=${setupOptions[amqp_user]} \
71+
--amqp-virtualhost=${setupOptions[amqp_virtualhost]} \
7072
--amqp-password=${setupOptions[amqp_password]}"
7173
fi
7274

@@ -91,15 +93,6 @@ sed -i "s|${MAGENTO_ROOT}|${MAGENTO_ROOT_HOST}|g" "/vagrant/.idea/misc.xml"
9193
set +x
9294
echo "
9395
Magento application was deployed to ${MAGENTO_ROOT} and installed successfully
96+
9497
Access storefront at ${setupOptions[base_url]}
9598
Access admin panel at ${setupOptions[base_url]}${setupOptions[admin_frontname]}/"
96-
97-
if [[ ${is_windows_host} == 1 || ${use_nfs} == 0 ]]; then
98-
echo "
99-
[Optional] To finish developer environment set up:
100-
1. Please create new PhpStorm project using 'magento2ce' directory on your host
101-
(this directory should already contain Magento repository cloned earlier)
102-
103-
2. Use instructions provided here https://github.com/paliarush/vagrant-magento/blob/2.0/docs/phpstorm-configuration-windows-hosts.md
104-
to set up synchronization in PhpStorm (or using rsync) with ${MAGENTO_ROOT} directory"
105-
fi

0 commit comments

Comments
 (0)