It is expected that Magento 2 project source code will be located and managed on the host. This is necessary to allow quick indexing of project files by IDE. All other infrastructure is deployed on the guest machine.
Current Vagrant configuration aims to solve performance issues of Magento installed on Virtual Box for development. Custom solution is implemented for Windows hosts. See explanation of the proposed solution.
Environment for Magento EE development is configured as well.
It is easy to install multiple Magento instances based on different codebases simultaneously.
Project initialization script configures complete development environment:
If you never used Vagrant before, read Vagrant Docs
Software listed below should be available in PATH (except for PHP Storm).
Git. Make sure you have SSH keys generated and associated with your github account, see how to check and how to configure if not configured.
vagrant-magento/magento2ce
.
On Windows hosts Git must be v2.7+, also make sure to set the following options to avoid issues with incorrect line separators:
git config --global core.autocrlf false
git config --global core.eol LF
git config --global diff.renamelimit 5000
PHP (any version) to allow Magento dependency management with Composer
PHP Storm is optional but recommended.
NFS server must be installed and running on *nix and OSX hosts. Is usually available, so just try to follow installation steps first.
Open terminal and change directory to the one which you want to contain Magento project. On Windows use Git Bash, which is available after Git installation
Download project with Vagrant configuration:
git clone git@github.com:paliarush/magento2-vagrant-for-developers.git vagrant-magento
etc/composer/auth.json
"github.com": "your-github-token"
to github-oauth
section for GitHub authorizationOptionally, copy etc/config.yaml.dist as etc/config.yaml
and make necessary customizations
Initialize project (this will configure environment, install Magento, configure PHPStorm project):
cd vagrant-magento
bash init_project.sh
Use vagrant-magento
directory as 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. If NFS files sync is disabled in config and on Windows hosts verify deployment configuration in PHP Storm
Configure remote PHP interpreter in PHP Storm. Go to Settings => Languages & Frameworks => PHP
, add new remote interpreter and select "Deployment configuration" as a source for connection details.
Some of default settings are available for override. These settings can be found in the file etc/config.yaml.dist. To override settings just create a copy of the file under the name 'config.yaml' and put there your custom settings. When using 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 2 or more instances are running at the same time. Upon a successful installation, you'll see the location and URL of the newly-installed Magento 2 application in console.
Web access:
http://magento2.vagrant<random_suffix>
http://magento2.vagrant<random_suffix>/admin/
admin/123123q
http://magento2.vagrant<random_suffix>:15672
, credentials guest
/guest
Codebase and DB access:
echo ${MAGENTO_ROOT}
/var/www/magento2ce
localhost
(not accessible remotely)magento
, magento_integration_tests
mysql
with no user and password (root/password
will be used by default)Codebase on host
vagrant_project_root/magento2ce
etc/config.yaml
: vagrant_project_root/magento2ce/magento2ee
Current vagrant project follows semantic versioning so feel free to pull the latest features and fixes, they will not break your project.
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
.
Note, that semantic versioning is only used for x.0
branches (not for develop
).
use_nfs
option in config.yaml to 0
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 to 1
vagrant-magento
directory as project root in PHP Storm (not vagrant-magento/magento2ce
)To save some time and get clear Magento installation, you can skip installation of software like web server or php. The following command will clear Magento DB, Magento caches and reinstall Magento instance.
Go to 'vagrant-magento' created earlier and run in command line:
bash m-reinstall
Go to 'vagrant-magento' created earlier and run in command line:
bash m-clear-cache
Assume, that EE codebase is available in vagrant_project_root/magento2ce/magento2ee
.
The following commands will link/unlink EE codebase, clear cache, update composer dependencies and reinstall Magento.
Go to 'vagrant-magento' created earlier and run in command line:
bash m-switch-to-ce
OR
bash m-switch-to-ee
Go to 'vagrant-magento' created earlier and run in command line:
bash m-composer install
OR
bash m-composer update
Go to 'vagrant-magento' created earlier and run in command line:
bash m-bin-magento <command_name>
e.g.
bash m-bin-magento list
XDebug is already configured to connect to the host machine automatically. So just:
To debug a CLI script:
PHPSTORM
as IDE keyxdebug.remote_host
value might be different for you):php -d xdebug.remote_host=192.168.10.1 -d xdebug.idekey=PHPSTORM -d xdebug.remote_connect_back=0 -d xdebug.remote_autostart=1 <path_to_cli_script>
To debug Magento Setup script, go to Magento installation script and find php ${install_cmd}
. Follow steps above for any CLI script
Answer can be found here
To install several Magento instances based on different code bases, just follow Installation steps to initialize project in another directory on the host.
Unique IP address, SSH port and domain name will be generated for each new instance if not specified manually in etc/config.yaml
It is possible to reset project environment to default state, which you usually get just after project initialization. The following command will delete vagrant box, vagrant project settings and PhpStorm project settings. After that it will initialize project from scratch. Magento 2 code base (magento2ce
directory) will stay untouched.
Go to 'vagrant-magento' created earlier and run in command line:
bash init_project.sh -f
You can reset project settings and 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
Go to 'vagrant-magento' created earlier and run in command line:
bash init_project.sh -fc
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。