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

Commit 544de35

Browse files
author
Alexander Paliarush
committed
Created vagrant configuration for Magneto 2 CE developer's environment installation
1 parent 22403ec commit 544de35

16 files changed

+418
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/.vagrant
2+
/.idea

README.md

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# Vagrant for Magento CE, optimized for Windows hosts
2+
3+
## What You get
4+
5+
The current Vagrant configuration aims to solve performance issues of Magento installed on Virtual Box, when the host is Windows.
6+
See [explanation of the proposed solution](docs/performance-issue-on-windows-hosts.md).
7+
8+
With current configuration Vagrant will:
9+
10+
1. Run Ubuntu box
11+
1. Install and configure all software necessary for Magento 2
12+
1. Install all necessary libraries
13+
1. Install the Magento 2 application
14+
15+
## Usage
16+
17+
If you never used Vagrant before, read [Vagrant Docs](https://docs.vagrantup.com/v2/)
18+
19+
### Prerequisites
20+
- [Vagrant](https://www.vagrantup.com/downloads.html) is installed and available globally in command line
21+
- [VirtualBox](https://www.virtualbox.org/wiki/Downloads)
22+
- [Composer](https://getcomposer.org/doc/00-intro.md) is installed and is available globally in command line
23+
- Make sure you have SSH keys generated and associated with your github account, see [manual](https://help.github.com/articles/generating-ssh-keys/).
24+
:information_source: You can use another way of getting codebase instead of cloning, it does not matter for successful installation.
25+
26+
### To install the whole image from scratch
27+
28+
1. Run in command line from the directory which contains your projects:
29+
30+
```
31+
git clone git@github.com:paliarush/vagrant-magento.git vagrant-magento
32+
git clone git@github.com:magento/magento2.git magento2ce
33+
cd magento2ce
34+
mkdir -p var/generation
35+
composer install --prefer-source
36+
cd ../vagrant-magento
37+
vagrant up
38+
```
39+
1. At some point you will be prompted to [set up synchronization with PHP Storm](docs/phpstorm-configuration.md)
40+
and install Magento using:
41+
42+
```
43+
vagrant provision --provision-with install_magento
44+
```
45+
46+
###To reinstall Magento
47+
To save some time and get clear Magento installation, you can skip installation of software like web server or php.
48+
The following command will clear Magento DB, Magento caches and reinstall Magento instance.
49+
50+
Go to 'vagrant-magento' created earlier and run in command line:
51+
52+
```
53+
vagrant provision --provision-with install_magento
54+
```
55+
56+
### After installation
57+
58+
Upon a successful installation, you'll see the location and URL of the newly-installed Magento 2 application:
59+
```
60+
Magento application was deployed in /var/www/magento2 and installed
61+
Access front store at http://${HOST}/
62+
Access admin panel at http://${HOST}/${backend_frontame}/
63+
```
64+
65+
`/var/www/magento2` is a path to your Magento installation on the VM.
66+
67+
### Default credentials
68+
69+
```
70+
db host: localhost (not accessible remotely)
71+
db user/password: magento/magento
72+
db name: magento
73+
74+
also available db user/password: root/password
75+
76+
Magento admin user/password: admin/123123q
77+
```
78+
79+
### Hostname
80+
81+
The hostname of the Magento application is derived from hostname of the VM defined in the `Vagrantfile`:
82+
```
83+
config.vm.hostname = "magento2.vagrant"
84+
```
85+
86+
Change this value in the `Vagrantfile` if you want to use different hostname.
87+
88+
If Vagrant can't determine hostname of the VM for some reason, it will use its IP address (also specified in `Vagrantfile`).
89+
90+
Also make sure you update your system `hosts` file with a record that links the IP address and hostname of the VM.
91+
For the following `Vagrantfile`
92+
```
93+
...
94+
config.vm.network :private_network, ip: '192.168.10.11'
95+
config.vm.hostname = "magento2.vagrant"
96+
...
97+
```
98+
Specify the following in your `hosts` file:
99+
```
100+
192.168.10.11 magento2.vagrant
101+
```
102+
103+
### GitHub Limitations
104+
105+
Be aware that you may encounter GitHub limits on the number of downloads (used by Composer to download Magento dependencies).
106+
107+
These limits may significantly slow down the installation since all of the libraries will be cloned from GitHub repositories instead of downloaded as ZIP archives. In the worst case, these limitations may even terminate the installation.
108+
109+
If you have a GitHub account, you can bypass these limitations by using an OAuth token in the Composer configuration. See [API rate limit and OAuth tokens](https://getcomposer.org/doc/articles/troubleshooting.md#api-rate-limit-and-oauth-tokens) for more information.
110+
111+
For the Vagrant configuration you may specify your token in `local.config/github.oauth.token` file after cloning the repository. The file is a basic text file and is ignored by Git, so you'll need to create it yourself. Simply write your OAuth token in this file making sure to avoid any empty spaces, and it will be read during deployment. You should see the following message in the Vagrant log:
112+
```
113+
Installing GitHub OAuth token from /vagrant/local.config/github.oauth.token
114+
```
115+
116+
## Related Repositories
117+
118+
- https://github.com/buskamuza/magento2-product-vagrant

Vagrantfile

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# -*- mode: ruby -*-
2+
# vi: set ft=ruby :
3+
4+
# All Vagrant configuration is done below. The "2" in Vagrant.configure
5+
# configures the configuration version (we support older styles for
6+
# backwards compatibility). Please don't change it unless you know what
7+
# you're doing.
8+
Vagrant.configure(2) do |config|
9+
config.vm.box = "ubuntu/trusty64"
10+
11+
config.vm.provider "virtualbox" do |vb|
12+
vb.memory = 2048
13+
end
14+
config.vm.network :private_network, ip: '192.168.10.11'
15+
config.vm.hostname = "magento2.vagrant"
16+
17+
config.vm.synced_folder '.', '/vagrant'
18+
config.vm.synced_folder '../magento2ce/var/generation', '/var/www/magento2/var/generation', owner: "www-data", group: "www-data", mount_options: ["dmode=775", "fmode=775"]
19+
config.vm.synced_folder '../magento2ce/app/etc', '/var/www/magento2/app/etc', owner: "www-data", group: "www-data", mount_options: ["dmode=775", "fmode=775"]
20+
21+
config.vm.provision "install_environment", type: "shell" do |s|
22+
s.path = "bootstrap.sh"
23+
end
24+
25+
config.vm.provision "install_magento", type: "shell" do |s|
26+
s.path = "install_magento.sh"
27+
end
28+
end

bootstrap.sh

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/usr/bin/env bash
2+
3+
set -ex
4+
5+
apt-get update
6+
7+
# Check arguments
8+
#
9+
# Default values
10+
reinstall='';
11+
with_sample_data='';
12+
deploy_static_view_files='';
13+
for var in "$@"
14+
do
15+
if [ "${var}" == "reinstall" ]; then
16+
reinstall=true;
17+
fi
18+
if [ "${var}" == "with_sample_data" ]; then
19+
with_sample_data=true;
20+
fi
21+
if [ "${var}" == "deploy_static_view_files" ]; then
22+
deploy_static_view_files=true;
23+
fi
24+
done
25+
26+
# Determine external IP address
27+
set +x
28+
IP=`ifconfig eth1 | grep inet | awk '{print $2}' | sed 's/addr://'`
29+
echo "IP address is '${IP}'"
30+
set -x
31+
32+
# Determine hostname for Magento web-site
33+
HOST=`hostname -f`
34+
if [ -z ${HOST} ]; then
35+
# Use external IP address as hostname
36+
set +x
37+
HOST=${IP}
38+
echo "Use IP address '${HOST}' as hostname"
39+
set -x
40+
fi
41+
42+
# Setup Apache
43+
apt-get install -y apache2
44+
a2enmod rewrite
45+
apache_config="/etc/apache2/sites-available/magento2.conf"
46+
cp /vagrant/magento2.vhost.conf ${apache_config}
47+
sed -i "s/<host>/${HOST}/g" ${apache_config}
48+
# Enable Magento virtual host
49+
a2ensite magento2.conf
50+
# Disable default virtual host
51+
sudo a2dissite 000-default
52+
53+
# Setup PHP
54+
apt-get install -y php5 php5-mhash php5-mcrypt php5-curl php5-cli php5-mysql php5-gd php5-intl php5-xsl curl
55+
if [ ! -f /etc/php5/apache2/conf.d/20-mcrypt.ini ]; then
56+
ln -s /etc/php5/mods-available/mcrypt.ini /etc/php5/apache2/conf.d/20-mcrypt.ini
57+
fi
58+
if [ ! -f /etc/php5/cli/conf.d/20-mcrypt.ini ]; then
59+
ln -s /etc/php5/mods-available/mcrypt.ini /etc/php5/cli/conf.d/20-mcrypt.ini
60+
fi
61+
echo "date.timezone = America/Chicago" >> /etc/php5/cli/php.ini
62+
63+
# Restart Apache
64+
service apache2 restart
65+
66+
# Setup MySQL
67+
debconf-set-selections <<< 'mysql-server mysql-server/root_password password password'
68+
debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password password'
69+
apt-get install -q -y mysql-server-5.6 mysql-client-5.6
70+
71+
# Setup Composer
72+
apt-get install -y git
73+
if [ ! -f /usr/local/bin/composer ]; then
74+
cd /tmp
75+
curl -sS https://getcomposer.org/installer | php
76+
mv composer.phar /usr/local/bin/composer
77+
fi

docs/images/automatic-upload.png

73.6 KB
Loading
154 KB
Loading
46 KB
Loading

docs/images/new-sftp-server.png

65.8 KB
Loading

docs/images/private-key-auth-type.png

86.6 KB
Loading

docs/images/projects-mapping.png

45.9 KB
Loading

docs/images/ssh-config.png

7.67 KB
Loading
121 KB
Loading
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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.

docs/phpstorm-configuration.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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/generation', '/var/www/magento2/var/generation'
11+
config.vm.synced_folder '../magento2ce/app/etc', '/var/www/magento2/app/etc'
12+
end
13+
```
14+
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.
15+
1. Go to Tools -> Deployment -> Configuration
16+
![](images/deployment-configuration.png)
17+
1. Add new SFTP server and mark it as default when added (using button in top left corner)
18+
![](images/new-sftp-server.png)
19+
1. Fill out connection settings using the information taken from vagrant ssh config
20+
- Go to the 'vagrant-magento' directory (contains your vagrant project) in console and execute 'vagrant ssh-config'
21+
![](images/ssh-config.png)
22+
- Use private key Auth type instead of password
23+
![](images/private-key-auth-type.png)
24+
1. Set up mapping between your local and remote versions of the project, for remote project use '/var/www/magento2'
25+
![](images/projects-mapping.png)
26+
1. Add remote paths excluded from synchronization by PHPStorm. You should add those paths which are specified in Vagrant config for synchronization.
27+
![](images/exclude-paths-from-mapping.png)
28+
1. Go to Tools -> Deployment -> Options... and enable automatic upload to default server and check "Upload external changes"
29+
![](images/automatic-upload.png)
30+
1. Upload Magento code base to the virtual machine from the host machine using context menu on the root of the project in PHPStorm
31+
![](images/upload-magento-codebase.png)

0 commit comments

Comments
 (0)