├── .editorconfig ├── .gitignore ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── Vagrantfile ├── docs ├── images │ ├── automatic-upload.png │ ├── deployment-configuration.png │ ├── exclude-paths-from-mapping.png │ ├── linux-icon.png │ ├── new-sftp-server.png │ ├── osx-icon.png │ ├── private-key-auth-type.png │ ├── projects-mapping.png │ ├── release_badge.png │ ├── release_badge.svg │ ├── ssh-config.png │ ├── tests_badge.png │ ├── tests_badge.svg │ ├── upload-magento-codebase.png │ └── windows-icon.png ├── known-issues.md ├── performance-issue-on-windows-hosts.md └── phpstorm-configuration-windows-hosts.md ├── etc ├── .gitignore ├── composer │ └── auth.json.dist ├── config.yaml.dist ├── guest │ └── .gitignore ├── magento2_default_varnish.vcl.dist └── magento2_virtual_host.conf.dist ├── init_project.sh ├── lib └── .gitignore ├── log └── email │ └── .gitignore ├── m-bin-magento ├── m-clear-cache ├── m-composer ├── m-reinstall ├── m-search-engine ├── m-switch-to-ce ├── m-switch-to-ee ├── m-varnish └── scripts ├── colors.sh ├── get_config_value.sh ├── guest ├── change_magento_config_for_functional_tests ├── check_mounted_directories ├── configure_cache_backend ├── configure_debugging ├── configure_search_engine ├── configure_varnish ├── generate_basic_data ├── link_configs ├── log_email ├── m-clear-cache ├── m-reinstall ├── m-search-engine ├── m-varnish ├── unlink_configs ├── update_magento_config └── warm_up_cache ├── host ├── .gitignore ├── check_mounted_directories.sh ├── check_requirements.sh ├── composer.sh ├── configure_php_storm.sh ├── configure_tests.sh ├── get_host_os.sh ├── get_path_to_php.sh ├── install_php.sh ├── m_clear_cache.sh ├── m_composer.sh ├── m_reinstall.sh ├── m_switch_to_ce.sh ├── m_switch_to_ee.sh ├── php-storm-configs │ ├── .name │ ├── deployment.xml │ ├── encodings.xml │ ├── host_name.iml │ ├── inspectionProfiles │ │ ├── Project_Default.xml │ │ └── profiles_settings.xml │ ├── modules.xml │ ├── php.xml │ ├── remote-mappings.xml │ ├── vcs.ce.xml │ ├── vcs.ee.xml │ ├── vcs.xml │ └── webServers.xml ├── relink_sample_data.sh └── warm_up_cache.sh ├── output_functions.sh └── provision ├── configure_environment.sh ├── configure_environment_recurring.sh ├── export_env_variables_recurring.sh └── upgrade_environment_recurring.sh /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: http://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | # Unix-style newlines with a newline ending every file 7 | [*] 8 | end_of_line = lf 9 | insert_final_newline = true 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.vagrant 2 | /.idea 3 | /log/*.log 4 | /scripts/.current_nesting_level 5 | /scripts/.current_log_path 6 | .DS_Store 7 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | This project adheres to [Semantic Versioning](http://semver.org/). 5 | 6 | * [\[Unreleased\]](#unreleased) 7 | * [\[v2.2.0\] - 2017-02-25](#v220---2017-02-25) 8 | * [\[v2.1.0\] - 2016-06-22](#v210---2016-06-22) 9 | * [\[v2.0.0\] - 2016-02-05](#v200---2016-02-05) 10 | * [\[v1.0.0\] - 2016-01-11](#v100---2016-01-11) 11 | 12 | ## [Unreleased] 13 | 14 | ### Changed 15 | 16 | - Verified compatibility with Vagrant 2.x and loosened Vagrant version requirement 17 | - Config option 'php_version' should now be used for PHP version selection instead of 'use_php7' 18 | - Upgraded Varnish to v4.1 19 | - Improved Magento re-installation speed by avoiding unnecessary cache cleaning 20 | - Custom code sniffer rules replaced with PSR2 21 | - MessageQueue module will now be installed with CE if using Magento v2.3+ 22 | 23 | ### Added 24 | 25 | - PHP 7.1 and PHP 7.2 support 26 | - Support for new location of `generated` directory in Magento 2.2.0 27 | - Basic data generation can be turned off. Added configurable product and customer address generation 28 | - Documentation in config.yaml.dist for choosing specific composer package versions 29 | 30 | ### Fixed 31 | 32 | - Magento 2.2.0 EE installation from composer 33 | 34 | ## [v2.2.0] - 2017-02-25 35 | 36 | ### Changed 37 | 38 | - Magento EE and sample data directories are added to 'Exclude list' in PhpStorm 39 | - Redis is used as default cache backend instead of filesystem 40 | - After EE is linked, EE versions of composer.lock and composer.json are replaced back with CE versions (thus are not marked by git as modified) 41 | - Improved CLI scripts output formatting 42 | 43 | ### Fixed 44 | 45 | - Issue with some files marked as unversioned in git after EE linking 46 | - It is now possible to use spaces in path to vagrant project on Windows. On OSX and Linux hosts it works in non-NFS mode, in NFS mode it does not work because of [bug in vagrant](mitchellh/vagrant#7540) 47 | - Issue with MySQL being down after VM power off 48 | 49 | ### Added 50 | 51 | - Added ability to configure number of CPUs for virtual machine via [etc/config.yaml](etc/config.yaml.dist) 52 | - Added generation of basic sample data for testing purposes 53 | - Ability to upgrade Magento using `m-switch-to-ce` and `m-switch-to-ee` (when `-u` flag is specified) 54 | - Redis support for Magento caching 55 | - Access to Magento developer mode and storefront/admin UI debugging features via [etc/config.yaml](etc/config.yaml.dist) 56 | - Composer-based installation support 57 | - Magento cache warming up after re-install and clearing cache (when `-w` flag is specified) 58 | - Tests configuration files are generated during project initialization 59 | - Sample data support 60 | - ElasticSearch support 61 | - NodeJS, NPM, Gulp and Grunt are installed as part of the provisioning process 62 | 63 | ## [v2.1.0] - 2016-06-22 64 | 65 | ### Changed 66 | 67 | - Removed requirement for public github token due to Composer limitations (issue is fixed on Composer side) 68 | - Changed requirement for minimum box version from 1.0 to 1.1 69 | - Upgraded PHP 5.5.9 to PHP 5.6 70 | - When [init_project.sh](init_project.sh) is executed, EE will be installed by default, if EE repository is specified in [etc/config.yaml](etc/config.yaml.dist). Not supported on Windows hosts 71 | 72 | ### Fixed 73 | 74 | - Permissions during Magento installation on Windows hosts 75 | - Issue with Magento compiler on Windows hosts 76 | - "stdin: is not a tty" warning 77 | 78 | ### Added 79 | 80 | - Setup and upgrade cron scripts to crontab 81 | - Logging of all emails in HTML format to `vagrant-magento/log/email` 82 | - Host wrapper script for bin/magento command on guest 83 | - Ability to modify guest config files (PHP, Apache etc) directly from host IDE 84 | - Ability to choose if PhpStorm configs should be removed during project reinitialization 85 | - Ability to switch PHP version without destroying the project ("vagrant reload" is required) 86 | - Ability to do force switch to CE or EE (even if already switched to target edition) 87 | - Ability to use Varnish full page caching automatically. (Using "vagrant reload" or m-varnish script) 88 | 89 | ## [v2.0.0] - 2016-02-05 90 | 91 | ### Changed 92 | 93 | - Moved provisioning scripts 94 | - Magento project directory moved to vagrant project root. Current structure is as follows: `vagrant-magento/magento2ce/magento2ee` 95 | - PHP 7.0 is installed by default instead of PHP 5.5.9 (can be configured in [etc/config.yaml](etc/config.yaml.dist)) 96 | - Renamed configuration folder from `local.config` to `etc` 97 | - Set minimum Vagrant version as 1.8 98 | - Improved deployment speed in case of disabled NFS for folders sync 99 | - Used custom Vagrant box with pre-installed software necessary for Magento 2 development 100 | - Eliminated explicit dependency on PHP for Windows hosts (it can be downloaded and used locally for the project) 101 | - XSD URN generation is executed after Magento installation 102 | 103 | ### Added 104 | 105 | - Added [project initialization script](init_project.sh) and host scripts for routine flows (compatible with OSX, *nix and Windows) 106 | - Implemented static value of forwarded SSH port to prevent necessity to reconfigure software accessing guest via SSH 107 | - Implemented collision prevention for IP address and host name (in case when several machines are created at once) 108 | - Configuration file [etc/config.yaml](etc/config.yaml.dist) 109 | - PHP 7.0 support 110 | - PHP Storm configuration during project initialization (particularly automatic deployment settings) 111 | - Automatic vagrant plugins installation 112 | 113 | ## [v1.0.0] - 2016-01-11 114 | 115 | ### Added 116 | 117 | - Integrated vagrant host manager plugin to allow automatic /etc/hosts update 118 | - Support of EE linked to CE using symlinks on *nix hosts 119 | - ${MAGENTO_ROOT} environment variable, which stores installation path on the guest 120 | - Support of Rabbit MQ 121 | - Possibility to specify tokens for repo.magento.com composer repository 122 | - git is now installed on guest machine 123 | - Removed 'magento' MySQL user, password of 'root' user removed 124 | - Database for integration tests are created by default 125 | - Added script for clearing Magento cache from host command line 126 | - Configured XDebug to allow remote debugging 127 | - Fixed max_nesting_level issue with XDebug enabled 128 | - Apache is run by 'vagrant' user 129 | - Enabled Magento cron jobs 130 | - Enabled XDebug by default 131 | - Created vagrant configuration for Magneto 2 CE developer's environment installation 132 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Everyone is welcome to contribute improvements and fixes to this project. There are no specific requirements, just create a pull request with proposed modifications and try to run [tests](https://github.com/paliarush/magento2-vagrant-for-developers-tests) on your local environment. -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Paliarush Alex 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Vagrant project for Magento 2 developers (optimized for Mac, Windows and \*nix hosts) 2 | 3 | :warning: Current project is not supported anymore. Please check out https://github.com/magento/magento2-kubernetes-devbox which is under development and may become an official devbox for Magento 2 in the future. 4 | 5 | [![Tests passing on OSX](docs/images/tests_badge.png)](https://github.com/paliarush/magento2-vagrant-for-developers-tests) 6 | [![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE) 7 | [![Semver](http://img.shields.io/SemVer/2.0.0.png?color=blue)](http://semver.org/spec/v2.0.0.html) 8 | [![Latest GitHub release](docs/images/release_badge.png)](https://github.com/paliarush/magento2-vagrant-for-developers/releases/latest) 9 | 10 | * [What You get](#what-you-get) 11 | * [How to install](#how-to-install) 12 | * [Requirements](#requirements) 13 | * [Installation steps](#installation-steps) 14 | * [Default credentials and settings](#default-credentials-and-settings) 15 | * [Getting updates and fixes](#getting-updates-and-fixes) 16 | * [Day-to-day development scenarios](#day-to-day-development-scenarios) 17 | * [Reinstall Magento](#reinstall-magento) 18 | * [Clear Magento cache](#clear-magento-cache) 19 | * [Switch between CE and EE](#switch-between-ce-and-ee) 20 | * [Sample data installation](#sample-data-installation) 21 | * [Basic data generation](#basic-data-generation) 22 | * [Use Magento CLI (bin/magento)](#use-magento-cli-binmagento) 23 | * [Debugging with XDebug](#debugging-with-xdebug) 24 | * [Connecting to MySQL DB](#connecting-to-mysql-db) 25 | * [View emails sent by Magento](#view-emails-sent-by-magento) 26 | * [Accessing PHP and other config files](#accessing-php-and-other-config-files) 27 | * [Upgrading Magento](#upgrading-magento) 28 | * [Multiple Magento instances](#multiple-magento-instances) 29 | * [Update Composer dependencies](#update-composer-dependencies) 30 | * [Running Magento tests](#running-magento-tests) 31 | * [Environment configuration](#environment-configuration) 32 | * [Switch between PHP versions](#switch-between-php-versions) 33 | * [Activating Varnish](#activating-varnish) 34 | * [Activating ElasticSearch](#activating-elasticsearch) 35 | * [Redis for caching](#redis-for-caching) 36 | * [Reset environment](#reset-environment) 37 | * [Switch NodeJS Versions](#switch-nodejs-versions) 38 | * [FAQ](#faq) 39 | 40 | ## What You get 41 | 42 | It's expected that the Magento 2 project source code will be located and managed on the host to allow quick indexing of project files by IDE. All other infrastructure is deployed on the guest machine. 43 | 44 | Current Vagrant configuration aims to solve performance issues of Magento installed on Virtual Box **for development**. A custom solution is implemented for Windows hosts. See [explanation of the proposed solution](docs/performance-issue-on-windows-hosts.md). 45 | 46 | The environment for Magento EE development is also configured. 47 | 48 | It is easy to [install multiple Magento instances](#multiple-magento-instances) based on different codebases simultaneously. 49 | 50 | The [project initialization script](init_project.sh) configures a complete development environment: 51 | 52 | 1. Adds some missing software on the host 53 | 1. Configures all software necessary for Magento 2 using a [custom Ubuntu vagrant box](https://atlas.hashicorp.com/paliarush/boxes/magento2.ubuntu) (Apache 2.4, PHP 7.0 or 5.6, MySQL 5.6, Git, Composer, XDebug, Rabbit MQ, Varnish) 54 | 1. Installs Magento 2 from Git repositories or Composer packages (can be configured via `checkout_source_from` option in [etc/config.yaml](etc/config.yaml.dist)) 55 | 1. Configures PHP Storm project (partially at the moment) 56 | 1. Installs NodeJS, NPM, Grunt and Gulp for front end development 57 | 58 | :information_source: This box uses the [n package manager](https://www.npmjs.com/package/n) to provide the latest NodeJS LTS version.
59 | 60 | ## How to install 61 | 62 | If you never used Vagrant before, read the [Vagrant Docs](https://docs.vagrantup.com/v2) first. 63 | 64 | ### Requirements 65 | 66 | The software listed below should be available in [PATH](https://en.wikipedia.org/wiki/PATH_\(variable\)) (except for PHP Storm). 67 | 68 | - [Vagrant 1.8+](https://www.vagrantup.com/downloads.html) 69 | - [VirtualBox](https://www.virtualbox.org/wiki/Downloads) 70 | - [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) - Ensure that SSH keys are generated and associated with your Github account. See [how to check](https://help.github.com/articles/testing-your-ssh-connection/) and [how to configure](https://help.github.com/articles/generating-ssh-keys/), if not configured.
71 | :information_source: To obtain the codebase without cloning, just use the Magento 2 codebase instead of `vagrant-magento/magento2ce`. Either method will produce a successful installation.
72 | 73 | :information_source: On Windows hosts ![](docs/images/windows-icon.png) Git must be [v2.7+](http://git-scm.com/download/win). Also make sure to set the following options to avoid issues with incorrect line separators: 74 | 75 | ``` 76 | git config --global core.autocrlf false 77 | git config --global core.eol LF 78 | git config --global diff.renamelimit 5000 79 | ``` 80 | - [PHP](http://php.net/manual/en/install.php) ![](docs/images/linux-icon.png)![](docs/images/osx-icon.png) (any version) to allow Magento dependency management with [Composer](https://getcomposer.org/doc/00-intro.md) 81 | - [PHP Storm](https://www.jetbrains.com/phpstorm), optional but recommended 82 | - [NFS server](https://en.wikipedia.org/wiki/Network_File_System) ![](docs/images/linux-icon.png)![](docs/images/osx-icon.png) must be installed and running on \*nix and OSX hosts; usually available, follow [installation steps](#how-to-install) first 83 | 84 | ### Installation steps 85 | 86 | :information_source: In case of any issues during installation, please read [FAQ section](#faq) 87 | 88 | 1. Open terminal and change your directory to the one you want to contain Magento project. ![](docs/images/windows-icon.png) On Windows use Git Bash, which is available after Git installation. 89 | 90 | 1. Download or clone the project with Vagrant configuration: 91 | 92 | :warning: Do not open it in PhpStorm until `init_project.sh` has completed PhpStorm configuration in the initialize project step below. 93 | 94 | ``` 95 | git clone git@github.com:paliarush/magento2-vagrant-for-developers.git vagrant-magento 96 | ``` 97 | 98 | Optionally, if you use private repositories on GitHub or download packages from the Magento Marketplace using Composer 99 | 100 | 1. Copy [etc/composer/auth.json.dist](etc/composer/auth.json.dist) to `etc/composer/auth.json`. 101 | 1. Specify your GitHub token by adding `"github.com": "your-github-token"` to the `github-oauth` section for GitHub authorization. 102 | 1. Add the Magento Marketplace keys for Marketplace authorization to the `repo.magento.com` section. 103 | 1. Copy (optional) [etc/config.yaml.dist](etc/config.yaml.dist) as `etc/config.yaml` and make the necessary customizations. 104 | 105 | 1. Initialize the project (this will configure the environment, install Magento, and configure the PHPStorm project): 106 | 107 | ``` 108 | cd vagrant-magento 109 | bash init_project.sh 110 | ``` 111 | 112 | 1. Use the `vagrant-magento` directory as the project root in PHP Storm (not `vagrant-magento/magento2ce`). This is important, because in this case PHP Storm will be configured automatically by [init_project.sh](init_project.sh). If NFS files sync is disabled in [config](etc/config.yaml.dist) and ![](docs/images/windows-icon.png)on Windows hosts [verify the deployment configuration in PHP Storm](docs/phpstorm-configuration-windows-hosts.md). 113 | 114 | Use the URL for accessing your Magento storefront in the browser as your Web server root URL. Typically this is the localhost, which refers to your development machine. Depending on how you've set up your VM you may also need a port number, like `http://localhost:8080`. 115 | 116 | 1. Configure the remote PHP interpreter in PHP Storm. Go to Preferences, then Languages and Frameworks. Click PHP and add a new remote interpreter. Select Deployment configuration as a source for connection details. 117 | 118 | ### Default credentials and settings 119 | 120 | Some of default settings are available for override. These settings can be found in the file [etc/config.yaml.dist](etc/config.yaml.dist). 121 | 122 | To override settings create a copy of the file under the name 'config.yaml' and add your custom settings. 123 | 124 | When using [init_project.sh](init_project.sh), if not specified manually, random IP address is generated and is used as suffix for host name to prevent collisions, in case when two or more instances are running at the same time. 125 | 126 | Upon a successful installation, you'll see the location and URL of the newly-installed Magento 2 application in console. 127 | 128 | **Web access**: 129 | - Access storefront at `http://magento2.vagrant` 130 | - Access admin panel at `http://magento2.vagrant/admin/` 131 | - Magento admin user/password: `admin/123123q` 132 | - Rabbit MQ control panel: `http://magento2.vagrant:15672`, credentials `guest`/`guest` 133 | 134 | :information_source: Your admin URL, storefront URL, and admin user and password are located in `etc/config.yaml.dist`. 135 | 136 | **Codebase and DB access**: 137 | - Path to your Magento installation on the VM: 138 | - Can be retrieved from environment variable: `echo ${MAGENTO_ROOT}` 139 | - ![](docs/images/windows-icon.png) On Windows hosts: `/var/www/magento2ce` 140 | - ![](docs/images/linux-icon.png)![](docs/images/osx-icon.png) On Mac and \*nix hosts: the same as on host 141 | - MySQL DB host: `localhost` (not accessible remotely) 142 | - MySQL DB name: `magento`, `magento_integration_tests` 143 | - MySQL DB user/password: `root:`. In CLI just use `mysql` with no user and password (`root:` will be used by default) 144 | 145 | **Codebase on host** 146 | - CE codebase: `vagrant_project_root/magento2ce` 147 | - EE codebase will be available if path to EE repository is specified in `etc/config.yaml`: `vagrant_project_root/magento2ce/magento2ee` 148 | 149 | ### Getting updates and fixes 150 | 151 | Current vagrant project follows [semantic versioning](http://semver.org/spec/v2.0.0.html) so feel free to pull the latest features and fixes, they will not break your project. 152 | For example your current branch is `2.0`, then it will be safe to pull any changes from `origin/2.0`. However branch `3.0` will contain changes backward incompatible with `2.0`. 153 | Note, that semantic versioning is only used for `x.0` branches (not for `develop`). 154 | 155 | :information_source: To apply changes run `vagrant reload`. 156 | 157 | ## Day-to-day development scenarios 158 | 159 | ### Reinstall Magento 160 | 161 | Use commands described in [Switch between CE and EE](#switch-between-ce-and-ee) section with `-f` flag. Before doing actual re-installation, these commands update linking of EE codebase, clear cache, update composer dependencies. 162 | 163 | If no composer update and relinking of EE codebase is necessary, use the following command. It will clear Magento DB, Magento caches and reinstall Magento instance. 164 | 165 | Go to the root of vagrant project in command line and execute: 166 | 167 | ``` 168 | bash m-reinstall 169 | ``` 170 | 171 | ### Clear Magento cache 172 | 173 | Go to the root of vagrant project in command line and execute: 174 | 175 | ``` 176 | bash m-clear-cache 177 | ``` 178 | 179 | ### Switch between CE and EE 180 | 181 | Assume, that EE codebase is available in `vagrant_project_root/magento2ce/magento2ee`. 182 | The following commands will link/unlink EE codebase, clear cache, update composer dependencies and reinstall Magento. 183 | Go to 'vagrant-magento' created earlier and run in command line: 184 | 185 | ``` 186 | bash m-switch-to-ce 187 | OR 188 | bash m-switch-to-ee 189 | ``` 190 | 191 | Force switch can be done using `-f` flag even if already switched to the target edition. May be helpful to relink EE modules after switching between branches. 192 | 193 | Upgrade can be performed instead of re-installation using `-u` flag. 194 | 195 | :information_source: On Windows hosts (or when NFS mode is disabled in [config.yaml](etc/config.yaml.dist) explicitly) you will be asked to wait until code is uploaded to guest machine by PhpStorm (PhpStorm must be launched). To continue the process press any key. 196 | 197 | ### Sample data installation 198 | 199 | Make sure that `ce_sample_data` and `ee_sample_data` are defined in [config.yaml](etc/config.yaml.dist) and point CE and optionally EE sample data repositories. 200 | During initial project setup or during `bash init_project.sh -fc` (with `-fc` project will be re-created from scratch), sample data repositories willl be checked out to `vagrant_project_root/magento2ce/magento2ce-sample-data` and `vagrant_project_root/magento2ce/magento2ee-sample-data`. 201 | 202 | To install Magento with sample data set `install_sample_data` in [config.yaml](etc/config.yaml.dist) to `1` and run `bash m-switch-to-ce -f` or `bash m-switch-to-ee -f`, depending on the edition to be installed. To disable sample data, set this option to `0` and force-switch to necessary edition (using the same commands). 203 | 204 | ### Basic data generation 205 | 206 | Several entities are generated for testing purposes by default using REST API after Magento installation: 207 | - Customer with address (credentials `customer@example.com`:`123123qQ`) 208 | - Category 209 | - Couple simple products 210 | - Configurable product 211 | 212 | To disable this feature, set `magento/generate_basic_data` in [config.yaml](etc/config.yaml.dist) to `0` and run `bash m-switch-to-ce -f` or `bash m-switch-to-ee -f`, depending on the edition to be installed. 213 | 214 | ### Use Magento CLI (bin/magento) 215 | 216 | Go to 'vagrant-magento' created earlier and run in command line: 217 | 218 | ``` 219 | bash m-bin-magento 220 | e.g. 221 | bash m-bin-magento list 222 | ``` 223 | 224 | ### Debugging with XDebug 225 | 226 | XDebug is already configured to connect to the host machine automatically. So just: 227 | 228 | 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 229 | 1. Start listening for PHP Debug connections in PhpStorm on default 9000 port. See how to [integrate XDebug with PhpStorm](https://www.jetbrains.com/phpstorm/help/configuring-xdebug.html#integrationWithProduct) 230 | 1. Set beakpoint or set option in PhpStorm menu 'Run -> Break at first line in PHP scripts' 231 | 232 | To debug a CLI script: 233 | 234 | 1. Create [remote debug configuration](https://www.jetbrains.com/help/phpstorm/2016.1/run-debug-configuration-php-remote-debug.html) in PhpStorm, use `phpstorm` as IDE key 235 | 1. Run created remote debug configuration 236 | 1. Run CLI command on the guest as follows (`xdebug.remote_host` value might be different for you): 237 | 238 | ``` 239 | php -d xdebug.remote_autostart=1 240 | ``` 241 | 242 | To debug Magento Setup script, go to [Magento installation script](scripts/guest/m-reinstall) and find `php ${install_cmd}`. Follow steps above for any CLI script 243 | 244 | :information_source: In addition to XDebug support, [config.yaml](etc/config.yaml.dist) has several options in `debug` section which allow storefront and admin UI debugging. Plus, desired Magento mode (developer/production/default) can be enabled using `magento_mode` option, default is developer mode. 245 | 246 | ### Connecting to MySQL DB 247 | 248 | Answer can be found [here](https://github.com/paliarush/magento2-vagrant-for-developers/issues/8) 249 | 250 | ### View emails sent by Magento 251 | 252 | All emails are saved to 'vagrant-magento/log/email' in HTML format. 253 | 254 | ### Accessing PHP and other config files 255 | 256 | 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. 257 | Do not edit any symlinks using PhpStorm because it may break your installation. 258 | 259 | After editing configs in IDE it is still required to restart related services manually. 260 | 261 | ### Upgrading Magento 262 | 263 | Sometimes it is necessary to test upgrade flow. This can be easily done as follows (assuming that you have installed instance): 264 | 265 | - For git-based installation - check out codebase corresponding to the target Magento version. Or modify your `composer.json` in case of composer-based installation 266 | - Use commands described in [Switch between CE and EE](#switch-between-ce-and-ee) section with `-u` flag 267 | 268 | ### Multiple Magento instances 269 | 270 | 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. 271 | Unique IP address, SSH port and domain name will be generated for each new instance if not specified manually in `etc/config.yaml` 272 | 273 | ### Update Composer dependencies 274 | 275 | Go to 'vagrant-magento' created earlier and run in command line: 276 | 277 | ``` 278 | bash m-composer install 279 | OR 280 | bash m-composer update 281 | ``` 282 | 283 | ### Running Magento tests 284 | 285 | See [draft](https://github.com/paliarush/magento2-vagrant-for-developers/issues/120) 286 | 287 | 288 | ## Environment configuration 289 | 290 | ### Switch between PHP versions 291 | 292 | Switch between PHP versions using "php_version: " option in [config.yaml](etc/config.yaml.dist). Supported versions are 5.6, 7.0, 7.1 and 7.2. 293 | PHP version will be applied after "vagrant reload". 294 | 295 | ### Activating Varnish 296 | 297 | Set `use_varnish: 1` to use varnish along with apache in [config.yaml](etc/config.yaml.dist). Changes will be applied on `m-reinstall`. 298 | It will use default file etc/magento2_default_varnish.vcl.dist generated from a Magento 2.1 instance. Magento 2.2+ supports additional Varnish features and you may need to provide custom version of VCL to enable them. 299 | Varnish Version: 4.1 300 | 301 | Use the following commands to enable/disable varnish without reinstalling Magento: `m-varnish disable` or `m-varnish enable`. 302 | 303 | ### Activating ElasticSearch 304 | 305 | :information_source: Available in Magento EE only. 306 | 307 | Set `search_engine: "elasticsearch"` in [config.yaml](etc/config.yaml.dist) to use ElasticSearch as current search engine or `search_engine: "mysql"` to use MySQL. Changes will be applied on `m-reinstall`. 308 | 309 | Use the following commands to switch between search engines without reinstalling Magento: `m-search-engine elasticsearch` or `m-search-engine mysql`. 310 | 311 | ### Redis for caching 312 | 313 | :information_source: Available in Magento v2.0.6 and higher. 314 | 315 | Redis is configured as cache backend by default. It is still possible to switch back to filesystem cache by changing `environment_cache_backend` to `filesystem` in [config.yaml](etc/config.yaml.dist). 316 | 317 | ### Reset environment 318 | 319 | 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 and vagrant project settings. After that it will initialize project from scratch. Magento 2 code base (`magento2ce` directory) and [etc/config.yaml](etc/config.yaml.dist) and PhpStorm settings will stay untouched, but guest config files (located in [etc/guest](etc/guest)) will be cleared. 320 | 321 | Go to 'vagrant-magento' created earlier and run in command line: 322 | 323 | ``` 324 | bash init_project.sh -f 325 | ``` 326 | 327 | It is possible to reset Magento 2 code base at the same time. Magento 2 code base will be deleted and then cloned from the repositories specified in [etc/config.yaml](etc/config.yaml.dist) 328 | 329 | ``` 330 | bash init_project.sh -fc 331 | ``` 332 | 333 | To reset PhpStorm project configuration, in addition to `-f` specify `-p` option: 334 | 335 | ``` 336 | bash init_project.sh -fp 337 | ``` 338 | 339 | Ultimate project reset can be achieved by combining all available flags: 340 | 341 | ``` 342 | bash init_project.sh -fcp 343 | ``` 344 | 345 | ### Switch NodeJS Versions 346 | 347 | By default, the box will install the latest `NodeJS LTS` version using the [n package manager](https://www.npmjs.com/package/n). If you need another version of `Node` because of Magento's `package.json` requirements, simply run: 348 | 349 | ```js 350 | n 351 | ``` 352 | 353 | Note: See [Working with npm](https://www.npmjs.com/package/n#working-with-npm) if after switching versions with `n`, `npm` is not working properly. 354 | 355 | ### FAQ 356 | 357 | 1. To debug any CLI script in current Vagrant project, set `debug:vagrant_project` option in [config.yaml](etc/config.yaml.dist) to `1` 358 | 1. Is Windows 10 supported? Yes, but you may face the same issue as described [here](https://github.com/paliarush/magento2-vagrant-for-developers/issues/36) or [here](https://github.com/paliarush/magento2-vagrant-for-developers/issues/173). Also Virtual box may not work on Windows 10 in headless mode, see how to [enable GUI mode](https://www.vagrantup.com/docs/virtualbox/configuration.html) 359 | 1. ![](docs/images/linux-icon.png)![](docs/images/osx-icon.png) On OSX and \*nix hosts NFS will be used by default to sync your project files with guest. On some hosts Vagrant cannot configure NFS properly, in this case it is possible to deploy project without NFS by setting `use_nfs` option in [config.yaml](etc/config.yaml.dist) to `0`
360 | 1. ![](docs/images/windows-icon.png) On Windows hosts you might face `Composer Install Error: ZipArchive::extractTo(): Full extraction path exceed MAXPATHLEN (260)` exception during `composer install`. This can be fixed in 2 ways: decrease path length to the project directory or set `composer_prefer_source` option in [config.yaml](etc/config.yaml.dist) to `1` 361 | 1. Make sure that you used `vagrant-magento` directory as project root in PHP Storm (not `vagrant-magento/magento2ce`) 362 | 1. If project opened in PhpStorm looks broken, close PhpStorm and remove `vagrant-magento/.idea`. Run `bash vagrant-magento/scripts/host/configure_php_storm.sh`. After opening project in PhpStorm again everything should look good 363 | 1. If code is not synchronized properly on Windows hosts (or when NFS mode is disabled in [config.yaml](etc/config.yaml.dist) explicitly), make sure that PhpStorm is running before making any changes in the code. This is important because otherwise PhpStorm will not be able to detect changes and upload them to the guest machine 364 | 1. Please make sure that currently installed software, specified in [requirements section](#requirements), meets minimum version requirement 365 | 1. Be careful if your OS is case-insensitive, NFS might break the symlinks if you cd into the wrong casing and you power the vagrant up. Just be sure to cd in to the casing the directory was originally created as. 366 | 1. Cannot run unit tests from PHPStorm on Magento 2.2, see possible solution [here](https://github.com/paliarush/magento2-vagrant-for-developers/issues/167) 367 | 1. [Permission denied (publickey)](https://github.com/paliarush/magento2-vagrant-for-developers/issues/165) 368 | 1. If during a vagrant reload, the following message appears: 369 | 370 | >There was a problem while downloading the metadata for your box 371 | to check for updates. This is not an error, since it is usually due 372 | to temporary network problems. This is just a warning. The problem 373 | encountered was: 374 | The requested URL returned error: 404 Not Found 375 | 376 | It is likely that your vagrant cli is caching an old url. Perform the following cli commands: 377 | 378 | ```bash 379 | sed -i -- 's/atlas.hashicorp/vagrantcloud/g' ~/.vagrant.d/boxes/{name of your paliarush/ubuntu image}/metadata_url 380 | mv ~/.vagrant.d/boxes/{name of your paliarush/ubuntu image}/metadata_url2 ~/.vagrant.d/boxes/{name of your paliarush/ubuntu image}/metadata_url 381 | ``` 382 | 383 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | Vagrant.require_version ">= 1.8" 5 | 6 | require 'yaml' 7 | require 'vagrant/util/deep_merge' 8 | 9 | module OS 10 | def OS.is_windows 11 | (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil 12 | end 13 | end 14 | 15 | module Config 16 | # Load and override config settings 17 | def Config.load 18 | local_config_dir = 'etc' 19 | config_dist_file = local_config_dir + '/config.yaml.dist' 20 | config_file = local_config_dir + '/config.yaml' 21 | 22 | config_data_dist = YAML.load_file(config_dist_file) 23 | config_data = File.exists?(config_file) ? YAML.load_file(config_file) : {} 24 | return Vagrant::Util::DeepMerge.deep_merge(config_data_dist, config_data) 25 | end 26 | end 27 | 28 | # Get parameters from config file 29 | config_data = Config.load 30 | magento_host_name = config_data['magento']['host_name'] 31 | magento_ip_address = config_data['guest']['ip_address'] 32 | forwarded_ssh_port = config_data['guest']['forwarded_ssh_port'] 33 | guest_memory = config_data['guest']['memory'] 34 | guest_cpus = config_data['guest']['cpus'] 35 | 36 | # NFS will be used for *nix and OSX hosts, if not disabled explicitly in config 37 | use_nfs_for_synced_folders = !OS.is_windows && (config_data['guest']['use_nfs'] == 1) 38 | 39 | host_vagrant_dir = Dir.pwd + '' 40 | host_magento_dir = host_vagrant_dir + '/magento2ce' 41 | 42 | VAGRANT_API_VERSION = 2 43 | Vagrant.configure(VAGRANT_API_VERSION) do |config| 44 | config.vm.box = "paliarush/magento2.ubuntu" 45 | config.vm.box_version = "~> 1.1" 46 | 47 | config.vm.provider "virtualbox" do |vb| 48 | vb.memory = guest_memory 49 | vb.cpus = guest_cpus 50 | # Uncomment option below to avoid issues with VirtualBox on Windows 10 51 | # vb.gui=true 52 | end 53 | 54 | config.vm.synced_folder '.', '/vagrant', disabled: true 55 | config.vm.synced_folder './etc', '/vagrant/etc', mount_options: ["dmode=775,fmode=664"] 56 | config.vm.synced_folder './scripts', '/vagrant/scripts' 57 | config.vm.synced_folder './log', '/vagrant/log' 58 | config.vm.synced_folder './.idea', '/vagrant/.idea', create: true 59 | if use_nfs_for_synced_folders 60 | guest_magento_dir = host_magento_dir 61 | config.vm.synced_folder host_magento_dir, guest_magento_dir, type: "nfs", create: true 62 | else 63 | guest_magento_dir = '/var/www/magento2ce' 64 | config.vm.synced_folder host_magento_dir + '/var', guest_magento_dir + '/var', create: true 65 | config.vm.synced_folder host_magento_dir + '/generated', guest_magento_dir + '/generated', create: true 66 | config.vm.synced_folder host_magento_dir + '/app/etc', guest_magento_dir + '/app/etc', create: true 67 | end 68 | 69 | shell_script_args = [ 70 | use_nfs_for_synced_folders ? "1" : "0", #1 71 | guest_magento_dir, #2 72 | magento_host_name, #3 73 | config_data['environment']['use_php7'] || 0, #4 TODO: Remove legacy parameter, replaced with php_version 74 | host_magento_dir, #5 75 | OS.is_windows ? "1" : "0", #6 76 | host_vagrant_dir, #7 77 | config_data['environment']['php_version'] #8 78 | ] 79 | 80 | config.vm.provision "fix_no_tty", type: "shell", run: "always" do |s| 81 | s.privileged = false 82 | s.inline = "sudo sed -i '/tty/!s/mesg n/tty -s \\&\\& mesg n/' /root/.profile" 83 | end 84 | 85 | config.vm.provision "upgrade_environment_recurring", type: "shell", run: "always", keep_color: true do |s| 86 | s.path = "scripts/provision/upgrade_environment_recurring.sh" 87 | s.args = shell_script_args 88 | end 89 | 90 | config.vm.provision "configure_environment", type: "shell", keep_color: true do |s| 91 | s.path = "scripts/provision/configure_environment.sh" 92 | s.args = shell_script_args 93 | end 94 | 95 | config.vm.provision "configure_environment_recurring", type: "shell", run: "always", keep_color: true do |s| 96 | s.path = "scripts/provision/configure_environment_recurring.sh" 97 | s.args = shell_script_args 98 | end 99 | 100 | config.vm.provision "export_env_variables_recurring", type: "shell", run: "always", keep_color: true do |s| 101 | s.path = "scripts/provision/export_env_variables_recurring.sh" 102 | s.args = shell_script_args 103 | end 104 | 105 | if !use_nfs_for_synced_folders 106 | config.vm.provision "host_compress_magento_code", type: "host_shell", inline: "tar cf scripts/host/magento2ce.tar magento2ce" 107 | config.vm.provision "guest_uncompress_magento_code", type: "shell", inline: "mkdir -p /var/www && tar xf /vagrant/scripts/host/magento2ce.tar -C /var/www &>/dev/null" 108 | config.vm.provision "guest_remove_compressed_code", type: "shell", inline: "rm -f /vagrant/scripts/host/magento2ce.tar" 109 | end 110 | 111 | # Host manager plugin configuration 112 | config.hostmanager.enabled = true 113 | config.hostmanager.manage_host = true 114 | config.hostmanager.ignore_private_ip = false 115 | config.hostmanager.include_offline = true 116 | config.vm.define magento_host_name do |node| 117 | node.vm.hostname = magento_host_name 118 | node.vm.network :private_network, ip: magento_ip_address 119 | node.vm.network :forwarded_port, guest: 22, host: forwarded_ssh_port 120 | end 121 | config.ssh.guest_port = forwarded_ssh_port 122 | end 123 | -------------------------------------------------------------------------------- /docs/images/automatic-upload.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paliarush/magento2-vagrant-for-developers/96bf66a60f8a166d0eb04e17cab0124d2e3da64d/docs/images/automatic-upload.png -------------------------------------------------------------------------------- /docs/images/deployment-configuration.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paliarush/magento2-vagrant-for-developers/96bf66a60f8a166d0eb04e17cab0124d2e3da64d/docs/images/deployment-configuration.png -------------------------------------------------------------------------------- /docs/images/exclude-paths-from-mapping.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paliarush/magento2-vagrant-for-developers/96bf66a60f8a166d0eb04e17cab0124d2e3da64d/docs/images/exclude-paths-from-mapping.png -------------------------------------------------------------------------------- /docs/images/linux-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paliarush/magento2-vagrant-for-developers/96bf66a60f8a166d0eb04e17cab0124d2e3da64d/docs/images/linux-icon.png -------------------------------------------------------------------------------- /docs/images/new-sftp-server.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paliarush/magento2-vagrant-for-developers/96bf66a60f8a166d0eb04e17cab0124d2e3da64d/docs/images/new-sftp-server.png -------------------------------------------------------------------------------- /docs/images/osx-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paliarush/magento2-vagrant-for-developers/96bf66a60f8a166d0eb04e17cab0124d2e3da64d/docs/images/osx-icon.png -------------------------------------------------------------------------------- /docs/images/private-key-auth-type.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paliarush/magento2-vagrant-for-developers/96bf66a60f8a166d0eb04e17cab0124d2e3da64d/docs/images/private-key-auth-type.png -------------------------------------------------------------------------------- /docs/images/projects-mapping.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paliarush/magento2-vagrant-for-developers/96bf66a60f8a166d0eb04e17cab0124d2e3da64d/docs/images/projects-mapping.png -------------------------------------------------------------------------------- /docs/images/release_badge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paliarush/magento2-vagrant-for-developers/96bf66a60f8a166d0eb04e17cab0124d2e3da64d/docs/images/release_badge.png -------------------------------------------------------------------------------- /docs/images/release_badge.svg: -------------------------------------------------------------------------------- 1 | releasereleasev2.2.0v2.2.0 2 | -------------------------------------------------------------------------------- /docs/images/ssh-config.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paliarush/magento2-vagrant-for-developers/96bf66a60f8a166d0eb04e17cab0124d2e3da64d/docs/images/ssh-config.png -------------------------------------------------------------------------------- /docs/images/tests_badge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paliarush/magento2-vagrant-for-developers/96bf66a60f8a166d0eb04e17cab0124d2e3da64d/docs/images/tests_badge.png -------------------------------------------------------------------------------- /docs/images/tests_badge.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | tests 16 | tests 17 | passing on OSX 18 | passing on OSX 19 | 20 | 21 | -------------------------------------------------------------------------------- /docs/images/upload-magento-codebase.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paliarush/magento2-vagrant-for-developers/96bf66a60f8a166d0eb04e17cab0124d2e3da64d/docs/images/upload-magento-codebase.png -------------------------------------------------------------------------------- /docs/images/windows-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paliarush/magento2-vagrant-for-developers/96bf66a60f8a166d0eb04e17cab0124d2e3da64d/docs/images/windows-icon.png -------------------------------------------------------------------------------- /docs/known-issues.md: -------------------------------------------------------------------------------- 1 | Known issues 2 | ---------------------------- 3 | 4 | 1. PHP Warning: require(/var/www/magento2ce/app/etc/NonComposerComponentRegistration.php): failed to open stream: No such file or directory 5 | Check modified files from /var/www/magento2ce/app/etc/ in git and revert them. 6 | 7 | 2. Guest system behaves wierd, e.g. install process can be suddenly killed. 8 | Try to increase memory for guest machine. 9 | 10 | 11 | -------------------------------------------------------------------------------- /docs/performance-issue-on-windows-hosts.md: -------------------------------------------------------------------------------- 1 | Desired developer experience 2 | ---------------------------- 3 | 4 | Vagrant provides convenient way to set up development environment consistently on different hosts (see [more](https://docs.vagrantup.com/v2/why-vagrant/)). Typically it uses Virtual Box as a provider with \*nix system as guest OS. 5 | This allows Magento developers who use Windows machines to run their Magento instance in \*nix environment similar to those on Bamboo or production. 6 | Project files editing, work with Git and running tests is usually done on host OS (Windows), since this approach provides better user experience. However, in this case project files must be synchronized between host and guest OSs to allow code modifications be visible on the running Magento instance as well as provide access to auto-generated files (e.g. view materialized files, generated classes) in the IDE. So two-way synchronization is required. 7 | 8 | Existing problem for Windows users 9 | ---------------------------------- 10 | 11 | Developers, who use Magento installed on Vagrant for daily development in Windows environment, complaint about Magento performance issues. 12 | The main reason for performance degradation is that default synchronization (Virtual box shared folders) is used for project files synchronization on host and on guest OSs. **PHP requests all source files from the host,** also lost of files are created by the Magento instance on the fly in non-production mode, which are immediately synchronized with the host. 13 | There are several other types of files synchronization available, but all of them have issues, which spoil developer experience: 14 | 15 | - SMB - on some machines does not work (various errors, unstable 16 | implementation). Also when EE is linked to CE on the host using 17 | symlinks (our current workflow), **symlinks are not created properly** on 18 | the guest. SSH connection to the guest OS is aborted from time to 19 | time when SMB is enabled. 20 | - RSync - requires extra software to be installed on the Windows, 21 | provides **one-way synchronization only** 22 | - NFS - is recommended and performant option for \*nix hosts, but is 23 | **unavailable for Windows** hosts 24 | 25 | Proposed solution 26 | ----------------- 27 | 28 | Even though there are no out-of-the-box solution which satisfies our developer experience requirements, we can apply hybrid approach, which: 29 | 30 | - is reasonably complex 31 | - does not break developer experience 32 | - has negligible performance degradation caused by files synchronization 33 | 34 | To solve performance degradation problem, local copy of the project should be stored on host (for good indexing performance in IDE) and on the guest (to avoid delays caused by PHP requesting remote files via network). This cannot be achieved with built-in Vagrant synchronization capabilities. However, this can be done using one-way PhpStorm project deployment to remote host or by using rsync. This approach has one drawback: all files generated on the guest, will not be visible to IDE and as a result autocomplete for auto-generated classes will be unavailable. This issue can be overcome by enabling two-way Vagrant synchronization for those files which should be downloaded from guest OS. 35 | -------------------------------------------------------------------------------- /docs/phpstorm-configuration-windows-hosts.md: -------------------------------------------------------------------------------- 1 | Synchronization with local PHP Storm 2 | ----------------- 3 | 4 | This solution is applicable to any Vagrant configuration for Magento instance, several tweaks should be done: 5 | 6 | 1. Set up synchronization in vagrant config file only for those directories, which require guest-to-host synchronization (can be of any type, even default). Recommended directories are already configured in Vagrant config: 7 | 8 | ``` 9 | Vagrant.configure(2) do |config| 10 | config.vm.synced_folder '../magento2ce/var', '/var/www/magento2ce/var' 11 | config.vm.synced_folder '../magento2ce/app/etc', '/var/www/magento2ce/app/etc' 12 | end 13 | ``` 14 | 15 | 1. Open your project on host machine in PhpStorm and set up deployment configuration, which will upload to the guest machine everything except for those folders which are synchronized by Vagrant. :information_source: Note that rsync can be used instead of PHP Storm deployment. 16 | 1. Go to Tools -> Deployment -> Configuration 17 | 18 | ![](images/deployment-configuration.png) 19 | 20 | 1. Add new SFTP server and mark it as default when added (using button in top left corner) 21 | 22 | ![](images/new-sftp-server.png) 23 | 24 | 1. Fill out connection settings using the information taken from vagrant ssh config 25 | - Go to the 'vagrant-magento' directory (contains your vagrant project) in console and execute 'vagrant ssh-config' 26 | 27 | ![](images/ssh-config.png) 28 | 29 | - Use private key Auth type instead of password 30 | 31 | ![](images/private-key-auth-type.png) 32 | 33 | 1. Set up mapping between your local and remote versions of the project, for remote project use '/var/www/magento2ce' 34 | 35 | ![](images/projects-mapping.png) 36 | 37 | 1. Add remote paths excluded from synchronization by PhpStorm. You should add those paths which are specified in Vagrant config for synchronization. 38 | 39 | ![](images/exclude-paths-from-mapping.png) 40 | 41 | 1. Go to Tools -> Deployment -> Options... and enable automatic upload to default server and check "Upload external changes" 42 | 43 | ![](images/automatic-upload.png) 44 | 45 | 46 | Day-to-day development scenarios 47 | ----------------- 48 | 49 | 1. You can upload full Magento code base to the virtual machine from the host machine using context menu on the root of the project in PhpStorm. 50 | 51 | ![](images/upload-magento-codebase.png) -------------------------------------------------------------------------------- /etc/.gitignore: -------------------------------------------------------------------------------- 1 | /* 2 | !/.gitignore 3 | !/composer 4 | /composer/* 5 | !/composer/auth.json.dist 6 | !/config.yaml.dist 7 | !/magento2_virtual_host.conf.dist 8 | !/guest -------------------------------------------------------------------------------- /etc/composer/auth.json.dist: -------------------------------------------------------------------------------- 1 | { 2 | "github-oauth": { 3 | }, 4 | "http-basic": { 5 | "repo.magento.com": { 6 | "username": "your-magento-repo-public-key", 7 | "password": "your-magento-repo-secret-key" 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /etc/config.yaml.dist: -------------------------------------------------------------------------------- 1 | # [To apply changes: init_project.sh -fc] Possible values: git, composer 2 | checkout_source_from: "git" 3 | 4 | composer_project: 5 | # Current section used only if 'checkout_source_from' is set to 'composer' 6 | 7 | # [To apply changes: init_project.sh -fc] 8 | # Custom version can be provided by using '={version}' appended to repo name. E.g. name: "magento/project-community-edition=2.2.0". Otherwise, default version is used 9 | name: "magento/project-community-edition" 10 | # Make sure to specify valid keys for this repository in etc/composer/auth.json 11 | url: "https://repo.magento.com" 12 | 13 | repository_url: 14 | # Current section used only if 'checkout_source_from' is set to 'git' 15 | 16 | # [To apply changes: init_project.sh -fc] 17 | # git@github.com:magento/magento2ce.git OR custom one. Use '::' to specify a specific branch, e.g: git@github.com:magento/magento2.git::2.1 18 | ce: "git@github.com:magento/magento2.git" 19 | # git@github.com:magento/magento2ee.git OR custom one 20 | ee: "" 21 | # can be replaced with custom repository. Use '::' to specify a specific branch, e.g: git@github.com:magento/magento2-sample-data.git::2.1-develop 22 | ce_sample_data: "git@github.com:magento/magento2-sample-data.git" 23 | # git@github.com:magento/magento2-sample-data-ee.git OR custom one 24 | ee_sample_data: "" 25 | 26 | guest: 27 | # [To apply changes: init_project.sh -f] NFS will be used for folder synchronization on *nix and OSX hosts by default. 28 | use_nfs: 1 29 | # [To apply changes: vagrant reload] Default is 2Gb, around 3Gb is necessary to run functional tests. 30 | memory: 2048 31 | # Recommended number of CPUs is 2 32 | cpus: 1 33 | ip_address: "192.168.10.2" 34 | forwarded_ssh_port: 3000 35 | 36 | environment: 37 | # [To apply changes: vagrant reload] Valid versions: 5.6, 7.0, 7.1, 7.2 38 | php_version: "7.1" 39 | composer_prefer_source: 0 40 | # [To apply changes: m-reinstall OR m-varnish enable/disable] 41 | use_varnish: 0 42 | # [To apply changes: m-reinstall] Possible values: mysql, elasticsearch 43 | search_engine: "mysql" 44 | # [To apply changes: m-clear-cache] Possible values: redis, filesystem 45 | cache_backend: "filesystem" 46 | 47 | magento: 48 | # [To apply changes: m-switch-to-ce -f OR m-switch-to-ee -f] 49 | install_sample_data: 0 50 | # [To apply changes: m-switch-to-ce -f OR m-switch-to-ee -f] Generate customer (customer@example.com:123123qQ), category, simple product, configurable product after successful Magento installation 51 | generate_basic_data: 1 52 | # [To apply changes: init_project.sh -f] 53 | host_name: "magento2.vagrant2" 54 | # [To apply changes: m-reinstall] 55 | admin_frontname: "admin" 56 | language: "en_US" 57 | timezone: "America/Chicago" 58 | currency: "USD" 59 | admin_user: "admin" 60 | admin_password: "123123q" 61 | # [Changes applied on m-clear-cache] Available options: developer, production, default 62 | mode: "developer" 63 | 64 | debug: 65 | # [Changes applied on m-clear-cache] Enable template path and block name hints on storefront 66 | magento_storefront: 0 67 | # [Changes applied on m-clear-cache] Enable template path hints in the admin panel 68 | magento_admin: 0 69 | # [Changes applied immediately] Enable detailed output from all scripts provided by current vagrant project 70 | vagrant_project: 0 71 | -------------------------------------------------------------------------------- /etc/guest/.gitignore: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------- /etc/magento2_default_varnish.vcl.dist: -------------------------------------------------------------------------------- 1 | vcl 4.0; 2 | 3 | import std; 4 | # The minimal Varnish version is 4.0 5 | # For SSL offloading, pass the following header in your proxy server or load balancer: 'X-Forwarded-Proto: https' 6 | 7 | backend default { 8 | .host = "localhost"; 9 | .port = "8080"; 10 | } 11 | 12 | acl purge { 13 | "localhost"; 14 | } 15 | 16 | sub vcl_recv { 17 | if (req.method == "PURGE") { 18 | if (client.ip !~ purge) { 19 | return (synth(405, "Method not allowed")); 20 | } 21 | if (!req.http.X-Magento-Tags-Pattern) { 22 | return (synth(400, "X-Magento-Tags-Pattern header required")); 23 | } 24 | ban("obj.http.X-Magento-Tags ~ " + req.http.X-Magento-Tags-Pattern); 25 | return (synth(200, "Purged")); 26 | } 27 | 28 | if (req.method != "GET" && 29 | req.method != "HEAD" && 30 | req.method != "PUT" && 31 | req.method != "POST" && 32 | req.method != "TRACE" && 33 | req.method != "OPTIONS" && 34 | req.method != "DELETE") { 35 | /* Non-RFC2616 or CONNECT which is weird. */ 36 | return (pipe); 37 | } 38 | 39 | # We only deal with GET and HEAD by default 40 | if (req.method != "GET" && req.method != "HEAD") { 41 | return (pass); 42 | } 43 | 44 | # Bypass shopping cart, checkout and search requests 45 | if (req.url ~ "/checkout" || req.url ~ "/catalogsearch") { 46 | return (pass); 47 | } 48 | 49 | # normalize url in case of leading HTTP scheme and domain 50 | set req.url = regsub(req.url, "^http[s]?://", ""); 51 | 52 | # collect all cookies 53 | std.collect(req.http.Cookie); 54 | 55 | # Compression filter. See https://www.varnish-cache.org/trac/wiki/FAQ/Compression 56 | if (req.http.Accept-Encoding) { 57 | if (req.url ~ "\.(jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf|flv)$") { 58 | # No point in compressing these 59 | unset req.http.Accept-Encoding; 60 | } elsif (req.http.Accept-Encoding ~ "gzip") { 61 | set req.http.Accept-Encoding = "gzip"; 62 | } elsif (req.http.Accept-Encoding ~ "deflate" && req.http.user-agent !~ "MSIE") { 63 | set req.http.Accept-Encoding = "deflate"; 64 | } else { 65 | # unkown algorithm 66 | unset req.http.Accept-Encoding; 67 | } 68 | } 69 | 70 | # Remove Google gclid parameters to minimize the cache objects 71 | set req.url = regsuball(req.url,"\?gclid=[^&]+$",""); # strips when QS = "?gclid=AAA" 72 | set req.url = regsuball(req.url,"\?gclid=[^&]+&","?"); # strips when QS = "?gclid=AAA&foo=bar" 73 | set req.url = regsuball(req.url,"&gclid=[^&]+",""); # strips when QS = "?foo=bar&gclid=AAA" or QS = "?foo=bar&gclid=AAA&bar=baz" 74 | 75 | # static files are always cacheable. remove SSL flag and cookie 76 | if (req.url ~ "^/(pub/)?(media|static)/.*\.(ico|css|js|jpg|jpeg|png|gif|tiff|bmp|mp3|ogg|svg|swf|woff|woff2|eot|ttf|otf)$") { 77 | unset req.http.Https; 78 | unset req.http.X-Forwarded-Proto; 79 | unset req.http.Cookie; 80 | } 81 | 82 | return (hash); 83 | } 84 | 85 | sub vcl_hash { 86 | if (req.http.cookie ~ "X-Magento-Vary=") { 87 | hash_data(regsub(req.http.cookie, "^.*?X-Magento-Vary=([^;]+);*.*$", "\1")); 88 | } 89 | 90 | # For multi site configurations to not cache each other's content 91 | if (req.http.host) { 92 | hash_data(req.http.host); 93 | } else { 94 | hash_data(server.ip); 95 | } 96 | 97 | # To make sure http users don't see ssl warning 98 | if (req.http.X-Forwarded-Proto) { 99 | hash_data(req.http.X-Forwarded-Proto); 100 | } 101 | 102 | } 103 | 104 | sub vcl_backend_response { 105 | if (beresp.http.content-type ~ "text") { 106 | set beresp.do_esi = true; 107 | } 108 | 109 | if (bereq.url ~ "\.js$" || beresp.http.content-type ~ "text") { 110 | set beresp.do_gzip = true; 111 | } 112 | 113 | # cache only successfully responses and 404s 114 | if (beresp.status != 200 && beresp.status != 404) { 115 | set beresp.ttl = 0s; 116 | set beresp.uncacheable = true; 117 | return (deliver); 118 | } elsif (beresp.http.Cache-Control ~ "private") { 119 | set beresp.uncacheable = true; 120 | set beresp.ttl = 86400s; 121 | return (deliver); 122 | } 123 | 124 | if (beresp.http.X-Magento-Debug) { 125 | set beresp.http.X-Magento-Cache-Control = beresp.http.Cache-Control; 126 | } 127 | 128 | # validate if we need to cache it and prevent from setting cookie 129 | # images, css and js are cacheable by default so we have to remove cookie also 130 | if (beresp.ttl > 0s && (bereq.method == "GET" || bereq.method == "HEAD")) { 131 | unset beresp.http.set-cookie; 132 | if (bereq.url !~ "\.(ico|css|js|jpg|jpeg|png|gif|tiff|bmp|gz|tgz|bz2|tbz|mp3|ogg|svg|swf|woff|woff2|eot|ttf|otf)(\?|$)") { 133 | set beresp.http.Pragma = "no-cache"; 134 | set beresp.http.Expires = "-1"; 135 | set beresp.http.Cache-Control = "no-store, no-cache, must-revalidate, max-age=0"; 136 | set beresp.grace = 1m; 137 | } 138 | } 139 | 140 | # If page is not cacheable then bypass varnish for 2 minutes as Hit-For-Pass 141 | if (beresp.ttl <= 0s || 142 | beresp.http.Surrogate-control ~ "no-store" || 143 | (!beresp.http.Surrogate-Control && beresp.http.Vary == "*")) { 144 | # Mark as Hit-For-Pass for the next 2 minutes 145 | set beresp.ttl = 120s; 146 | set beresp.uncacheable = true; 147 | } 148 | return (deliver); 149 | } 150 | 151 | sub vcl_deliver { 152 | if (resp.http.X-Magento-Debug) { 153 | if (resp.http.x-varnish ~ " ") { 154 | set resp.http.X-Magento-Cache-Debug = "HIT"; 155 | } else { 156 | set resp.http.X-Magento-Cache-Debug = "MISS"; 157 | } 158 | } else { 159 | unset resp.http.Age; 160 | } 161 | 162 | unset resp.http.X-Magento-Debug; 163 | unset resp.http.X-Magento-Tags; 164 | unset resp.http.X-Powered-By; 165 | unset resp.http.Server; 166 | unset resp.http.X-Varnish; 167 | unset resp.http.Via; 168 | unset resp.http.Link; 169 | } 170 | -------------------------------------------------------------------------------- /etc/magento2_virtual_host.conf.dist: -------------------------------------------------------------------------------- 1 | 2 | DocumentRoot "" 3 | ServerName 4 | "> 5 | Options Indexes FollowSymLinks 6 | AllowOverride All 7 | Require all granted 8 | 9 | ErrorLog "${APACHE_LOG_DIR}/error.log" 10 | CustomLog "${APACHE_LOG_DIR}/access.log" common 11 | 12 | -------------------------------------------------------------------------------- /init_project.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | vagrant_dir=$PWD 6 | 7 | source "${vagrant_dir}/scripts/output_functions.sh" 8 | resetNestingLevel 9 | current_script_name=`basename "$0"` 10 | initLogFile ${current_script_name} 11 | 12 | debug_vagrant_project="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "debug_vagrant_project")" 13 | if [[ ${debug_vagrant_project} -eq 1 ]]; then 14 | set -x 15 | fi 16 | 17 | config_path="${vagrant_dir}/etc/config.yaml" 18 | if [[ ! -f "${config_path}" ]]; then 19 | status "Initializing etc/config.yaml using defaults from etc/config.yaml.dist" 20 | cp "${config_path}.dist" "${config_path}" 21 | fi 22 | 23 | magento_ce_dir="${vagrant_dir}/magento2ce" 24 | magento_ce_sample_data_dir="${magento_ce_dir}/magento2ce-sample-data" 25 | magento_ee_dir="${magento_ce_dir}/magento2ee" 26 | magento_ee_sample_data_dir="${magento_ce_dir}/magento2ee-sample-data" 27 | host_os="$(bash "${vagrant_dir}/scripts/host/get_host_os.sh")" 28 | use_nfs="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "guest_use_nfs")" 29 | repository_url_ce="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "repository_url_ce")" 30 | repository_url_ee="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "repository_url_ee")" 31 | composer_project_name="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "composer_project_name")" 32 | composer_project_url="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "composer_project_url")" 33 | checkout_source_from="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "checkout_source_from")" 34 | 35 | function checkoutSourceCodeFromGit() 36 | { 37 | if [[ ! -d ${magento_ce_dir} ]]; then 38 | if [[ ${host_os} == "Windows" ]]; then 39 | status "Configuring git for Windows host" 40 | git config --global core.autocrlf false 41 | git config --global core.eol LF 42 | git config --global diff.renamelimit 5000 43 | fi 44 | 45 | initMagentoCeGit 46 | initMagentoCeSampleGit 47 | 48 | # By default EE repository is not specified and EE project is not checked out 49 | if [[ -n "${repository_url_ee}" ]]; then 50 | initMagentoEeGit 51 | fi 52 | # By default EE sample data repository is not specified and EE project is not checked out 53 | repository_url_ee_sample_data="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "repository_url_ee_sample_data")" 54 | if [ -n "${repository_url_ee_sample_data}" ]; then 55 | initMagentoEeSampleGit 56 | fi 57 | fi 58 | } 59 | 60 | function initMagentoCeGit() 61 | { 62 | initGitRepository ${repository_url_ce} "CE" "${magento_ce_dir}" 63 | } 64 | 65 | function initMagentoEeGit() 66 | { 67 | initGitRepository ${repository_url_ee} "EE" "${magento_ee_dir}" 68 | } 69 | 70 | function initMagentoCeSampleGit() 71 | { 72 | repository_url_ce_sample_data="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "repository_url_ce_sample_data")" 73 | initGitRepository ${repository_url_ce_sample_data} "CE sample data" "${magento_ce_sample_data_dir}" 74 | } 75 | 76 | function initMagentoEeSampleGit() 77 | { 78 | initGitRepository ${repository_url_ee_sample_data} "EE sample data" "${magento_ee_sample_data_dir}" 79 | } 80 | 81 | # Initialize the cloning and checkout of a git repository 82 | # Arguments: 83 | # Url of repository 84 | # Name of repository (CE, EE) 85 | # Directory where the repository will be cloned to 86 | function initGitRepository() 87 | { 88 | local repository_url=${1} 89 | local repository_name=${2} 90 | local directory=${3} 91 | 92 | if [[ ${repository_url} == *"::"* ]]; then 93 | local branch=$(getGitBranch ${repository_url}) 94 | local repo=$(getGitRepository ${repository_url}) 95 | else 96 | local repo=${repository_url} 97 | fi 98 | 99 | status "Checking out ${repository_name} repository" 100 | git clone ${repo} "${directory}" 2> >(logError) > >(log) 101 | 102 | if [[ -n ${branch} ]]; then 103 | status "Checking out branch ${branch} of ${repository_name} repository" 104 | cd "${directory}" 105 | git fetch 2> >(logError) > >(log) 106 | git checkout ${branch} 2> >(log) > >(log) 107 | fi 108 | cd "${vagrant_dir}" 109 | } 110 | 111 | # Get the git repository from a repository_url setting in config.yaml 112 | function getGitRepository() 113 | { 114 | local repo="${1%::*}" # Gets the substring before the '::' characters 115 | echo ${repo} 116 | } 117 | 118 | # Get the git branch from a repository_url setting in config.yaml 119 | function getGitBranch() 120 | { 121 | local branch="${1#*::}" # Gets the substring after the '::' characters 122 | echo ${branch} 123 | } 124 | 125 | function composerCreateProject() 126 | { 127 | if [[ ! -d ${magento_ce_dir} ]]; then 128 | status "Downloading Magento codebase using 'composer create-project'" 129 | bash "${vagrant_dir}/scripts/host/composer.sh" create-project ${composer_project_name} "${magento_ce_dir}" --repository-url=${composer_project_url} 130 | 131 | # TODO: Workaround for Magento 2.2+ until PHP is upgraded to 7.1 on the guest 132 | cd "${magento_ce_dir}" 133 | composer_dir="${vagrant_dir}/scripts/host" 134 | composer_phar="${composer_dir}/composer.phar" 135 | php_executable="$(bash "${vagrant_dir}/scripts/host/get_path_to_php.sh")" 136 | project_version="$("${php_executable}" "${composer_phar}" show --self | grep version)" 137 | matching_version_pattern='2.[23].[0-9]+' 138 | if [[ ${project_version} =~ ${matching_version_pattern} ]]; then 139 | status "Composer require zendframework/zend-code:~3.1.0 (needed for Magento 2.2+ only)" 140 | cd "${magento_ce_dir}" 141 | bash "${vagrant_dir}/scripts/host/composer.sh" require "zendframework/zend-code:~3.1.0" 142 | fi 143 | fi 144 | } 145 | 146 | bash "${vagrant_dir}/scripts/host/check_requirements.sh" 147 | 148 | status "Installing missing vagrant plugins" 149 | vagrant_plugin_list="$(vagrant plugin list)" 150 | if ! echo ${vagrant_plugin_list} | grep -q 'vagrant-hostmanager' ; then 151 | vagrant plugin install vagrant-hostmanager 152 | fi 153 | if ! echo ${vagrant_plugin_list} | grep -q 'vagrant-vbguest' ; then 154 | vagrant plugin install vagrant-vbguest 155 | fi 156 | if ! echo ${vagrant_plugin_list} | grep -q 'vagrant-host-shell' ; then 157 | vagrant plugin install vagrant-host-shell 158 | fi 159 | 160 | status "Generating random IP address, and host name to prevent collisions (if no custom values specified)" 161 | random_ip="$(( ( RANDOM % 240 ) + 12 ))" 162 | forwarded_ssh_port="$(( random_ip + 3000 ))" 163 | sed -i.back "s|ip_address: \"192.168.10.2\"|ip_address: \"192.168.10.${random_ip}\"|g" "${config_path}" 164 | sed -i.back "s|host_name: \"magento2.vagrant2\"|host_name: \"magento2.vagrant${random_ip}\"|g" "${config_path}" 165 | sed -i.back "s|forwarded_ssh_port: 3000|forwarded_ssh_port: ${forwarded_ssh_port}|g" "${config_path}" 166 | rm -f "${config_path}.back" 167 | 168 | # Clean up the project before initialization if "-f" option was specified. Remove codebase if "-fc" is used. 169 | force_project_cleaning=0 170 | force_codebase_cleaning=0 171 | force_phpstorm_config_cleaning=0 172 | while getopts 'fcp' flag; do 173 | case "${flag}" in 174 | f) force_project_cleaning=1 ;; 175 | c) force_codebase_cleaning=1 ;; 176 | p) force_phpstorm_config_cleaning=1 ;; 177 | *) error "Unexpected option" && exit 1;; 178 | esac 179 | done 180 | if [[ ${force_project_cleaning} -eq 1 ]]; then 181 | status "Cleaning up the project before initialization since '-f' option was used" 182 | vagrant destroy -f 2> >(logError) > >(log) 183 | mv "${vagrant_dir}/etc/guest/.gitignore" "${vagrant_dir}/etc/.gitignore.back" 184 | rm -rf "${vagrant_dir}/.vagrant" "${vagrant_dir}/etc/guest" 185 | mkdir "${vagrant_dir}/etc/guest" 186 | mv "${vagrant_dir}/etc/.gitignore.back" "${vagrant_dir}/etc/guest/.gitignore" 187 | cd "${vagrant_dir}/log" && mv email/.gitignore email_gitignore.back && rm -rf email && mkdir email && mv email_gitignore.back email/.gitignore 188 | if [[ ${force_codebase_cleaning} -eq 1 ]]; then 189 | status "Removing current Magento codebase before initialization since '-c' option was used" 190 | rm -rf "${magento_ce_dir}" 191 | fi 192 | fi 193 | 194 | if [[ ! -d ${magento_ce_dir} ]]; then 195 | if [[ "${checkout_source_from}" == "composer" ]]; then 196 | composerCreateProject 197 | elif [[ "${checkout_source_from}" == "git" ]]; then 198 | checkoutSourceCodeFromGit 199 | else 200 | error "Value specified for 'checkout_source_from' is invalid. Supported options: composer OR git" 201 | exit 1 202 | fi 203 | fi 204 | 205 | if [[ "${checkout_source_from}" == "git" ]]; then 206 | status "Installing Magento dependencies via Composer" 207 | cd "${magento_ce_dir}" 208 | bash "${vagrant_dir}/scripts/host/composer.sh" install 209 | fi 210 | 211 | status "Initializing vagrant box" 212 | cd "${vagrant_dir}" 213 | 214 | vagrant up --provider virtualbox 2> >(logError) | { 215 | while IFS= read -r line 216 | do 217 | filterVagrantOutput "${line}" 218 | lastline="${line}" 219 | done 220 | filterVagrantOutput "${lastline}" 221 | } 222 | 223 | bash "${vagrant_dir}/scripts/host/check_mounted_directories.sh" 224 | 225 | if [[ ${force_project_cleaning} -eq 1 ]] && [[ ${force_phpstorm_config_cleaning} -eq 1 ]]; then 226 | status "Resetting PhpStorm configuration since '-p' option was used" 227 | rm -rf "${vagrant_dir}/.idea" 228 | fi 229 | if [[ ! -f "${vagrant_dir}/.idea/deployment.xml" ]]; then 230 | bash "${vagrant_dir}/scripts/host/configure_php_storm.sh" 231 | fi 232 | bash "${vagrant_dir}/scripts/host/configure_tests.sh" 233 | 234 | if [[ ${host_os} == "Windows" ]] || [[ ${use_nfs} == 0 ]]; then 235 | # Automatic switch to EE during project initialization cannot be supported on Windows 236 | status "Installing Magento CE" 237 | bash "${vagrant_dir}/scripts/host/m_reinstall.sh" 2> >(logError) 238 | else 239 | if [[ -n "${repository_url_ee}" ]]; then 240 | bash "${vagrant_dir}/scripts/host/m_switch_to_ee.sh" -f 2> >(logError) 241 | else 242 | bash "${vagrant_dir}/scripts/host/m_switch_to_ce.sh" -f 2> >(logError) 243 | fi 244 | fi 245 | 246 | success "Project initialization succesfully completed (make sure there are no errors in the log above)" 247 | 248 | info "$(bold)[Important]$(regular) 249 | Please use $(bold)${vagrant_dir}$(regular) directory as PhpStorm project root, NOT $(bold)${magento_ce_dir}$(regular)." 250 | 251 | if [[ ${host_os} == "Windows" ]] || [[ ${use_nfs} == 0 ]]; then 252 | info "$(bold)[Optional]$(regular) 253 | To verify that deployment configuration for $(bold)${magento_ce_dir}$(regular) in PhpStorm is correct, 254 | use instructions provided here: $(bold)https://github.com/paliarush/magento2-vagrant-for-developers/blob/2.0/docs/phpstorm-configuration-windows-hosts.md$(regular). 255 | If not using PhpStorm, you can set up synchronization using rsync" 256 | fi 257 | 258 | info "$(regular)See details in $(bold)${vagrant_dir}/log/${current_script_name}.log$(regular). For debug output set $(bold)debug:vagrant_project$(regular) to $(bold)1$(regular) in $(bold)etc/config.yaml$(regular)" 259 | -------------------------------------------------------------------------------- /lib/.gitignore: -------------------------------------------------------------------------------- 1 | * -------------------------------------------------------------------------------- /log/email/.gitignore: -------------------------------------------------------------------------------- 1 | * -------------------------------------------------------------------------------- /m-bin-magento: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | cd "$(dirname "${BASH_SOURCE[0]}")" && vagrant_dir=$PWD 6 | 7 | source "${vagrant_dir}/scripts/output_functions.sh" 8 | resetNestingLevel 9 | current_script_name=`basename "$0"` 10 | initLogFile ${current_script_name} 11 | 12 | debug_vagrant_project="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "debug_vagrant_project")" 13 | if [[ ${debug_vagrant_project} -eq 1 ]]; then 14 | set -x 15 | fi 16 | 17 | arguments=$@ 18 | cd "${vagrant_dir}" 19 | vagrant ssh -c "\$MAGENTO_ROOT/bin/magento $arguments" 2> >(logError) 20 | # To debug, comment out line above and uncomment line below 21 | # vagrant ssh -c "php -d xdebug.remote_autostart=1 \$MAGENTO_ROOT/bin/magento $arguments" 2> >(logError) 22 | 23 | info "$(regular)See details in $(bold)${vagrant_dir}/log/${current_script_name}.log$(regular). For debug output set $(bold)debug:vagrant_project$(regular) to $(bold)1$(regular) in $(bold)etc/config.yaml$(regular)" 24 | -------------------------------------------------------------------------------- /m-clear-cache: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | cd "$(dirname "${BASH_SOURCE[0]}")" && vagrant_dir=$PWD 6 | 7 | source "${vagrant_dir}/scripts/output_functions.sh" 8 | resetNestingLevel 9 | current_script_name=`basename "$0"` 10 | initLogFile ${current_script_name} 11 | 12 | warm_up_cache=0 13 | while getopts 'w' flag; do 14 | case "${flag}" in 15 | w) warm_up_cache=1 ;; 16 | *) error "Unexpected option" && exit 1;; 17 | esac 18 | done 19 | 20 | debug_vagrant_project="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "debug_vagrant_project")" 21 | if [[ ${debug_vagrant_project} -eq 1 ]]; then 22 | set -x 23 | fi 24 | 25 | bash "${vagrant_dir}/scripts/host/m_clear_cache.sh" "$@" 2> >(logError) 26 | 27 | if [[ ${warm_up_cache} -eq 1 ]]; then 28 | incrementNestingLevel 29 | bash "${vagrant_dir}/scripts/host/warm_up_cache.sh" 2> >(logError) 30 | decrementNestingLevel 31 | else 32 | info "Use 'bash ./m-clear-cache -w' to get automatic cache warm up" 33 | fi 34 | 35 | info "$(regular)See details in $(bold)${vagrant_dir}/log/${current_script_name}.log$(regular). For debug output set $(bold)debug:vagrant_project$(regular) to $(bold)1$(regular) in $(bold)etc/config.yaml$(regular)" 36 | -------------------------------------------------------------------------------- /m-composer: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | cd "$(dirname "${BASH_SOURCE[0]}")" && vagrant_dir=$PWD 6 | 7 | source "${vagrant_dir}/scripts/output_functions.sh" 8 | resetNestingLevel 9 | current_script_name=`basename "$0"` 10 | initLogFile ${current_script_name} 11 | 12 | debug_vagrant_project="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "debug_vagrant_project")" 13 | if [[ ${debug_vagrant_project} -eq 1 ]]; then 14 | set -x 15 | fi 16 | 17 | bash "${vagrant_dir}/scripts/host/m_composer.sh" "$@" 2> >(logError) 18 | 19 | info "$(regular)See details in $(bold)${vagrant_dir}/log/${current_script_name}.log$(regular). For debug output set $(bold)debug:vagrant_project$(regular) to $(bold)1$(regular) in $(bold)etc/config.yaml$(regular)" 20 | -------------------------------------------------------------------------------- /m-reinstall: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | cd "$(dirname "${BASH_SOURCE[0]}")" && vagrant_dir=$PWD 6 | 7 | source "${vagrant_dir}/scripts/output_functions.sh" 8 | resetNestingLevel 9 | current_script_name=`basename "$0"` 10 | initLogFile ${current_script_name} 11 | 12 | debug_vagrant_project="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "debug_vagrant_project")" 13 | if [[ ${debug_vagrant_project} -eq 1 ]]; then 14 | set -x 15 | fi 16 | 17 | bash "${vagrant_dir}/scripts/host/m_reinstall.sh" "$@" 2> >(logError) 18 | 19 | info "$(regular)See details in $(bold)${vagrant_dir}/log/${current_script_name}.log$(regular). For debug output set $(bold)debug:vagrant_project$(regular) to $(bold)1$(regular) in $(bold)etc/config.yaml$(regular)" 20 | -------------------------------------------------------------------------------- /m-search-engine: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | cd "$(dirname "${BASH_SOURCE[0]}")" && vagrant_dir=$PWD 6 | 7 | source "${vagrant_dir}/scripts/output_functions.sh" 8 | resetNestingLevel 9 | current_script_name=`basename "$0"` 10 | initLogFile ${current_script_name} 11 | 12 | debug_vagrant_project="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "debug_vagrant_project")" 13 | if [[ ${debug_vagrant_project} -eq 1 ]]; then 14 | set -x 15 | fi 16 | 17 | cd "${vagrant_dir}" 18 | vagrant ssh -c "bash /vagrant/scripts/guest/m-search-engine ${@}" 2> >(logError) 19 | 20 | info "$(regular)See details in $(bold)${vagrant_dir}/log/${current_script_name}.log$(regular). For debug output set $(bold)debug:vagrant_project$(regular) to $(bold)1$(regular) in $(bold)etc/config.yaml$(regular)" 21 | -------------------------------------------------------------------------------- /m-switch-to-ce: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | cd "$(dirname "${BASH_SOURCE[0]}")" && vagrant_dir=$PWD 6 | 7 | source "${vagrant_dir}/scripts/output_functions.sh" 8 | resetNestingLevel 9 | current_script_name=`basename "$0"` 10 | initLogFile ${current_script_name} 11 | 12 | debug_vagrant_project="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "debug_vagrant_project")" 13 | if [[ ${debug_vagrant_project} -eq 1 ]]; then 14 | set -x 15 | fi 16 | 17 | bash "${vagrant_dir}/scripts/host/m_switch_to_ce.sh" "$@" 2> >(logError) 18 | 19 | info "$(regular)See details in $(bold)${vagrant_dir}/log/${current_script_name}.log$(regular). For debug output set $(bold)debug:vagrant_project$(regular) to $(bold)1$(regular) in $(bold)etc/config.yaml$(regular)" 20 | -------------------------------------------------------------------------------- /m-switch-to-ee: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | cd "$(dirname "${BASH_SOURCE[0]}")" && vagrant_dir=$PWD 6 | 7 | source "${vagrant_dir}/scripts/output_functions.sh" 8 | resetNestingLevel 9 | current_script_name=`basename "$0"` 10 | initLogFile ${current_script_name} 11 | 12 | debug_vagrant_project="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "debug_vagrant_project")" 13 | if [[ ${debug_vagrant_project} -eq 1 ]]; then 14 | set -x 15 | fi 16 | 17 | bash "${vagrant_dir}/scripts/host/m_switch_to_ee.sh" "$@" 2> >(logError) 18 | 19 | info "$(regular)See details in $(bold)${vagrant_dir}/log/${current_script_name}.log$(regular). For debug output set $(bold)debug:vagrant_project$(regular) to $(bold)1$(regular) in $(bold)etc/config.yaml$(regular)" 20 | -------------------------------------------------------------------------------- /m-varnish: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | cd "$(dirname "${BASH_SOURCE[0]}")" && vagrant_dir=$PWD 6 | 7 | source "${vagrant_dir}/scripts/output_functions.sh" 8 | resetNestingLevel 9 | current_script_name=`basename "$0"` 10 | initLogFile ${current_script_name} 11 | 12 | debug_vagrant_project="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "debug_vagrant_project")" 13 | if [[ ${debug_vagrant_project} -eq 1 ]]; then 14 | set -x 15 | fi 16 | 17 | cd "${vagrant_dir}" 18 | vagrant ssh -c "bash /vagrant/scripts/guest/m-varnish ${@}" 2> >(logError) 19 | 20 | info "$(regular)See details in $(bold)${vagrant_dir}/log/${current_script_name}.log$(regular). For debug output set $(bold)debug:vagrant_project$(regular) to $(bold)1$(regular) in $(bold)etc/config.yaml$(regular)" 21 | -------------------------------------------------------------------------------- /scripts/colors.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # CLI color functions 4 | function red() 5 | { 6 | printf "\e[31m" 7 | } 8 | 9 | function bold() 10 | { 11 | printf "\e[1m" 12 | } 13 | 14 | function green() 15 | { 16 | printf "\e[32m" 17 | } 18 | 19 | function yellow() 20 | { 21 | printf "\e[33m" 22 | } 23 | 24 | function blue() 25 | { 26 | printf "\e[34m" 27 | } 28 | 29 | function grey() 30 | { 31 | printf "\e[37m" 32 | } 33 | 34 | function regular() 35 | { 36 | printf "\e[m" 37 | } 38 | -------------------------------------------------------------------------------- /scripts/get_config_value.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | parse_yaml() { 4 | # src: https://gist.github.com/pkuczynski/8665367 5 | local prefix=$2 6 | local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs="$(echo @|tr @ '\034')" 7 | sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \ 8 | -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" "$1" | 9 | awk -F$fs '{ 10 | indent = length($1)/2; 11 | vname[indent] = $2; 12 | for (i in vname) {if (i > indent) {delete vname[i]}} 13 | if (length($3) > 0) { 14 | vn=""; for (i=0; i >(logError) > >(log) 44 | else 45 | status "Using file system backend for caching" 46 | fi 47 | 48 | decrementNestingLevel 49 | -------------------------------------------------------------------------------- /scripts/guest/configure_debugging: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | vagrant_dir="/vagrant" 4 | 5 | source "${vagrant_dir}/scripts/output_functions.sh" 6 | 7 | debug_magento_storefront="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "debug_magento_storefront")" 8 | if [[ ${debug_magento_storefront} == 1 ]]; then 9 | status "Enabling Magento storefront debugging (as specified in etc/config.yaml)" 10 | incrementNestingLevel 11 | update_magento_config 'dev/debug/template_hints_storefront' '1' 12 | update_magento_config 'dev/debug/template_hints_blocks' '1' 13 | decrementNestingLevel 14 | else 15 | update_magento_config 'dev/debug/template_hints_storefront' '0' 2> >(logError) > >(log) 16 | update_magento_config 'dev/debug/template_hints_blocks' '0' 2> >(logError) > >(log) 17 | fi 18 | 19 | debug_magento_admin="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "debug_magento_admin")" 20 | if [[ ${debug_magento_admin} == 1 ]]; then 21 | status "Enabling Magento admin debugging (as specified in etc/config.yaml)" 22 | incrementNestingLevel 23 | update_magento_config 'dev/debug/template_hints_admin' '1' 24 | decrementNestingLevel 25 | else 26 | update_magento_config 'dev/debug/template_hints_admin' '0' 2> >(logError) > >(log) 27 | fi 28 | 29 | # Switch to desired Magento mode 30 | env_php_content="$(cat "${MAGENTO_ROOT}/app/etc/env.php")" 31 | magento_mode="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "magento_mode")" 32 | status "Checking if Magento mode should be changed to '${magento_mode}' (as specified in etc/config.yaml)" 33 | mage_mode_pattern="'MAGE_MODE' => '${magento_mode}" 34 | if [[ ! ${env_php_content} =~ ${mage_mode_pattern} ]]; then 35 | status "Enabling Magento '${magento_mode}' mode" 36 | php "${MAGENTO_ROOT}/bin/magento" deploy:mode:set ${magento_mode} 2> >(logError) > >(log) 37 | fi 38 | -------------------------------------------------------------------------------- /scripts/guest/configure_search_engine: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Init environment variables 4 | vagrant_dir="/vagrant" 5 | 6 | source "${vagrant_dir}/scripts/output_functions.sh" 7 | 8 | status "Configuring search engine according to config.yaml" 9 | incrementNestingLevel 10 | 11 | if [[ -z "$(grep "search_engine:" /vagrant/etc/config.yaml)" ]]; then 12 | sed -i '/environment:/a \ \ search_engine: "mysql"' /vagrant/etc/config.yaml 13 | fi 14 | 15 | if [[ -f "${MAGENTO_ROOT}/LICENSE_EE.txt" ]]; then 16 | search_engine="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "environment_search_engine")" 17 | if [[ ${search_engine} == "elasticsearch" ]]; then 18 | status "Configuring ElasticSearch search engine" 19 | update_magento_config 'catalog/search/engine' 'elasticsearch' 20 | update_magento_config 'catalog/search/elasticsearch_server_hostname' 'localhost' 21 | update_magento_config 'catalog/search/elasticsearch_server_port' '9200' 22 | update_magento_config 'catalog/search/elasticsearch_index_prefix' 'magento2' 23 | update_magento_config 'catalog/search/elasticsearch_enable_auth' '0' 24 | update_magento_config 'catalog/search/elasticsearch_server_timeout' '15' 25 | elif [[ ${search_engine} == "mysql" ]]; then 26 | status "Configuring MySQL search engine" 27 | update_magento_config 'catalog/search/engine' 'mysql' 28 | fi 29 | 30 | bash m-clear-cache 31 | 32 | status "Rebuilding catalog search index" 33 | php "${MAGENTO_ROOT}/bin/magento" indexer:reindex catalogsearch_fulltext 2> >(logError) > >(log) 34 | else 35 | status "Search engine configuration was not changed (custom search engine is not available in Magento CE)." 36 | fi 37 | 38 | decrementNestingLevel 39 | -------------------------------------------------------------------------------- /scripts/guest/configure_varnish: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | vagrant_dir="/vagrant" 4 | 5 | source "${vagrant_dir}/scripts/output_functions.sh" 6 | 7 | status "Configuring Varnish FPC according to config.yaml" 8 | incrementNestingLevel 9 | 10 | # Get args 11 | while getopts 'f' flag; do 12 | case "${flag}" in 13 | f) force_restart_services=1 ;; 14 | *) error "Unexpected option" && decrementNestingLevel && exit 1;; 15 | esac 16 | done 17 | 18 | if [[ -z "$(grep "use_varnish:" /vagrant/etc/config.yaml)" ]]; then 19 | sed -i '/environment:/a \ \ use_varnish: 0' /vagrant/etc/config.yaml 20 | fi 21 | 22 | # Configure Varnish if enabled in config 23 | restart_services=0 24 | use_varnish="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "environment_use_varnish")" 25 | if [[ $use_varnish == 1 ]]; then 26 | status "Configuring apache files to be ready for varnish" 27 | if [[ -z "$(grep "VirtualHost\s\*:8080" /etc/apache2/sites-enabled/magento2.conf)" ]]; then 28 | sudo sed -ie "s//" /etc/apache2/sites-enabled/magento2.conf 29 | restart_services=1 30 | fi 31 | if [[ -z "$(grep "VirtualHost\s\*:8080" /etc/apache2/sites-available/magento2.conf)" ]]; then 32 | sudo sed -ie "s//" /etc/apache2/sites-available/magento2.conf 33 | restart_services=1 34 | fi 35 | if [[ -z "$(grep "Listen\s8080" /etc/apache2/ports.conf)" ]]; then 36 | sudo sed -ie "s/Listen 80/Listen 8080/" /etc/apache2/ports.conf 37 | restart_services=1 38 | fi 39 | 40 | status "Updating Magento database to use varnish FPC" 41 | mysql -D magento -e "INSERT INTO core_config_data 42 | ( scope, scope_id, path, value ) VALUES 43 | ( 'default', '0', 'system/full_page_cache/caching_application', '2' ) 44 | ON DUPLICATE KEY UPDATE value = 2 45 | ;" 46 | else 47 | status "Configuring apache files to run without varnish" 48 | if [[ -z "$(grep "VirtualHost\s\*:80\b" /etc/apache2/sites-enabled/magento2.conf)" ]]; then 49 | sudo sed -ie "s//" /etc/apache2/sites-enabled/magento2.conf 50 | restart_services=1 51 | fi 52 | if [[ -z "$(grep "VirtualHost\s\*:80\b" /etc/apache2/sites-available/magento2.conf)" ]]; then 53 | sudo sed -ie "s//" /etc/apache2/sites-available/magento2.conf 54 | restart_services=1 55 | fi 56 | if [[ -z "$(grep "Listen\s80\b" /etc/apache2/ports.conf)" ]]; then 57 | sudo sed -ie "s/Listen 8080/Listen 80/" /etc/apache2/ports.conf 58 | restart_services=1 59 | fi 60 | 61 | status "Updating Magento database to not use varnish FPC" 62 | mysql -D magento -e "INSERT INTO core_config_data 63 | ( scope, scope_id, path, value ) VALUES 64 | ( 'default', '0', 'system/full_page_cache/caching_application', '1' ) 65 | ON DUPLICATE KEY UPDATE value = 1 66 | ;" 67 | fi 68 | 69 | # Check if need restart services 70 | if [[ $force_restart_services == 1 ]]; then 71 | restart_services=1 72 | fi 73 | if [[ $restart_services == 1 ]]; then 74 | status "Restarting Apache and Varnish" 75 | if [[ "$(ps -ax | pgrep varnish)" ]]; then 76 | sudo pkill varnishd 77 | fi 78 | sudo service apache2 restart 2> >(logError) > >(log) 79 | if [[ $use_varnish == 1 ]]; then 80 | sudo varnishd -f /etc/varnish/default.vcl 81 | fi 82 | bash m-clear-cache 83 | fi 84 | 85 | decrementNestingLevel 86 | -------------------------------------------------------------------------------- /scripts/guest/generate_basic_data: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | vagrant_dir="/vagrant" 4 | 5 | source "${vagrant_dir}/scripts/output_functions.sh" 6 | 7 | host_name="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "magento_host_name")" 8 | 9 | status "Generating sample data" 10 | 11 | incrementNestingLevel 12 | 13 | adminToken=$(curl -sb -X POST "http://${host_name}/rest/V1/integration/admin/token" \ 14 | -H "Content-Type:application/json" \ 15 | -d '{"username":"admin", "password":"123123q"}') 16 | adminToken=$(echo ${adminToken} | sed -e 's/"//g') 17 | 18 | category_creation_response=$(curl -sb -X POST "http://${host_name}/rest/V1/categories" \ 19 | -H "Content-Type: application/json" \ 20 | -H "Authorization: Bearer ${adminToken}" \ 21 | -d '{ 22 | "category": { 23 | "parentId": 2, 24 | "name": "Test Category", 25 | "isActive": true, 26 | "includeInMenu": true 27 | } 28 | }') 29 | 30 | pattern='\{\"id\":([0-9]+),' 31 | if [[ "${category_creation_response}" =~ ${pattern} ]]; then 32 | category_id=${BASH_REMATCH[1]} 33 | fi 34 | 35 | attribute_creation_response=$(curl -sb -X POST "http://${host_name}/rest/V1/products/attributes/color/options" \ 36 | -H "Content-Type: application/json" \ 37 | -H "Authorization: Bearer ${adminToken}" \ 38 | -d '{ 39 | "option": { 40 | "label": "red" 41 | } 42 | }') 43 | 44 | attribute_creation_response=$(curl -sb -X POST "http://${host_name}/rest/V1/products/attributes/color/options" \ 45 | -H "Content-Type: application/json" \ 46 | -H "Authorization: Bearer ${adminToken}" \ 47 | -d '{ 48 | "option": { 49 | "label": "blue" 50 | } 51 | }') 52 | 53 | attribute_creation_response=$(curl -sb -X POST "http://${host_name}/rest/V1/products/attributes/color/options" \ 54 | -H "Content-Type: application/json" \ 55 | -H "Authorization: Bearer ${adminToken}" \ 56 | -d '{ 57 | "option": { 58 | "label": "green" 59 | } 60 | }') 61 | 62 | attribute_set_add_response=$(curl -sb -X POST "http://${host_name}/rest/V1/products/attribute-sets/attributes" \ 63 | -H "Content-Type: application/json" \ 64 | -H "Authorization: Bearer ${adminToken}" \ 65 | -d '{ 66 | "attributeSetId": 4, 67 | "attributeGroupId": 7, 68 | "attributeCode": "color", 69 | "sortOrder": 0 70 | }') 71 | 72 | product_creation_response=$(curl -sb -X POST "http://${host_name}/rest/V1/products" \ 73 | -H "Content-Type: application/json" \ 74 | -H "Authorization: Bearer ${adminToken}" \ 75 | -d '{ 76 | "product": { 77 | "sku": "testSimpleProduct", 78 | "name": "Test Simple Product", 79 | "attribute_set_id": 4, 80 | "price": 22, 81 | "weight": 1, 82 | "status": 1, 83 | "visibility": 4, 84 | "type_id": "simple", 85 | "extension_attributes": { 86 | "stock_item": { 87 | "qty": 12345, 88 | "is_in_stock": true 89 | } 90 | }, 91 | "custom_attributes": [ 92 | { 93 | "attribute_code": "category_ids", 94 | "value": [ 95 | "'"${category_id}"'" 96 | ] 97 | } 98 | ] 99 | } 100 | }') 101 | 102 | product_creation_response2=$(curl -sb -X POST "http://${host_name}/rest/V1/products" \ 103 | -H "Content-Type: application/json" \ 104 | -H "Authorization: Bearer ${adminToken}" \ 105 | -d '{ 106 | "product": { 107 | "sku": "testSimpleProduct2", 108 | "name": "Test Simple Product 2", 109 | "attribute_set_id": 4, 110 | "price": 32, 111 | "weight": 1, 112 | "status": 1, 113 | "visibility": 4, 114 | "type_id": "simple", 115 | "extension_attributes": { 116 | "stock_item": { 117 | "qty": 12345, 118 | "is_in_stock": true 119 | } 120 | }, 121 | "custom_attributes": [ 122 | { 123 | "attribute_code": "category_ids", 124 | "value": [ 125 | "'"${category_id}"'" 126 | ] 127 | } 128 | ] 129 | } 130 | }') 131 | 132 | product_creation_response_child1=$(curl -sb -X POST "http://${host_name}/rest/V1/products" \ 133 | -H "Content-Type: application/json" \ 134 | -H "Authorization: Bearer ${adminToken}" \ 135 | -d '{ 136 | "product": { 137 | "sku": "testConfigProduct-red", 138 | "name": "Test Red Configurable Product", 139 | "attribute_set_id": 4, 140 | "price": 10, 141 | "weight": 1, 142 | "status": 1, 143 | "visibility": 1, 144 | "type_id": "simple", 145 | "extension_attributes": { 146 | "stock_item": { 147 | "qty": 1000, 148 | "is_in_stock": true 149 | } 150 | }, 151 | "custom_attributes": [ 152 | { 153 | "attribute_code": "category_ids", 154 | "value": [ 155 | "'"${category_id}"'" 156 | ] 157 | }, 158 | { 159 | "attribute_code": "color", 160 | "value": "4" 161 | } 162 | ] 163 | } 164 | }') 165 | 166 | product_creation_response_child2=$(curl -sb -X POST "http://${host_name}/rest/V1/products" \ 167 | -H "Content-Type: application/json" \ 168 | -H "Authorization: Bearer ${adminToken}" \ 169 | -d '{ 170 | "product": { 171 | "sku": "testConfigProduct-blue", 172 | "name": "Test Blue Configurable Product", 173 | "attribute_set_id": 4, 174 | "price": 10, 175 | "weight": 1, 176 | "status": 1, 177 | "visibility": 1, 178 | "type_id": "simple", 179 | "extension_attributes": { 180 | "stock_item": { 181 | "qty": 1000, 182 | "is_in_stock": true 183 | } 184 | }, 185 | "custom_attributes": [ 186 | { 187 | "attribute_code": "category_ids", 188 | "value": [ 189 | "'"${category_id}"'" 190 | ] 191 | }, 192 | { 193 | "attribute_code": "color", 194 | "value": "5" 195 | } 196 | ] 197 | } 198 | }') 199 | 200 | product_creation_response_child3=$(curl -sb -X POST "http://${host_name}/rest/V1/products" \ 201 | -H "Content-Type: application/json" \ 202 | -H "Authorization: Bearer ${adminToken}" \ 203 | -d '{ 204 | "product": { 205 | "sku": "testConfigProduct-green", 206 | "name": "Test Green Configurable Product", 207 | "attribute_set_id": 4, 208 | "price": 10, 209 | "weight": 1, 210 | "status": 1, 211 | "visibility": 1, 212 | "type_id": "simple", 213 | "extension_attributes": { 214 | "stock_item": { 215 | "qty": 1000, 216 | "is_in_stock": true 217 | } 218 | }, 219 | "custom_attributes": [ 220 | { 221 | "attribute_code": "category_ids", 222 | "value": [ 223 | "'"${category_id}"'" 224 | ] 225 | }, 226 | { 227 | "attribute_code": "color", 228 | "value": "6" 229 | } 230 | ] 231 | } 232 | }') 233 | 234 | config_product_creation_response=$(curl -sb -X POST "http://${host_name}/rest/V1/products" \ 235 | -H "Content-Type: application/json" \ 236 | -H "Authorization: Bearer ${adminToken}" \ 237 | -d '{ 238 | "product": { 239 | "sku": "testConfigProduct", 240 | "name": "Test Configurable Product", 241 | "attribute_set_id": 4, 242 | "price": 10, 243 | "weight": 1, 244 | "status": 1, 245 | "visibility": 4, 246 | "type_id": "configurable", 247 | "extension_attributes": { 248 | "stock_item": { 249 | "qty": 1000, 250 | "is_in_stock": true 251 | } 252 | }, 253 | "custom_attributes": [ 254 | { 255 | "attribute_code": "category_ids", 256 | "value": [ 257 | "'"${category_id}"'" 258 | ] 259 | } 260 | ] 261 | } 262 | }') 263 | 264 | option_creation_resp=$(curl -sb -X POST "http://${host_name}/rest/V1/configurable-products/testConfigProduct/options" \ 265 | -H "Content-Type: application/json" \ 266 | -H "Authorization: Bearer ${adminToken}" \ 267 | -d '{ 268 | "option": { 269 | "attribute_id": "93", 270 | "label": "Color", 271 | "position": 0, 272 | "values": [ 273 | { 274 | "value_index": 4 275 | }, 276 | { 277 | "value_index": 5 278 | }, 279 | { 280 | "value_index": 6 281 | } 282 | ] 283 | } 284 | }') 285 | 286 | product_creation_response_child1=$(curl -sb -X PUT "http://${host_name}/rest/V1/products" \ 287 | -H "Content-Type: application/json" \ 288 | -H "Authorization: Bearer ${adminToken}" \ 289 | -d '{ 290 | "product": { 291 | "id": 3, 292 | "sku": "testConfigProduct-red", 293 | "name": "Test Red Configurable Product", 294 | "attribute_set_id": 4, 295 | "price": 10, 296 | "status": 1, 297 | "visibility": 1, 298 | "type_id": "simple", 299 | "weight": 1, 300 | "extension_attributes": { 301 | "website_ids": [ 302 | 1 303 | ], 304 | "category_links": [ 305 | { 306 | "position": 0, 307 | "category_id": "3" 308 | } 309 | ], 310 | "stock_item": { 311 | "item_id": 3, 312 | "product_id": 3, 313 | "stock_id": 1, 314 | "qty": 1000, 315 | "is_in_stock": true, 316 | "is_qty_decimal": false, 317 | "show_default_notification_message": false, 318 | "use_config_min_qty": true, 319 | "min_qty": 0, 320 | "use_config_min_sale_qty": 1, 321 | "min_sale_qty": 1, 322 | "use_config_max_sale_qty": true, 323 | "max_sale_qty": 10000, 324 | "use_config_backorders": true, 325 | "backorders": 0, 326 | "use_config_notify_stock_qty": true, 327 | "notify_stock_qty": 1, 328 | "use_config_qty_increments": true, 329 | "qty_increments": 0, 330 | "use_config_enable_qty_inc": true, 331 | "enable_qty_increments": false, 332 | "use_config_manage_stock": true, 333 | "manage_stock": true, 334 | "low_stock_date": null, 335 | "is_decimal_divided": false, 336 | "stock_status_changed_auto": 0 337 | } 338 | }, 339 | "product_links": [], 340 | "options": [], 341 | "media_gallery_entries": [], 342 | "tier_prices": [], 343 | "custom_attributes": [ 344 | { 345 | "attribute_code": "color", 346 | "value": "4" 347 | }, 348 | { 349 | "attribute_code": "category_ids", 350 | "value": [ 351 | "3" 352 | ] 353 | }, 354 | { 355 | "attribute_code": "options_container", 356 | "value": "container2" 357 | }, 358 | { 359 | "attribute_code": "required_options", 360 | "value": "0" 361 | }, 362 | { 363 | "attribute_code": "has_options", 364 | "value": "0" 365 | }, 366 | { 367 | "attribute_code": "url_key", 368 | "value": "test-red-configurable-product" 369 | }, 370 | { 371 | "attribute_code": "tax_class_id", 372 | "value": "2" 373 | } 374 | ] 375 | } 376 | }') 377 | 378 | product_creation_response_child2=$(curl -sb -X PUT "http://${host_name}/rest/V1/products" \ 379 | -H "Content-Type: application/json" \ 380 | -H "Authorization: Bearer ${adminToken}" \ 381 | -d '{ 382 | "product": { 383 | "id": 4, 384 | "sku": "testConfigProduct-blue", 385 | "name": "Test Blue Configurable Product", 386 | "attribute_set_id": 4, 387 | "price": 10, 388 | "status": 1, 389 | "visibility": 1, 390 | "type_id": "simple", 391 | "created_at": "2017-09-12 01:50:09", 392 | "updated_at": "2017-09-12 01:50:09", 393 | "weight": 1, 394 | "extension_attributes": { 395 | "website_ids": [ 396 | 1 397 | ], 398 | "category_links": [ 399 | { 400 | "position": 0, 401 | "category_id": "3" 402 | } 403 | ], 404 | "stock_item": { 405 | "item_id": 4, 406 | "product_id": 4, 407 | "stock_id": 1, 408 | "qty": 1000, 409 | "is_in_stock": true, 410 | "is_qty_decimal": false, 411 | "show_default_notification_message": false, 412 | "use_config_min_qty": true, 413 | "min_qty": 0, 414 | "use_config_min_sale_qty": 1, 415 | "min_sale_qty": 1, 416 | "use_config_max_sale_qty": true, 417 | "max_sale_qty": 10000, 418 | "use_config_backorders": true, 419 | "backorders": 0, 420 | "use_config_notify_stock_qty": true, 421 | "notify_stock_qty": 1, 422 | "use_config_qty_increments": true, 423 | "qty_increments": 0, 424 | "use_config_enable_qty_inc": true, 425 | "enable_qty_increments": false, 426 | "use_config_manage_stock": true, 427 | "manage_stock": true, 428 | "low_stock_date": null, 429 | "is_decimal_divided": false, 430 | "stock_status_changed_auto": 0 431 | } 432 | }, 433 | "product_links": [], 434 | "options": [], 435 | "media_gallery_entries": [], 436 | "tier_prices": [], 437 | "custom_attributes": [ 438 | { 439 | "attribute_code": "category_ids", 440 | "value": [ 441 | "3" 442 | ] 443 | }, 444 | { 445 | "attribute_code": "options_container", 446 | "value": "container2" 447 | }, 448 | { 449 | "attribute_code": "required_options", 450 | "value": "0" 451 | }, 452 | { 453 | "attribute_code": "color", 454 | "value": "5" 455 | }, 456 | { 457 | "attribute_code": "has_options", 458 | "value": "0" 459 | }, 460 | { 461 | "attribute_code": "url_key", 462 | "value": "test-blue-configurable-product" 463 | }, 464 | { 465 | "attribute_code": "tax_class_id", 466 | "value": "2" 467 | } 468 | ] 469 | } 470 | }') 471 | 472 | product_creation_response_child3=$(curl -sb -X PUT "http://${host_name}/rest/V1/products" \ 473 | -H "Content-Type: application/json" \ 474 | -H "Authorization: Bearer ${adminToken}" \ 475 | -d '{ 476 | "product": { 477 | "id": 5, 478 | "sku": "testConfigProduct-green", 479 | "name": "Test Green Configurable Product", 480 | "attribute_set_id": 4, 481 | "price": 10, 482 | "status": 1, 483 | "visibility": 1, 484 | "type_id": "simple", 485 | "created_at": "2017-09-12 01:50:10", 486 | "updated_at": "2017-09-12 01:50:10", 487 | "weight": 1, 488 | "extension_attributes": { 489 | "website_ids": [ 490 | 1 491 | ], 492 | "category_links": [ 493 | { 494 | "position": 0, 495 | "category_id": "3" 496 | } 497 | ], 498 | "stock_item": { 499 | "item_id": 5, 500 | "product_id": 5, 501 | "stock_id": 1, 502 | "qty": 1000, 503 | "is_in_stock": true, 504 | "is_qty_decimal": false, 505 | "show_default_notification_message": false, 506 | "use_config_min_qty": true, 507 | "min_qty": 0, 508 | "use_config_min_sale_qty": 1, 509 | "min_sale_qty": 1, 510 | "use_config_max_sale_qty": true, 511 | "max_sale_qty": 10000, 512 | "use_config_backorders": true, 513 | "backorders": 0, 514 | "use_config_notify_stock_qty": true, 515 | "notify_stock_qty": 1, 516 | "use_config_qty_increments": true, 517 | "qty_increments": 0, 518 | "use_config_enable_qty_inc": true, 519 | "enable_qty_increments": false, 520 | "use_config_manage_stock": true, 521 | "manage_stock": true, 522 | "low_stock_date": null, 523 | "is_decimal_divided": false, 524 | "stock_status_changed_auto": 0 525 | } 526 | }, 527 | "product_links": [], 528 | "options": [], 529 | "media_gallery_entries": [], 530 | "tier_prices": [], 531 | "custom_attributes": [ 532 | { 533 | "attribute_code": "category_ids", 534 | "value": [ 535 | "3" 536 | ] 537 | }, 538 | { 539 | "attribute_code": "options_container", 540 | "value": "container2" 541 | }, 542 | { 543 | "attribute_code": "required_options", 544 | "value": "0" 545 | }, 546 | { 547 | "attribute_code": "color", 548 | "value": "6" 549 | }, 550 | { 551 | "attribute_code": "has_options", 552 | "value": "0" 553 | }, 554 | { 555 | "attribute_code": "url_key", 556 | "value": "test-green-configurable-product" 557 | }, 558 | { 559 | "attribute_code": "tax_class_id", 560 | "value": "2" 561 | } 562 | ] 563 | } 564 | }') 565 | 566 | child_create_response1=$(curl -sb -X POST "http://${host_name}/rest/V1/configurable-products/testConfigProduct/child" \ 567 | -H "Content-Type: application/json" \ 568 | -H "Authorization: Bearer ${adminToken}" \ 569 | -d '{"childSku": "testConfigProduct-red"}') 570 | child_create_response2=$(curl -sb -X POST "http://${host_name}/rest/V1/configurable-products/testConfigProduct/child" \ 571 | -H "Content-Type: application/json" \ 572 | -H "Authorization: Bearer ${adminToken}" \ 573 | -d '{"childSku": "testConfigProduct-blue"}') 574 | child_create_response3=$(curl -sb -X POST "http://${host_name}/rest/V1/configurable-products/testConfigProduct/child" \ 575 | -H "Content-Type: application/json" \ 576 | -H "Authorization: Bearer ${adminToken}" \ 577 | -d '{"childSku": "testConfigProduct-green"}') 578 | 579 | customer_creation_response=$(curl -sb -X POST "http://${host_name}/rest/V1/customers" \ 580 | -H "Content-Type: application/json" \ 581 | -H "Authorization: Bearer ${adminToken}" \ 582 | -d '{ 583 | "customer": { 584 | "group_id":1, 585 | "email":"customer@example.com", 586 | "firstname":"John", 587 | "lastname":"Doe", 588 | "store_id":1, 589 | "addresses":[ 590 | { 591 | "region": { 592 | "region_code": "TX", 593 | "region": "Texas", 594 | "region_id": 57 595 | }, 596 | "region_id": 57, 597 | "country_id": "US", 598 | "street": [ 599 | "7700 Parmer Lane" 600 | ], 601 | "telephone": "5555555555", 602 | "postcode": "78729", 603 | "city": "Austin", 604 | "firstname": "John", 605 | "lastname": "Doe", 606 | "default_shipping": true, 607 | "default_billing": true 608 | } 609 | ], 610 | "disable_auto_group_change": 0 611 | }, 612 | "password": "123123qQ" 613 | }') 614 | 615 | decrementNestingLevel 616 | -------------------------------------------------------------------------------- /scripts/guest/link_configs: -------------------------------------------------------------------------------- 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 | vagrant_dir="/vagrant" 20 | 21 | source "${vagrant_dir}/scripts/output_functions.sh" 22 | 23 | # Below configuration is required to allow managing mysql as a service 24 | if ! cat /etc/apparmor.d/local/usr.sbin.mysqld | grep -q '/vagrant/etc/guest' ; then 25 | echo " 26 | /vagrant/etc/guest/mysql/*.pem r, 27 | /vagrant/etc/guest/mysql/conf.d/ r, 28 | /vagrant/etc/guest/mysql/conf.d/* r, 29 | /vagrant/etc/guest/mysql/*.cnf r," >> /etc/apparmor.d/local/usr.sbin.mysqld 30 | fi 31 | 32 | status "Making guest configs visible and editable in the host IDE" 33 | incrementNestingLevel 34 | 35 | # Configs located under /etc/* 36 | config_dir="/etc" 37 | # See unlink_configs script 38 | configs=( apache2 php mysql varnish rabbitmq ) 39 | process_configs ${config_dir} ${configs} 40 | 41 | decrementNestingLevel 42 | -------------------------------------------------------------------------------- /scripts/guest/log_email: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | email_log_dir=$1 4 | if [[ ! -d ${email_log_dir} ]]; then 5 | mkdir -p "${email_log_dir}" 6 | fi 7 | 8 | # Construct email file path 9 | current_time="$( date +"%Y-%m-%d_%H-%M-%S" )" 10 | # Add random suffix to file name just in case there several emails sent in one second 11 | random_suffix="$(( RANDOM % 100 ))" 12 | email_file_path="${email_log_dir}/${current_time}_${random_suffix}" 13 | 14 | raw_email_output="$(cat)" 15 | 16 | # Add email topic to file name 17 | pattern="Subject: (.*)\sX-PHP-Originating-Script:" 18 | if [[ "${raw_email_output}" =~ ${pattern} ]]; then 19 | email_topic=${BASH_REMATCH[1]} 20 | email_file_path="${email_file_path}_${email_topic}" 21 | fi 22 | email_file_path="${email_file_path}.html" 23 | 24 | # Output content 25 | echo ${raw_email_output} > "${email_file_path}" 26 | 27 | # Process raw content of an email to make it a valid HTML 28 | sed -i "s|.*<\!DOCTYPE|<\!DOCTYPE|g" "${email_file_path}" 29 | sed -i "s|=3D|=|g" "${email_file_path}" 30 | sed -i "s|=0A||g" "${email_file_path}" 31 | sed -i "s|= ||g" "${email_file_path}" -------------------------------------------------------------------------------- /scripts/guest/m-clear-cache: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | vagrant_dir="/vagrant" 4 | 5 | source "${vagrant_dir}/scripts/output_functions.sh" 6 | 7 | if [[ ${SKIP_CACHE_CLEAN} -eq 1 ]] ; then 8 | exit 0 9 | fi 10 | 11 | status "Clearing Magento cache" 12 | incrementNestingLevel 13 | 14 | status "Clearing directories containing temporary files" 15 | 16 | mage_mode=$(bash "${vagrant_dir}/scripts/get_config_value.sh" "magento_mode") 17 | 18 | rm -f "${MAGENTO_ROOT}/app/etc/paths.php" 19 | if [[ -d "${MAGENTO_ROOT}/var" ]]; then 20 | # clear var 21 | cd "${MAGENTO_ROOT}" 22 | mv var/.htaccess var_htaccess.back 23 | if [[ -d "${MAGENTO_ROOT}/var/generation" ]] && [[ ${mage_mode} == "production" ]]; then 24 | # for Magento v2.0.x and v2.1.x 25 | mv var/generation var_generation.back 26 | fi 27 | rm -rf var/* var/.[^.]* 28 | if [[ -f var_htaccess.back ]]; then 29 | mv var_htaccess.back var/.htaccess 30 | fi 31 | if [[ -d "${MAGENTO_ROOT}/var_generation.back" ]] && [[ ${mage_mode} == "production" ]]; then 32 | mv var_generation.back var/generation 33 | fi 34 | fi 35 | 36 | if [[ -d "${MAGENTO_ROOT}/generated" ]] && [[ ${mage_mode} != "production" ]]; then 37 | # for Magento v2.2.0 and greater 38 | cd "${MAGENTO_ROOT}" 39 | rm -rf generated/* 40 | fi 41 | 42 | if [[ -d "${MAGENTO_ROOT}/pub" ]] && [[ ${mage_mode} != "production" ]]; then 43 | # clear pub/statics 44 | cd "${MAGENTO_ROOT}/pub" && mv static/.htaccess static_htaccess.back && rm -rf static && mkdir static 45 | if [[ -f static_htaccess.back ]]; then 46 | mv static_htaccess.back static/.htaccess 47 | fi 48 | fi 49 | 50 | if [[ -d "${MAGENTO_ROOT}/dev" ]]; then 51 | # clear integration tests tmp 52 | cd "${MAGENTO_ROOT}/dev/tests/integration" && mv tmp/.gitignore tmp_gitignore.back && rm -rf tmp && mkdir tmp 53 | if [[ -f tmp_gitignore.back ]]; then 54 | mv tmp_gitignore.back tmp/.gitignore 55 | fi 56 | # clear unit tests tmp 57 | cd "${MAGENTO_ROOT}/dev/tests/unit" && mv tmp/.gitignore tmp_gitignore.back && rm -rf tmp && mkdir tmp 58 | if [[ -f tmp_gitignore.back ]]; then 59 | mv tmp_gitignore.back tmp/.gitignore 60 | fi 61 | fi 62 | 63 | if [[ -f "${MAGENTO_ROOT}/app/etc/env.php" ]]; then 64 | 65 | bash configure_debugging 66 | 67 | # bash configure_cache_backend 68 | 69 | status "Flushing cache using 'bin/magento cache:flush'" 70 | php "${MAGENTO_ROOT}/bin/magento" cache:flush 2> >(logError) > >(log) 71 | fi 72 | 73 | decrementNestingLevel 74 | -------------------------------------------------------------------------------- /scripts/guest/m-reinstall: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | vagrant_dir="/vagrant" 4 | 5 | source "${vagrant_dir}/scripts/output_functions.sh" 6 | 7 | get_config_value="/vagrant/scripts/get_config_value.sh" 8 | magento_host_name="$(bash ${get_config_value} "magento_host_name")" 9 | use_nfs="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "guest_use_nfs")" 10 | is_windows_host=${IS_WINDOWS_HOST} 11 | generate_basic_data="$(bash ${get_config_value} "magento_generate_basic_data")" 12 | 13 | declare -A setupOptions 14 | setupOptions[admin_frontname]="$(bash ${get_config_value} "magento_admin_frontname")" 15 | setupOptions[language]="$(bash ${get_config_value} "magento_language")" 16 | setupOptions[timezone]="$(bash ${get_config_value} "magento_timezone")" 17 | setupOptions[currency]="$(bash ${get_config_value} "magento_currency")" 18 | setupOptions[admin_user]="$(bash ${get_config_value} "magento_admin_user")" 19 | setupOptions[admin_password]="$(bash ${get_config_value} "magento_admin_password")" 20 | setupOptions[db_host]='localhost' 21 | setupOptions[db_name]='magento' 22 | setupOptions[db_user]='root' 23 | setupOptions[base_url]="http://${magento_host_name}/" 24 | setupOptions[admin_lastname]='Admin' 25 | setupOptions[admin_firstname]='Admin' 26 | setupOptions[admin_email]='admin@example.com' 27 | setupOptions[amqp_host]='localhost' 28 | setupOptions[amqp_port]='5672' 29 | setupOptions[amqp_user]='guest' 30 | setupOptions[amqp_password]='guest' 31 | setupOptions[amqp_virtualhost]='/' 32 | 33 | if [[ ${is_windows_host} == 1 ]] || [[ ${use_nfs} == 0 ]]; then 34 | sudo chown -R vagrant:vagrant ${MAGENTO_ROOT} 35 | fi 36 | 37 | status "Killing MQ processes" 38 | pkill -f queue 39 | 40 | status "Installing/re-installing Magento" 41 | incrementNestingLevel 42 | 43 | cd ${MAGENTO_ROOT} 44 | 45 | status "Removing Magento configuration files (env.php and config.php)" 46 | rm -f "${MAGENTO_ROOT}/app/etc/config.php" 47 | rm -f "${MAGENTO_ROOT}/app/etc/env.php" 48 | 49 | status "Restoring stored in git config.php (if applicable)" 50 | git checkout "${MAGENTO_ROOT}/app/etc/config.php" &>/dev/null 51 | 52 | bash m-clear-cache 53 | # Cache cleaning takes 5-10 seconds and should be avoided until the end of installation to speed up the process 54 | export SKIP_CACHE_CLEAN=1 55 | 56 | db_names=("${setupOptions[db_name]}" "magento_integration_tests" ) 57 | for db_name in "${db_names[@]}"; do 58 | status "Dropping and creating '${db_name}' DB" 59 | mysql -e "drop database if exists ${db_name}; create database ${db_name};" 60 | done 61 | 62 | # Install Magento application 63 | cd ${MAGENTO_ROOT} 64 | 65 | install_cmd="./bin/magento setup:install \ 66 | --db-host=${setupOptions[db_host]} \ 67 | --db-name=${setupOptions[db_name]} \ 68 | --db-user=${setupOptions[db_user]} \ 69 | --backend-frontname=${setupOptions[admin_frontname]} \ 70 | --base-url=${setupOptions[base_url]} \ 71 | --language=${setupOptions[language]} \ 72 | --timezone=${setupOptions[timezone]} \ 73 | --currency=${setupOptions[currency]} \ 74 | --admin-lastname=${setupOptions[admin_lastname]} \ 75 | --admin-firstname=${setupOptions[admin_firstname]} \ 76 | --admin-email=${setupOptions[admin_email]} \ 77 | --admin-user=${setupOptions[admin_user]} \ 78 | --admin-password=${setupOptions[admin_password]} \ 79 | --cleanup-database \ 80 | --use-rewrites=1" 81 | 82 | # Configure Rabbit MQ 83 | if [[ -d "${MAGENTO_ROOT}/app/code/Magento/MessageQueue" ]] || [[ -d "${MAGENTO_ROOT}/vendor/magento/module-message-queue" ]]; then 84 | install_cmd="${install_cmd} \ 85 | --amqp-host=${setupOptions[amqp_host]} \ 86 | --amqp-port=${setupOptions[amqp_port]} \ 87 | --amqp-user=${setupOptions[amqp_user]} \ 88 | --amqp-virtualhost=${setupOptions[amqp_virtualhost]} \ 89 | --amqp-password=${setupOptions[amqp_password]}" 90 | fi 91 | 92 | sudo chmod +x bin/magento 93 | status "${install_cmd}" 94 | php ${install_cmd} 2> >(logError) > >(log) 95 | # Comment out the line above and uncomment the one below to debug Magento Setup script 96 | # php -d xdebug.remote_autostart=1 ${install_cmd} 2> >(logError) > >(log) 97 | 98 | if [[ $? != 0 ]]; then 99 | error "Magento installation failed." 100 | exit 1 101 | fi 102 | 103 | bash "${vagrant_dir}/scripts/guest/configure_varnish" -f 104 | 105 | status "Enabling Magento cron jobs" 106 | echo "* * * * * php ${MAGENTO_ROOT}/bin/magento cron:run & 107 | * * * * * php ${MAGENTO_ROOT}/update/cron.php & 108 | * * * * * php ${MAGENTO_ROOT}/bin/magento setup:cron:run &" | crontab -u vagrant - 109 | 110 | if [[ ${is_windows_host} == 1 ]] || [[ ${use_nfs} == 0 ]]; then 111 | status "Changing ownership of "${MAGENTO_ROOT}" to vagrant:vagrant" 112 | sudo chown -R vagrant:vagrant ${MAGENTO_ROOT} 113 | fi 114 | 115 | if [[ ${generate_basic_data} != 0 ]]; then 116 | bash generate_basic_data 117 | fi 118 | bash configure_search_engine 119 | bash change_magento_config_for_functional_tests 120 | bash update_magento_config 'admin/security/session_lifetime' '86400' 121 | 122 | export SKIP_CACHE_CLEAN=0 123 | bash m-clear-cache 124 | 125 | status "Checking if Magento frontend is accessible at '${setupOptions[base_url]}'" 126 | magento_home_page_content="$(curl -sL ${setupOptions[base_url]})" 127 | pattern="All rights reserved." 128 | if [[ ${magento_home_page_content} =~ ${pattern} ]]; then 129 | 130 | bash warm_up_cache 131 | 132 | status "Generating XSD references for PHP Storm" 133 | php bin/magento dev:urn-catalog:generate /vagrant/.idea/misc.xml 134 | sed -i "s|${MAGENTO_ROOT}|${MAGENTO_ROOT_HOST}|g" "/vagrant/.idea/misc.xml" 135 | 136 | decrementNestingLevel 137 | success "Magento reinstalled successfully" 138 | info "Magento application was deployed to $(bold)${MAGENTO_ROOT}$(regular) and installed successfully 139 | 140 | Access storefront at $(bold)${setupOptions[base_url]}$(regular) 141 | Access admin panel at $(bold)${setupOptions[base_url]}${setupOptions[admin_frontname]}/$(regular)" 142 | else 143 | error "Magento frontend is not accessible at '${setupOptions[base_url]}' after installation. Please scan output above and logs for errors" 144 | exit 1 145 | fi 146 | -------------------------------------------------------------------------------- /scripts/guest/m-search-engine: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | vagrant_dir="/vagrant" 4 | 5 | source "${vagrant_dir}/scripts/output_functions.sh" 6 | 7 | status "Configuring search engine" 8 | incrementNestingLevel 9 | 10 | if [[ $1 == "help" ]]; then 11 | status "Usage: ./m-search-engine mysql/elasticsearch" 12 | decrementNestingLevel 13 | exit 0 14 | fi 15 | 16 | 17 | # Check if user created config.yaml file 18 | if [[ ! -f /vagrant/etc/config.yaml ]]; then 19 | error "Please make sure you have create a config.yaml file copy from etc/config.yaml.dist" 20 | decrementNestingLevel 21 | exit 1 22 | fi 23 | 24 | if [[ -z "$(grep "search_engine:" /vagrant/etc/config.yaml)" ]]; then 25 | sed -i '/environment:/a \ \ search_engine: "mysql"' /vagrant/etc/config.yaml 26 | fi 27 | 28 | if [[ $1 == "mysql" ]]; then 29 | status "Enabling MySQL search engine" 30 | sed -ie 's/search_engine:.*/search_engine: "mysql"/' /vagrant/etc/config.yaml 31 | elif [[ $1 == "elasticsearch" ]]; then 32 | status "Enabling ElasticSearch search engine" 33 | sed -ie 's/search_engine:.*/search_engine: "elasticsearch"/' /vagrant/etc/config.yaml 34 | else 35 | error "Usage: ./m-search-engine mysql|elasticsearch" 36 | decrementNestingLevel 37 | exit 1 38 | fi 39 | 40 | bash configure_search_engine 41 | 42 | decrementNestingLevel 43 | -------------------------------------------------------------------------------- /scripts/guest/m-varnish: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | vagrant_dir="/vagrant" 4 | 5 | source "${vagrant_dir}/scripts/output_functions.sh" 6 | 7 | status "Configuring Varnish" 8 | incrementNestingLevel 9 | 10 | if [[ $1 == "help" ]]; then 11 | status "Usage: ./m-varnish enable/disable" 12 | decrementNestingLevel 13 | exit 0 14 | fi 15 | 16 | # Check if user created config.yaml file 17 | if [[ ! -f /vagrant/etc/config.yaml ]]; then 18 | error "Please make sure you have create a config.yaml file copy from etc/config.yaml.dist" 19 | decrementNestingLevel 20 | exit 1 21 | fi 22 | 23 | if [[ -z "$(grep "use_varnish:" /vagrant/etc/config.yaml)" ]]; then 24 | sed -i '/environment:/a \ \ use_varnish: 0' /vagrant/etc/config.yaml 25 | fi 26 | 27 | if [[ $1 == "enable" ]]; then 28 | status "Enabling Varnish" 29 | sed -ie "s/use_varnish:.*/use_varnish: 1/" /vagrant/etc/config.yaml 30 | elif [[ $1 == "disable" ]]; then 31 | status "Disabling Varnish" 32 | sed -ie "s/use_varnish:.*/use_varnish: 0/" /vagrant/etc/config.yaml 33 | else 34 | error "Usage: ./m-varnish enable|disable" 35 | decrementNestingLevel 36 | exit 1 37 | fi 38 | 39 | bash configure_varnish 40 | 41 | decrementNestingLevel 42 | -------------------------------------------------------------------------------- /scripts/guest/unlink_configs: -------------------------------------------------------------------------------- 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 [[ -L ${config_dir}/${config} ]] && [[ -e ${config_dir}/${config} ]]; then 9 | sudo rm ${config_dir}/${config} 10 | sudo mv /vagrant/etc/guest/${config} ${config_dir}/${config} 11 | elif [[ ! -e ${config_dir}/${config} ]] && [[ -e "${config_dir}/${config}.back" ]]; then 12 | sudo rm -rf ${config_dir}/${config} 13 | sudo cp -rp "${config_dir}/${config}.back" ${config_dir}/${config} 14 | fi 15 | done 16 | } 17 | 18 | vagrant_dir="/vagrant" 19 | 20 | source "${vagrant_dir}/scripts/output_functions.sh" 21 | 22 | status "Reverting configs before shutdown or reboot to allow proper services initialization on booting" 23 | incrementNestingLevel 24 | 25 | # Configs located under /etc/* 26 | config_dir="/etc" 27 | # See link_configs script 28 | configs=( apache2 php mysql varnish rabbitmq ) 29 | process_configs ${config_dir} ${configs} 30 | 31 | decrementNestingLevel 32 | -------------------------------------------------------------------------------- /scripts/guest/update_magento_config: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | vagrant_dir="/vagrant" 4 | 5 | source "${vagrant_dir}/scripts/output_functions.sh" 6 | 7 | config_path=$1 8 | config_value=$2 9 | 10 | status "Updating Magento config: ${config_path} = ${config_value}" 11 | incrementNestingLevel 12 | 13 | mysql -D magento -e "INSERT INTO core_config_data 14 | ( scope, scope_id, path, value ) VALUES 15 | ( 'default', '0', '${config_path}', '${config_value}' ) 16 | ON DUPLICATE KEY UPDATE value = '${config_value}' 17 | ;" 18 | 19 | decrementNestingLevel 20 | -------------------------------------------------------------------------------- /scripts/guest/warm_up_cache: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | cd "$(dirname "${BASH_SOURCE[0]}")/../.." && vagrant_dir=$PWD 4 | 5 | source "${vagrant_dir}/scripts/output_functions.sh" 6 | 7 | function loadByUrl() 8 | { 9 | log "Warming up ${1}" 10 | wget -q -O - "${1}" | grep -o "http://${host_name}[^\"]*" | grep -o ".*\.[A-Za-z]*$" | while read -r link ; do 11 | log "Warming up ${link}" 12 | wget -q ${link} 2> >(log) > >(log) 13 | done 14 | } 15 | 16 | admin_frontname="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "magento_admin_frontname")" 17 | host_name="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "magento_host_name")" 18 | 19 | status "Warming up Magento cache by loading frontend and admin pages" 20 | 21 | incrementNestingLevel 22 | 23 | loadByUrl "http://${host_name}" 24 | loadByUrl "http://${host_name}/${admin_frontname}" 25 | 26 | decrementNestingLevel 27 | -------------------------------------------------------------------------------- /scripts/host/.gitignore: -------------------------------------------------------------------------------- 1 | /composer.phar 2 | /magento2ce.tar -------------------------------------------------------------------------------- /scripts/host/check_mounted_directories.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | cd "$(dirname "${BASH_SOURCE[0]}")/../.." && vagrant_dir=$PWD 4 | 5 | source "${vagrant_dir}/scripts/output_functions.sh" 6 | 7 | cd "${vagrant_dir}" 8 | if [[ ! -f "${vagrant_dir}/etc/guest/mysql/my.cnf" ]]; then 9 | error "Directory '${vagrant_dir}/etc' was not mounted as expected by Vagrant. 10 | Please make sure that 'paliarush/magento2.ubuntu' Vagrant box was downloaded successfully (if not, this may help http://stackoverflow.com/questions/35519389/vagrant-cannot-find-box) 11 | And that Vagrant is able to mount VirtualBox shared folders on your environment (see https://www.vagrantup.com/docs/synced-folders/basic_usage.html ). 12 | Also remove any stale declarations from /etc/exports on the host." 13 | exit 1 14 | fi 15 | vagrant ssh -c "bash /vagrant/scripts/guest/check_mounted_directories" 2> >(logError) 16 | # Explicit exit is necessary to bypass incorrect output from vagrant in case of errors 17 | exit 0 18 | -------------------------------------------------------------------------------- /scripts/host/check_requirements.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | cd "$(dirname "${BASH_SOURCE[0]}")/../.." && vagrant_dir=$PWD 4 | 5 | source "${vagrant_dir}/scripts/output_functions.sh" 6 | 7 | status "Checking requirements" 8 | incrementNestingLevel 9 | 10 | php_executable="$(bash "${vagrant_dir}/scripts/host/get_path_to_php.sh")" 11 | 12 | if ! ${php_executable} -v 2> >(log) | grep -q 'Copyright' ; then 13 | bash "${vagrant_dir}/scripts/host/install_php.sh" 14 | fi 15 | 16 | decrementNestingLevel 17 | -------------------------------------------------------------------------------- /scripts/host/composer.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # This script allows to use credentials specified in etc/composer/auth.json without declaring them globally 4 | 5 | current_dir=${PWD} 6 | cd "$(dirname "${BASH_SOURCE[0]}")/../.." && vagrant_dir=$PWD 7 | 8 | source "${vagrant_dir}/scripts/output_functions.sh" 9 | 10 | status "Executing composer command" 11 | incrementNestingLevel 12 | 13 | composer_auth_json="${vagrant_dir}/etc/composer/auth.json" 14 | composer_dir="${vagrant_dir}/scripts/host" 15 | composer_phar="${composer_dir}/composer.phar" 16 | 17 | bash "${vagrant_dir}/scripts/host/check_requirements.sh" 18 | 19 | php_executable="$(bash "${vagrant_dir}/scripts/host/get_path_to_php.sh")" 20 | 21 | if [[ ! -f ${composer_phar} ]]; then 22 | status "Installing composer" 23 | cd "${composer_dir}" 24 | curl -sS https://getcomposer.org/installer | ${php_executable} 2> >(logError) > >(log) 25 | fi 26 | 27 | # commented out due to composer conflicts 28 | # ${php_executable} "${composer_phar}" global require "hirak/prestissimo:^0.3" 29 | 30 | cd "${current_dir}" 31 | if [[ -f ${composer_auth_json} ]]; then 32 | status "Exporting etc/auth.json to environment variable" 33 | export COMPOSER_AUTH="$(cat "${composer_auth_json}")" 34 | fi 35 | 36 | host_os="$(bash "${vagrant_dir}/scripts/host/get_host_os.sh")" 37 | if [[ $(bash "${vagrant_dir}/scripts/get_config_value.sh" "environment_composer_prefer_source") == 1 ]]; then 38 | # prefer-source is slow but guarantees that there will be no issues related to max path length on Windows 39 | status "composer --ignore-platform-reqs --prefer-source --no-interaction "$@"" 40 | "${php_executable}" "${composer_phar}" --ignore-platform-reqs --prefer-source --no-interaction "$@" 2> >(log) > >(log) 41 | else 42 | status "composer --ignore-platform-reqs --no-interaction "$@"" 43 | "${php_executable}" "${composer_phar}" --ignore-platform-reqs --no-interaction "$@" 2> >(log) > >(log) 44 | fi 45 | 46 | decrementNestingLevel 47 | -------------------------------------------------------------------------------- /scripts/host/configure_php_storm.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | cd "$(dirname "${BASH_SOURCE[0]}")/../.." && vagrant_dir=$PWD 4 | 5 | source "${vagrant_dir}/scripts/output_functions.sh" 6 | 7 | status "Configuring PhpStorm" 8 | incrementNestingLevel 9 | 10 | cd "${vagrant_dir}" 11 | ssh_port="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "guest_forwarded_ssh_port")" 12 | magento_host_name="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "magento_host_name")" 13 | 14 | cp -R "${vagrant_dir}/scripts/host/php-storm-configs/." "${vagrant_dir}/.idea/" 15 | 16 | enabled_virtual_host_config="/etc/apache2/sites-available/magento2.conf" 17 | 18 | host_os="$(bash "${vagrant_dir}/scripts/host/get_host_os.sh")" 19 | if [[ ${host_os} == "Windows" ]] || [[ $(bash "${vagrant_dir}/scripts/get_config_value.sh" "guest_use_nfs") == 0 ]]; then 20 | sed -i.back "s||/var/www/magento2ce|g" "${vagrant_dir}/.idea/deployment.xml" 21 | sed -i.back 's|| autoUpload="Always" autoUploadExternalChanges="true"|g' "${vagrant_dir}/.idea/deployment.xml" 22 | sed -i.back 's||