├── .github
└── FUNDING.yml
├── .gitignore
├── LICENSE
├── README.md
├── Vagrantfile
├── config.yaml.example
├── db-dump.sql.gz.example
├── dependency.rb
├── extra
├── 001-env-example.sh
├── 100-pre-build-example.sh
└── 120-post-build-example.sh
├── provision
├── 001-system-env.sh
├── 010-system-packages.sh
├── 020-system-services.sh
├── 100-magento-pre.sh
├── 110-magento-app.sh
└── 120-magento-post.sh
└── ssh.example
├── id_rsa
└── id_rsa.pub
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | github: [zepgram]
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /.vagrant
2 | /.idea
3 | /.DS_Store
4 | /ssh
5 | /www
6 | /vagrant-ssh
7 | /config.yaml
8 | /extra/001-env.sh
9 | /extra/100-pre-build.sh
10 | /extra/120-post-build.sh
11 | /db-dump.sql.gz
12 | /*.log
13 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 benjamin calef - zepgram
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 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Virtual Machine for Magento2
2 |
3 | [](https://app.vagrantup.com/geerlingguy/boxes/debian10)
4 | [](https://github.com/zepgram/magento2-fast-vm/blob/master/config.yaml.example)
5 | [](https://github.com/zepgram/magento2-fast-vm/blob/master/config.yaml.example)
6 | [](https://github.com/zepgram/magento2-fast-vm/releases)
7 | [](https://github.com/zepgram/magento2-fast-vm/releases)
8 | [](https://github.com/zepgram/magento2-fast-vm/blob/master/LICENSE)
9 |
10 | Supported system:
11 | 
12 | 
13 | 
14 |
15 | Supported release:
16 | [](https://github.com/magento/magento2/tree/2.1)
17 | [](https://github.com/magento/magento2/tree/2.2)
18 | [](https://github.com/magento/magento2/tree/2.3)
19 | [](https://github.com/magento/magento2/tree/2.4)
20 |
21 | 
22 |
23 | [](https://www.youracclaim.com/badges/406cc91a-0fda-4a6f-846b-19d7f8b59e0a/public_url)
24 |
25 | ## Requirements
26 |
27 | ### Virtualbox
28 | [VirtualBox](https://www.virtualbox.org/) is an open source virtualizer, an application that can run an entire operating system within its own virtual machine.
29 | Stable version >= 5.2.0
30 |
31 | 1. Download the installer for your laptop operating system using the links below.
32 | * [VirtualBox download](https://www.virtualbox.org/wiki/Downloads)
33 | 1. Run the installer, choosing all the default options.
34 | * Windows: Grant the installer access every time you receive a security prompt.
35 | * Mac: Enter your admin password.
36 | * Linux: Enter your user password if prompted.
37 | 1. Reboot your laptop if prompted to do so when installation completes.
38 | 1. Close the VirtualBox window if it pops up at the end of the install.
39 |
40 | ### Vagrant
41 | [Vagrant](https://www.vagrantup.com/) is an open source command line utility for managing reproducible developer environments.
42 | Stable version >= 2.2.0
43 |
44 | 1. Download the installer for your laptop operating system using the links below.
45 | * [Vagrant download](https://www.vagrantup.com/downloads)
46 | 1. Reboot your laptop if prompted to do so when installation completes.
47 |
48 | ## Configurations
49 |
50 | ### Related guide
51 | - Made by Onilab for Windows 10:
52 | https://onilab.com/blog/install-magento-2-on-localhost-a-windows-10-guide/
53 |
54 | ### Pre-installation
55 |
56 | ⚠ This vagrant installation is non-interactive: DO NOT USE SSH KEY WITH PASSPHRASE.
57 | If your ssh key has been created with a passphrase, please create another one.
58 |
59 | System | Steps |
60 | |---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
61 | | Windows | 1. Open UEFI BIOS and make sure virtualization is turned 'on'
2. Open powershell as administrator and run: ``Add-MpPreference -ExclusionProcess winnfsd.exe``
3. Open ``C:\Windows\System32\drivers\etc\hosts`` as administrator then add ``network_ip`` and ``magento_url``
Default values would be: ``192.168.60.0 dev.magento.com`` |
62 | | MacOs | 1. To avoid issue with guest additions, run:
``sudo apt install linux-headers-$(uname -r)`` |
63 | | Linux | 1. To install NFS properly, run:
``sudo apt install nfs-kernel-server``
64 | | Linux/MacOS | 2. Open ``/etc/hosts`` as sudo then add ``network_ip`` and ``magento_url``
Default values would be: ``192.168.60.0 dev.magento.com``
65 |
66 | ### Installation
67 |
68 | 1. Clone this project: ``git clone git@github.com:zepgram/magento2-fast-vm.git``
69 | 1. Copy/past: ``ssh.example`` rename it ``ssh`` then put your ``id_rsa`` and ``id_rsa.pub`` keys
70 | 1. Copy/past: ``config.yaml.example`` rename it ``config.yaml``
Then customize configurations according to [Yaml config overview](#yaml-config-overview)
71 | 1. If you want to import an existing database: create a compressed sql dump and name it ``db-dump.sql.gz``.
You must also fill ``crypt_key`` in config.yaml
72 | 1. To start install run: ``vagrant up`` (duration: ~20 minutes)
73 | 1. Finally, run: ``vagrant ssh`` to access guest machine
74 |
75 | ### Yaml config overview
76 | Parent Node | Name | Default Value | Allowed Value | Is optional | Description
77 | | --- |---------------| -- | --- | --- |---
78 | | vmconf | machine_name | Vagrant Magento 2 | string | no | Vagrant machine name
79 | | | network_ip | 192.168.60.0 | IP address | no | Accessible IP address /etc/hosts
80 | | | host_name | zepgram | string | no | Virtual host name
81 | | | memory | 4096 | number | no | RAM allocated
82 | | | cpus | 1 | number | no | CPU allocated
83 | | | mount | nfs | nfs / rsync / default | no | Mount strategy
84 | | | path | root | app / root | no | Mount whole directory or `app/` only
85 | | | provision | all | all / system / magento | no | Define script provision
86 | | composer | username | magentoUsernameKey | string | no | Composer auth user
87 | | | password | magentoPasswordKey | string | no | Composer auth password
88 | | git | name | John Doe | string | yes | Git user name
89 | | | email | john@doe.com | email | yes | Git user email
90 | | | host | github.com | url | yes | Git host server name
91 | | | repository | ssh://git@github.com:%.git | git repository | yes | Define repository to clone
92 | | magento | url | dev.magento.com | url | no | Magento site host name
93 | | | source | composer | composer / (master/develop..) | no | Define source installation. On git install set the branch name to clone.
94 | | | edition | community | community / enterprise | no | Magento project edition
95 | | | version | 2.4.5 | >=2.2 | no | Magento version release
96 | | | php_version | default | default / 7.x / 8.x | no | PHP version
97 | | | sample | true | true / false | no | Install sample data
98 | | | mode | developer | developer / production | no | Magento execution mode
99 | | | currency | USD | ISO 4217 | no | Default currency
100 | | | language | en_US | ISO 639-1 + ISO 3166 | no | Default language
101 | | | time_zone | America/New_York | timezone | no | Default timezone
102 | | | crypt_key | - | string | yes | Crypt key form app/etc/env.php for db-dump.sql.gz (db import)
103 | | | search_engine | opensearch | opensearch / elasticsearch | false | Search engine for catalog search
104 | | | disable_two_factor_auth | true | true / false | false | Disable 2 factor authentication for admin access
105 |
106 | ### Path
107 | * root directory: mount the entire project.
108 | * app directory: mount only app directory. Not sharing generated files between machines ensure great performance but in return, source code /vendor is missing.
109 |
110 | ### Mount options
111 |
112 | #### RSYNC
113 | Only useful on path set to ``root``.
114 | * Loss of performance is due to files generated on the fly, by excluding them you can mount the whole directory ``root`` and get performance equal to an ``app`` mount.
115 | * The ``vagrant rsync-auto`` is launched by default on vagrant up, even with that if you need to force an update you can run ``vagrant rsync``. Terminal should be kept open for rsync-auto: do not close it.
116 | * Rsync is unilateral, your host machine push files to guest but not the other way.
117 | Anyway if it's necessary, after a ``composer update`` for example, you can run ``vagrant rsync-back`` to push files from guest to host.
118 | * After first installation, you must run ``vagrant reload`` to enable file watching with rsync-auto.
119 | [See Rsync option](https://www.vagrantup.com/docs/synced-folders/rsync.html)
120 |
121 | #### NFS
122 | Recommended for ``root`` and ``app`` path.
123 | The most stable option, config has been made to ensure compliance with all OS.
124 | Less performant than rsync but files are perfectly shared between guest and host machine.
125 |
126 | [See NFS option](https://www.vagrantup.com/docs/synced-folders/nfs.html)
127 |
128 | #### DEFAULT
129 | It can be used with ``app`` path if you encountered any issue with NFS and rsync mount.
130 |
131 | [See basic usage](https://www.vagrantup.com/docs/synced-folders/basic_usage.html)
132 |
133 | ### Extra provisions
134 | You can add extra shell provisions.
135 | Those provisions will be executed on pre-defined sequences:
136 | 1. ``extra/001-env.sh`` his purpose is to provide extra environment variables or extra package, executed after script ``001-system-env.sh``
137 | 1. ``extra/100-pre-build.sh`` define your specific system configuration before installation, executed after script ``100-magento-pre.sh``
138 | 1. ``extra/120-post-build.sh`` you can execute magento command in this sequence, executed after script ``120-magento-post.sh``
139 |
140 | - To be executed you must remove the string `-example` from the filename script.
141 | - As an example of use, you can adapt data from your database import by using the script ``100-pre-build.sh``
142 |
143 | ## System usage
144 |
145 | ### Permission
146 | Magento file system owner is configured for ``vagrant`` user, it means all commands in magento project must be executed by this user.
147 | By default command line ``vagrant ssh`` will log you as vagrant user.
148 | * To re-apply magento permissions you can run ``permission`` directly in command line.
149 |
150 | ### Command line
151 | * magento (Magento CLI alias)
152 | * magento-cloud (Magento Cloud CLI)
153 | * pestle (A collection of command line scripts for code generation)
154 | * magerun (The swiss army knife for Magento developers)
155 | * permission (Re-apply permissions to project)
156 |
157 | ### Cron
158 | Enable cron:
159 | ```
160 | ./bin/magento cron:install
161 | ```
162 |
163 | Disable cron:
164 | ```
165 | ./bin/magento cron:remove
166 | ```
167 |
168 | ## Configuration
169 |
170 | ### Package & Software
171 | - php + required extensions
172 | - curl
173 | - git
174 | - gitflow
175 | - vim
176 | - composer
177 | - nginx
178 | - php-fpm
179 | - percona
180 | - redis-server
181 | - elasticsearch
182 | - opensearch
183 | - grunt
184 | - postfix
185 | - mailhog
186 | - pestle
187 | - magereun
188 | - adminer
189 | - magento-cloud cli
190 | - bin/magento bash completion
191 |
192 | ### Access
193 | * User bash terminal
194 | * user: vagrant
195 | * Back-office
196 | * url: magento[url]/admin
197 | * user: magento.admin
198 | * pass: admin123
199 | * Database
200 | * user: vagrant
201 | * pass: vagrant
202 | * name: magento
203 | * Mailhog
204 | * url: [network_ip]:8025
205 | * Adminer
206 | * url: [network_ip]/adminer
207 | * Phpinfo
208 | * url: [network_ip]/php
209 |
210 | ### Mysql
211 | Percona server 8.0 is now installed for Magento >=2.4.0
212 | Lower versions are handled foreach existing Magento versions.
213 |
214 | ### PHP
215 | PHP 8.2 is now installed by default for Magento >=2.4.6
216 | Lower versions are handled foreach existing Magento versions.
217 |
218 | ### Composer
219 | Composer v2 is now installed by default for Magento >=2.4.2
220 | Lower versions are handled foreach existing Magento versions.
221 |
222 | ### Elasticsearch
223 | Version 8.4.x of Elasticsearch is now available for Magento 2.4.6
224 | Version 7.6.x of Elasticsearch is available for version between 2.4.0 and 2.4.5
225 | Lower versions are handled foreach existing Magento versions
226 | Otherwise, you can also completely disable elasticsearch by installing this module: https://github.com/zepgram/module-disable-search-engine
227 |
228 | ### Opensearch
229 | Version 2.5.x is now available for Magento 2.4.6
230 | Elasticsearch will be installed by default on lower Magento versions.
231 |
232 | ## Issues
233 |
234 | ### Windows 10
235 | There is a known [issue with composer installation](https://github.com/zepgram/magento2-fast-vm/issues/70) on windows 10.
236 | This issue could not be solved yet, and has already been reported 2 times.
237 | - This is related to the computer and BIOS configuration.
238 | - This is only reported on "NFS" mount option.
239 |
240 | To solve this, I recommend to set mount option to "rsync", then after full installation you should be able to fall back to NFS.
241 |
242 | ### Others
243 | If you have trouble during installation please open a new issue on this GitHub repository.
244 |
--------------------------------------------------------------------------------
/Vagrantfile:
--------------------------------------------------------------------------------
1 | # ------------------------------------- #
2 | # Fast VM - Magento2 #
3 | # #
4 | # Author: zepgram #
5 | # Git: https://github.com/zepgram/ #
6 | # ------------------------------------- #
7 |
8 | # Requiered plugins
9 | # -*- mode: ruby -*-
10 | # vi: set ft=ruby :
11 | rootPath = File.dirname(__FILE__)
12 | require 'yaml'
13 | require "#{rootPath}/dependency.rb"
14 |
15 | # Load yaml configuration
16 | configValues = YAML.load_file("#{rootPath}/config.yaml")
17 | vmconf = configValues['vmconf']
18 | composer = configValues['composer']
19 | git = configValues['git']
20 | magento = configValues['magento']
21 | projectName = 'magento'
22 |
23 | # Check plugin
24 | check_plugins ['vagrant-bindfs', 'vagrant-rsync-back']
25 | if OS.is_windows
26 | check_plugins ['vagrant-winnfsd']
27 | end
28 |
29 | # Mount directory option
30 | hostDirectory = "./www/#{projectName}"
31 | guestDirectory = "/home/vagrant/#{projectName}"
32 | if vmconf['path'] == 'app'
33 | hostDirectory = "./www/#{projectName}/app"
34 | guestDirectory = "/home/vagrant/#{projectName}/app"
35 | end
36 |
37 | # Vagrant configure
38 | Vagrant.configure(2) do |config|
39 | # Virtual machine
40 | config.vm.box = 'geerlingguy/debian10'
41 |
42 | # Host manager configuration
43 | config.vm.define vmconf['host_name']
44 | config.vm.hostname = vmconf['host_name']
45 | config.vm.network "private_network", ip: vmconf['network_ip']
46 |
47 | # VBox config
48 | config.vm.provider 'virtualbox' do |v|
49 | v.name = vmconf['machine_name']
50 | v.memory = vmconf['memory']
51 | v.cpus = vmconf['cpus']
52 | # Share VPN connections
53 | v.customize ['modifyvm', :id, '--natdnshostresolver1', 'on']
54 | v.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
55 | # Use multiple CPUs in VM
56 | v.customize ['modifyvm', :id, '--ioapic', 'on']
57 | # Enable symlink
58 | v.customize ['setextradata', :id, 'VBoxInternal2/SharedFoldersEnableSymlinksCreate/var/www/', '1']
59 | # Resolve issue due to ssh lock https://github.com/hashicorp/vagrant/issues/11777
60 | v.customize ["modifyvm", :id, "--uart1", "0x3F8", "4"]
61 | v.customize ["modifyvm", :id, "--uartmode1", "file", File::NULL]
62 | # Uncomment option below to avoid issues with VirtualBox on Windows 10
63 | # v.gui=true
64 | end
65 |
66 | # Default options
67 | config.vm.synced_folder '.', '/vagrant', disabled: true
68 |
69 | # Bindfs options
70 | config.bindfs.default_options = {
71 | force_group: 'www-data',
72 | }
73 | # NFS mount
74 | if vmconf['mount'] == 'nfs'
75 | if OS.is_windows
76 | config.winnfsd.uid = 1
77 | config.winnfsd.gid = 1
78 | end
79 | # Linux NFS specification
80 | if OS.is_linux
81 | config.vm.synced_folder hostDirectory, guestDirectory, create: true, :nfs => true,
82 | linux__nfs_options: ['rw','no_subtree_check','all_squash','async'], nfs_version: 4, nfs_udp: false
83 | else
84 | config.vm.synced_folder hostDirectory, guestDirectory, create: true, :nfs => true
85 | end
86 | config.nfs.map_uid = Process.uid
87 | config.nfs.map_gid = Process.gid
88 | end
89 | # Rsync mount
90 | if vmconf['mount'] == 'rsync'
91 | config.vm.synced_folder hostDirectory, guestDirectory, create: true, type: 'rsync',
92 | rsync__args: ['--archive', '-z', '--copy-links'],
93 | rsync__exclude: rsync_exclude
94 | end
95 | # Default mount
96 | if vmconf['mount'] != 'rsync' && vmconf['mount'] != 'nfs'
97 | vmconf['mount'] = 'default';
98 | config.vm.synced_folder hostDirectory, guestDirectory, create: true
99 | end
100 |
101 | # Bindfs
102 | config.bindfs.bind_folder guestDirectory, guestDirectory, after: :provision
103 |
104 | # SSH key provisioning
105 | config.vm.provision 'file', source: './ssh/id_rsa', destination: '~/.ssh/id_rsa'
106 | config.vm.provision 'file', source: './ssh/id_rsa.pub', destination: '~/.ssh/id_rsa.pub'
107 |
108 | # Extra provision
109 | process_extra_file(config, 'extra/001-env.sh')
110 | process_extra_file(config, 'extra/100-pre-build.sh')
111 | process_extra_file(config, 'extra/120-post-build.sh')
112 |
113 | # Import db
114 | if File.file?('db-dump.sql.gz')
115 | config.vm.provision 'file', source: 'db-dump.sql.gz', destination: '/home/vagrant/extra/db-dump.sql.gz', run: 'always'
116 | end
117 |
118 | # Environment provisioning
119 | config.vm.provision 'shell', path: 'provision/001-system-env.sh', run: 'always', keep_color: true, args: [
120 | projectName, composer['username'], composer['password'],
121 | git['name'], git['email'], git['host'], git['repository'],
122 | magento['url'], magento['php_version'], magento['source'], magento['edition'],
123 | magento['version'], magento['sample'], magento['mode'], magento['currency'],
124 | magento['language'], magento['time_zone'], magento['crypt_key'], vmconf['mount'], vmconf['path'],
125 | magento['search_engine'], magento['disable_two_factor_auth']
126 | ]
127 |
128 | # Shell provisioning
129 | if vmconf['provision'] == 'all'
130 | config.vm.provision 'shell', path: 'provision/010-system-packages.sh', keep_color: true
131 | config.vm.provision 'shell', path: 'provision/020-system-services.sh', keep_color: true
132 | config.vm.provision 'shell', path: 'provision/100-magento-pre.sh', keep_color: true
133 | config.vm.provision 'shell', path: 'provision/110-magento-app.sh', keep_color: true
134 | config.vm.provision 'shell', path: 'provision/120-magento-post.sh', keep_color: true
135 | end
136 | if vmconf['provision'] == 'system'
137 | config.vm.provision 'shell', path: 'provision/010-system-packages.sh', keep_color: true
138 | config.vm.provision 'shell', path: 'provision/020-system-services.sh', keep_color: true
139 | end
140 | if vmconf['provision'] == 'magento'
141 | config.vm.provision 'shell', path: 'provision/100-magento-pre.sh', keep_color: true
142 | config.vm.provision 'shell', path: 'provision/110-magento-app.sh', keep_color: true
143 | config.vm.provision 'shell', path: 'provision/120-magento-post.sh', keep_color: true
144 | end
145 |
146 | # SSH
147 | config.ssh.forward_agent = true
148 |
149 | # Post up message
150 | config.vm.post_up_message =
151 | "
152 | ---------------------------------------------------------
153 | Vagrant machine ready to use for #{git['name']}
154 | mount #{vmconf['mount']}
155 | path #{guestDirectory}
156 | magento http://#{magento['url']}
157 | phpinfo http://#{vmconf['network_ip']}/php
158 | adminer http://#{vmconf['network_ip']}/adminer
159 | mailhog http://#{vmconf['network_ip']}:8025
160 | "
161 |
162 | # Triggers
163 | triggers(config, vmconf['mount'], vmconf['host_name'], hostDirectory)
164 | end
165 |
--------------------------------------------------------------------------------
/config.yaml.example:
--------------------------------------------------------------------------------
1 | vmconf:
2 | machine_name: 'Vagrant Magento 2'
3 | network_ip: '192.168.60.0'
4 | host_name: 'zepgram'
5 | memory: '4096'
6 | cpus: '1'
7 | mount: 'nfs'
8 | path: 'root'
9 | provision: 'all'
10 | composer:
11 | username: 'magentoUsernameKey'
12 | password: 'magentoPasswordKey'
13 | git:
14 | name: 'John Doe'
15 | email: 'john@doe.com'
16 | host: 'github.com'
17 | repository: 'ssh://git@github.com:project-name.git'
18 | magento:
19 | url: 'dev.magento.com'
20 | source: 'composer'
21 | edition: 'community'
22 | version: '2.4.6'
23 | php_version: 'default'
24 | sample: 'true'
25 | mode: 'developer'
26 | currency: 'USD'
27 | language: 'en_US'
28 | time_zone: 'America/New_York'
29 | crypt_key: ''
30 | search_engine: 'opensearch'
31 | disable_two_factor_auth: 'true'
32 |
--------------------------------------------------------------------------------
/db-dump.sql.gz.example:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zepgram/magento2-fast-vm/fea0b9a1b6add1a882087f0615fb5f1ebfcaf896/db-dump.sql.gz.example
--------------------------------------------------------------------------------
/dependency.rb:
--------------------------------------------------------------------------------
1 | # ------------------------------------- #
2 | # Fast VM - Magento2 #
3 | # #
4 | # Author: zepgram #
5 | # Git: https://github.com/zepgram/ #
6 | # ------------------------------------- #
7 |
8 | require 'getoptlong'
9 | require 'fileutils'
10 |
11 | ## Get OS
12 | module OS
13 | def OS.is_windows
14 | (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
15 | end
16 | def OS.is_mac
17 | (/darwin/ =~ RUBY_PLATFORM) != nil
18 | end
19 | def OS.is_linux
20 | !OS.is_windows and not OS.is_mac
21 | end
22 | end
23 |
24 | ## Check install plugins
25 | def check_plugins(dependencies)
26 | skip_dependency_manager = false
27 |
28 | ARGV.each_with_index do |value, index|
29 | case value
30 | when '--skip-dependency-manager'
31 | skip_dependency_manager = true
32 | end
33 | end
34 |
35 | if ['up', 'reload'].include?(ARGV[0]) && !skip_dependency_manager
36 | installed_dependencies = []
37 |
38 | puts "\033[0m" << "==> Checking dependencies..." << "\e[0m"
39 |
40 | raw_output = `vagrant plugin list`
41 | raw_list = raw_output.split("\n")
42 |
43 | raw_list.each do |plugin|
44 | if plugin.index("\e[0m") != nil
45 | first = plugin.index("\e[0m") + 4
46 | else
47 | first = 0
48 | end
49 | installed_dependencies.push plugin.slice((first)..(plugin.index("(").to_i-1)).strip
50 | end
51 |
52 | dependencies_already_satisfied = true
53 |
54 | dependencies.each_with_index do |dependency, index|
55 | if not installed_dependencies.include? dependency
56 | dependencies_already_satisfied = false
57 | puts "\033[0m" << "==> Missing '#{dependency}'!" << "\e[0m"
58 | if not system "vagrant plugin install #{dependency}"
59 | puts "\n\033[0m" << "==> Could not install plugin '#{dependency}'. " << "\e[0m\033[41m" <<"Stopped." << "\e[0m"
60 | exit -1
61 | end
62 | end
63 | end
64 |
65 | if dependencies_already_satisfied
66 | puts "\033[0m" << "==> All dependencies are satisfied" << "\e[0m"
67 | else
68 | puts "\033[0m" << "==> Dependencies installed" << "\e[0m"
69 | exec "vagrant " << "--skip-dependency-manager " << ARGV.join(" ")
70 | exit
71 | end
72 | end
73 |
74 | if ARGV.include?('--skip-dependency-manager')
75 | ARGV.delete_at(ARGV.index('--skip-dependency-manager'))
76 | end
77 |
78 | end
79 |
80 | ## Force LF
81 | def process_extra_file(config, file)
82 | if File.file?(file)
83 | config.vm.provision 'file', source: file, destination: '/home/vagrant/' + file, run: 'always'
84 | end
85 | end
86 |
87 | ## Define rsync exluded directories
88 | def rsync_exclude
89 | return [
90 | 'generated/code/*', 'var/page_cache/*', 'var/view_preprocessed/*',
91 | 'pub/static/adminhtml/*', 'pub/static/base/*', 'pub/static/frontend/*',
92 | 'dev', 'node_modules', 'phpserver', 'update'
93 | ]
94 | end
95 |
96 | ## Tiggers
97 | def triggers(config, mount, hostName, hostDirectory)
98 | if mount == 'rsync'
99 | rsync_back = false;
100 | config.trigger.after :up, :reload, :provision do |trigger|
101 | # Run rsync back
102 | trigger.ruby do |env,machine|
103 | if !File.exist?("#{hostDirectory}/app/etc/di.xml");
104 | rsync_back = true;
105 | end
106 | end
107 | # Add post-up message
108 | trigger.info = config.vm.post_up_message
109 | trigger.info+= '---------------------------------------------------------'
110 | if rsync_back;
111 | trigger.warn = "\r\nRsync-back duration: ~10min. Once rsync-back is complete, run 'vagrant reload'"
112 | trigger.run = {inline: "vagrant rsync-back #{hostName}"}
113 | else
114 | # Run rsync auto
115 | trigger.warn = "\r\nRsync-auto is running... Do not close this terminal."
116 | trigger.run = {inline: "vagrant rsync-auto --rsync-chown #{hostName}"}
117 | end
118 | end
119 | config.trigger.after :destroy do |trigger|
120 | trigger.ruby do |env,machine|
121 | File.delete("#{hostDirectory}/app/etc/di.xml") if File.file?("#{hostDirectory}/app/etc/di.xml")
122 | end
123 | end
124 | end
125 | end
126 |
--------------------------------------------------------------------------------
/extra/001-env-example.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # Hook on system init sequence
4 |
5 | # Example:
6 | # cat <> /etc/profile.d/myvars.sh
7 | # export CUSTOM_ENVIRONMENT=myvalue
8 | # EOF
9 |
--------------------------------------------------------------------------------
/extra/100-pre-build-example.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # Hook on pre-build sequence
4 |
5 | # Example:
6 | # apt-get install varnish
7 |
--------------------------------------------------------------------------------
/extra/120-post-build-example.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # Hook on post-build sequence
4 |
5 | # Example:
6 | # magento setup:upgrade
7 |
--------------------------------------------------------------------------------
/provision/001-system-env.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # ------------------------------------- #
4 | # Fast VM - Magento2 #
5 | # #
6 | # Author: zepgram #
7 | # Git: https://github.com/zepgram/ #
8 | # ------------------------------------- #
9 |
10 | export DEBIAN_FRONTEND=noninteractive
11 |
12 | echo '--- Environment variables ---'
13 |
14 | # Set php version
15 | PROJECT_VERSION=${12};
16 | PROJECT_PHP_VERSION='8.2';
17 | if $(dpkg --compare-versions "${PROJECT_VERSION}" "lt" "2.4.6"); then
18 | PROJECT_PHP_VERSION='8.1';
19 | fi
20 | if $(dpkg --compare-versions "${PROJECT_VERSION}" "lt" "2.4.4"); then
21 | PROJECT_PHP_VERSION='7.4';
22 | fi
23 | if $(dpkg --compare-versions "${PROJECT_VERSION}" "lt" "2.3.6"); then
24 | PROJECT_PHP_VERSION='7.3';
25 | fi
26 | if $(dpkg --compare-versions "${PROJECT_VERSION}" "lt" "2.3"); then
27 | PROJECT_PHP_VERSION='7.1';
28 | fi
29 | if $(dpkg --compare-versions "${PROJECT_VERSION}" "lt" "2.2"); then
30 | PROJECT_PHP_VERSION='7.0';
31 | fi
32 | if [ "${9}" != 'default' ]; then
33 | PROJECT_PHP_VERSION="${9}"
34 | fi
35 |
36 | # search engine
37 | SEARCH_ENGINE=${21}
38 | if [ "$SEARCH_ENGINE" != "opensearch" ]; then
39 | if $(dpkg --compare-versions "${PROJECT_VERSION}" "ge" "2.4.6"); then
40 | SEARCH_ENGINE='elasticsearch8'
41 | elif $(dpkg --compare-versions "${PROJECT_VERSION}" "ge" "2.4.0"); then
42 | SEARCH_ENGINE='elasticsearch7'
43 | else
44 | SEARCH_ENGINE='elasticsearch6'
45 | fi
46 | fi
47 |
48 | # two factor auth
49 | DISABLE_TWO_FACTOR_AUTH=${22}
50 | if [ "$DISABLE_TWO_FACTOR_AUTH" == "true" ] && $(dpkg --compare-versions "${PROJECT_VERSION}" "lt" "2.4.0"); then
51 | DISABLE_TWO_FACTOR_AUTH='false'
52 | fi
53 |
54 | # Set environment variable
55 | cat < /etc/profile.d/env.sh
56 | export PROJECT_NAME="${1}"
57 | export PROJECT_USER="${1}"
58 | export PROJECT_PATH="/home/vagrant/${1}"
59 | export PROJECT_COMPOSER_USER="${2}"
60 | export PROJECT_COMPOSER_PASS="${3}"
61 | export PROJECT_GIT_USER="${4}"
62 | export PROJECT_GIT_EMAIL="${5}"
63 | export PROJECT_HOST_REPOSITORY="${6}"
64 | export PROJECT_REPOSITORY="${7}"
65 | export PROJECT_URL="${8}"
66 | export PROJECT_PHP_VERSION="${PROJECT_PHP_VERSION}"
67 | export PROJECT_SOURCE="${10}"
68 | export PROJECT_EDITION="${11}"
69 | export PROJECT_VERSION="${PROJECT_VERSION}"
70 | export PROJECT_SAMPLE="${13}"
71 | export PROJECT_MODE="${14}"
72 | export PROJECT_CURRENCY="${15}"
73 | export PROJECT_LANGUAGE="${16}"
74 | export PROJECT_TIME_ZONE="${17}"
75 | export PROJECT_CRYPT_KEY="${18}"
76 | export PROJECT_MOUNT="${19}"
77 | export PROJECT_MOUNT_PATH="${20}"
78 | export PROJECT_SEARCH_ENGINE="${SEARCH_ENGINE}"
79 | export PROJECT_DISABLE_TWO_FACTOR_AUTH="${DISABLE_TWO_FACTOR_AUTH}"
80 | EOF
81 | source /etc/profile.d/env.sh
82 |
83 | # Project path
84 | if [[ -z $(grep "${PROJECT_PATH}" "/home/vagrant/.bashrc") ]]; then
85 | cat <<-EOF >> /home/vagrant/.bashrc
86 | cd $PROJECT_PATH
87 | EOF
88 | fi
89 |
90 | # Patch extra files
91 | sudo -u vagrant mkdir -p /home/vagrant/extra
92 | if [[ ! $(dpkg-query -l 'dos2unix') ]]; then
93 | sudo apt-get install -y dos2unix
94 | fi
95 | if [ -f /home/vagrant/extra/001-env.sh ]; then
96 | dos2unix /home/vagrant/extra/001-env.sh
97 | fi
98 | if [ -f /home/vagrant/extra/100-pre-build.sh ]; then
99 | dos2unix /home/vagrant/extra/100-pre-build.sh
100 | fi
101 | if [ -f /home/vagrant/extra/120-post-build.sh ]; then
102 | dos2unix /home/vagrant/extra/120-post-build.sh
103 | fi
104 |
105 | # Extra env
106 | if [ -f /home/vagrant/extra/001-env.sh ]; then
107 | bash /home/vagrant/extra/001-env.sh
108 | fi
109 |
110 | # Source and display
111 | source /etc/profile
112 | cat /etc/profile.d/env.sh
113 |
--------------------------------------------------------------------------------
/provision/010-system-packages.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # ------------------------------------- #
4 | # Fast VM - Magento2 #
5 | # #
6 | # Author: zepgram #
7 | # Git: https://github.com/zepgram/ #
8 | # ------------------------------------- #
9 |
10 | export DEBIAN_FRONTEND=noninteractive
11 |
12 | echo '--- Install system packages ---'
13 |
14 | # Mysql settings
15 | debconf-set-selections <<< "mysql-server mysql-server/root_password password password"
16 | debconf-set-selections <<< "mysql-server mysql-server/root_password_again password password"
17 | echo "percona-server-server-5.7 percona-server-server-5.7/root-pass password password" | debconf-set-selections
18 | echo "percona-server-server-5.7 percona-server-server-5.7/re-root-pass password password" | debconf-set-selections
19 |
20 | # Postfix settings
21 | debconf-set-selections <<< "postfix postfix/mailname string $PROJECT_URL"
22 | debconf-set-selections <<< "postfix postfix/main_mailer_type string 'Internet Site'"
23 |
24 | # Set default locale
25 | if ! grep -qF "LANG" /home/vagrant/.bashrc; then
26 | cp /etc/locale.gen /etc/locale.gen.old
27 | sed -i "s/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/g" /etc/locale.gen && /usr/sbin/locale-gen
28 | echo 'export LANG=en_US.UTF-8' | tee -a ~/.bashrc >> /home/vagrant/.bashrc
29 | echo 'export LC_CTYPE=en_US.UTF-8' | tee -a ~/.bashrc >> /home/vagrant/.bashrc
30 | echo 'export LC_ALL=en_US.UTF-8' | tee -a ~/.bashrc >> /home/vagrant/.bashrc
31 | fi
32 |
33 | # Required packages
34 | rm -rf /etc/apt/sources.list.d/*
35 | apt-get update -y && apt-get install -y \
36 | curl graphviz htop net-tools rsync sudo tree wget unzip zip g++ gnupg2 \
37 | libsqlite3-dev libxml2-utils build-essential software-properties-common \
38 | postfix mailutils libsasl2-2 libsasl2-modules ca-certificates libnss3-tools \
39 | apt-transport-https openssl redis-server nginx \
40 | python golang-go openjdk-11-jdk openjdk-11-jre \
41 | vim git git-flow
42 |
43 | # Php Repository
44 | wget -q https://packages.sury.org/php/apt.gpg -O- | apt-key add -
45 | echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php.list
46 |
47 | # Percona repository
48 | wget https://repo.percona.com/apt/percona-release_latest.$(lsb_release -sc)_all.deb
49 | dpkg -i percona-release_latest.$(lsb_release -sc)_all.deb
50 | rm -f percona-release_latest.$(lsb_release -sc)_all.deb
51 |
52 | if [ "$PROJECT_SEARCH_ENGINE" == "opensearch" ]; then
53 | # Open search repository
54 | curl -o- https://artifacts.opensearch.org/publickeys/opensearch.pgp | sudo apt-key add -
55 | echo "deb https://artifacts.opensearch.org/releases/bundle/opensearch/2.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/opensearch-2.x.list
56 | else
57 | # Elasticsearch repository
58 | wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add -
59 | if $(dpkg --compare-versions "${PROJECT_VERSION}" "ge" "2.4.6"); then
60 | echo "deb https://artifacts.elastic.co/packages/8.x/apt stable main" | tee /etc/apt/sources.list.d/elastic-8.x.list
61 | elif $(dpkg --compare-versions "${PROJECT_VERSION}" "ge" "2.4.0"); then
62 | echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | tee /etc/apt/sources.list.d/elastic-7.x.list
63 | else
64 | echo "deb https://artifacts.elastic.co/packages/6.x/apt stable main" | tee /etc/apt/sources.list.d/elastic-6.x.list
65 | fi
66 | fi
67 |
68 | # PHP and additional
69 | apt-get update -y && apt-get install -y \
70 | php"${PROJECT_PHP_VERSION}" php"${PROJECT_PHP_VERSION}"-common php"${PROJECT_PHP_VERSION}"-cli \
71 | php"${PROJECT_PHP_VERSION}"-curl php"${PROJECT_PHP_VERSION}"-gd php"${PROJECT_PHP_VERSION}"-intl \
72 | php"${PROJECT_PHP_VERSION}"-mbstring php"${PROJECT_PHP_VERSION}"-soap php"${PROJECT_PHP_VERSION}"-zip \
73 | php"${PROJECT_PHP_VERSION}"-xml php"${PROJECT_PHP_VERSION}"-xml php"${PROJECT_PHP_VERSION}"-bcmath \
74 | php"${PROJECT_PHP_VERSION}"-mysql php"${PROJECT_PHP_VERSION}"-sqlite3 php"${PROJECT_PHP_VERSION}"-fpm \
75 | php"${PROJECT_PHP_VERSION}"-memcache php"${PROJECT_PHP_VERSION}"-redis php"${PROJECT_PHP_VERSION}"-opcache \
76 | php"${PROJECT_PHP_VERSION}"-sockets
77 | if $(dpkg --compare-versions "${PROJECT_PHP_VERSION}" "lt" "7.2"); then
78 | apt-get install -y php"${PROJECT_PHP_VERSION}"-mcrypt
79 | fi
80 |
81 | # Search engine
82 | if [ "$PROJECT_SEARCH_ENGINE" == "opensearch" ]; then
83 | apt-get install -y opensearch=2.5.0
84 | # remove from apt list to avoid self-update
85 | rm -f /etc/apt/sources.list.d/opensearch-2.x.list
86 | else
87 | apt-get install -y elasticsearch
88 | fi
89 |
90 | # MySQL
91 | if $(dpkg --compare-versions "${PROJECT_VERSION}" "ge" "2.4.0"); then
92 | percona-release setup ps80
93 | apt-get install -y percona-server-server
94 | else
95 | apt-get install -y percona-server-server-5.7
96 | fi
97 |
98 |
99 | # Composer
100 | if $(dpkg --compare-versions "${PROJECT_VERSION}" "lt" "2.4.2"); then
101 | # Composer v1
102 | curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer --1
103 | # Prestissimo
104 | sudo -u vagrant composer global require hirak/prestissimo
105 | else
106 | # Composer v2
107 | curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
108 | fi
109 |
110 | # Postfix
111 | wget -P ~/ https://www.thawte.com/roots/thawte_Premium_Server_CA.pem && \
112 | mv ~/thawte_Premium_Server_CA.pem /usr/local/share/ca-certificates/thawte_Premium_Server_CA.crt && \
113 | update-ca-certificates;
114 |
115 | # Mailhog
116 | go get github.com/mailhog/MailHog
117 | ln -sfn /root/go/bin/MailHog /usr/local/bin/mailhog
118 |
119 | # Grunt
120 | curl -sL https://deb.nodesource.com/setup_10.x | bash -
121 | apt-get install -y nodejs
122 | npm install -g grunt-cli
123 |
124 | # Pestle
125 | curl -sL -o /usr/local/bin/pestle http://pestle.pulsestorm.net/pestle.phar
126 | chmod +x /usr/local/bin/pestle
127 |
128 | # Magerun
129 | curl -sL -o /usr/local/bin/magerun https://files.magerun.net/n98-magerun2.phar
130 | chmod +x /usr/local/bin/magerun
131 |
132 | # Magento cloud
133 | curl -sLS https://accounts.magento.cloud/cli/installer | php
134 | mv /root/.magento-cloud/bin/magento-cloud /usr/local/bin
135 | chmod +x /usr/local/bin/magento-cloud
136 |
137 | # Bash completion for magento cli
138 | curl -o /etc/bash_completion.d/magento2-bash-completion https://raw.githubusercontent.com/yvoronoy/magento2-bash-completion/master/magento2-bash-completion
139 | source /etc/bash_completion.d/magento2-bash-completion
140 |
141 | # Clean
142 | apt-get purge grub-pc -yq
143 | apt-get -y upgrade && apt-get -y clean autoclean && apt-get -y autoremove
144 |
--------------------------------------------------------------------------------
/provision/020-system-services.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # ------------------------------------- #
4 | # Fast VM - Magento2 #
5 | # #
6 | # Author: zepgram #
7 | # Git: https://github.com/zepgram/ #
8 | # ------------------------------------- #
9 |
10 | export DEBIAN_FRONTEND=noninteractive
11 |
12 | echo '--- Configure system services ---'
13 |
14 | # Create db user
15 | mysql -u root -ppassword -e "CREATE USER IF NOT EXISTS 'vagrant'@'localhost' IDENTIFIED BY 'vagrant';"
16 | mysql -u root -ppassword -e "CREATE USER IF NOT EXISTS 'vagrant'@'%' IDENTIFIED BY 'vagrant';"
17 | mysql -u root -ppassword -e "GRANT ALL PRIVILEGES ON * . * TO 'vagrant'@'localhost';"
18 | mysql -u root -ppassword -e "GRANT ALL PRIVILEGES ON * . * TO 'vagrant'@'%';"
19 | mysql -u root -ppassword -e "FLUSH PRIVILEGES;"
20 |
21 | # Mysql conf
22 | if ! grep -qF "innodb_buffer_pool_size" /etc/mysql/mysql.conf.d/mysqld.cnf; then
23 | cat <> /etc/mysql/mysql.conf.d/mysqld.cnf
24 | # Innodb
25 | innodb_buffer_pool_size = 1G
26 | innodb_log_file_size = 256M
27 | innodb_flush_log_at_trx_commit = 1
28 | innodb_flush_method = O_DIRECT
29 | EOF
30 | fi
31 |
32 |
33 | # -----------------------------------------------------------------------------------------------------
34 |
35 |
36 | # Add binary entry for sendmail
37 | ln -sfn /usr/sbin/sendmail /usr/local/bin/
38 |
39 | # Postfix config
40 | sed -i.bak '/relayhost/,/^/d' /etc/postfix/main.cf
41 | echo 'relayhost = 127.0.0.1:1025
42 | mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128' | tee -a /etc/postfix/main.cf
43 |
44 | # Configuration on booting
45 | cat <<'EOF' > /etc/systemd/system/mailhog.service
46 | [Unit]
47 | Description=MailHog service
48 |
49 | [Service]
50 | ExecStart=/usr/local/bin/mailhog
51 |
52 | [Install]
53 | WantedBy=multi-user.target
54 | EOF
55 | systemctl start mailhog
56 | systemctl enable mailhog
57 |
58 | /usr/sbin/sendmail -t -i -f $PROJECT_GIT_EMAIL <> /etc/tmpfiles.d/php-cli-opcache.conf
84 | d /tmp/php-opcache 1777 root root 1d
85 | EOF
86 | fi
87 | systemd-tmpfiles --create /etc/tmpfiles.d/php-cli-opcache.conf
88 |
89 |
90 | # -----------------------------------------------------------------------------------------------------
91 |
92 |
93 | # SSL certificates
94 | mkdir /home/vagrant/ssl
95 | cd /home/vagrant/ssl && openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 \
96 | -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.${PROJECT_URL}" \
97 | -keyout www."${PROJECT_URL}".key -out www."${PROJECT_URL}".crt
98 | cp /home/vagrant/ssl/www."${PROJECT_URL}".crt /etc/ssl/certs/www."${PROJECT_URL}".crt
99 | cp /home/vagrant/ssl/www."${PROJECT_URL}".key /etc/ssl/private/www."${PROJECT_URL}".key
100 | rm -rf /home/vagrant/ssl && cd /home/vagrant
101 |
102 | # Nginx
103 | perl -ne 'if ( m|\#location.*php\$ \{| .. m|^\s*#\}| ) { s/#//g; } print' -i /etc/nginx/sites-available/default
104 | sed -i "s|fastcgi_pass unix:/run/php/.*|fastcgi_pass unix:/run/php/php${PROJECT_PHP_VERSION}-fpm.sock;|" /etc/nginx/sites-available/default
105 | sed -i "s/With php-.*//" /etc/nginx/sites-available/default
106 | sed -i "s/fastcgi_pass 127.0.0.1:9000;//" /etc/nginx/sites-available/default
107 | sed -i 's/index index.html index.htm index.nginx-debian.html;/index index.php index.html index.htm index.nginx-debian.html;/' /etc/nginx/sites-available/default
108 |
109 | # Fpm
110 | sed -i 's/pm.max_children = .*/pm.max_children = 10/' /etc/php/"$PROJECT_PHP_VERSION"/fpm/pool.d/www.conf
111 | sed -i 's/pm.start_servers = .*/pm.start_servers = 2/' /etc/php/"$PROJECT_PHP_VERSION"/fpm/pool.d/www.conf
112 | sed -i 's/pm.min_spare_servers = .*/pm.min_spare_servers = 2/' /etc/php/"$PROJECT_PHP_VERSION"/fpm/pool.d/www.conf
113 | sed -i 's/pm.max_spare_servers = .*/pm.max_spare_servers = 5/' /etc/php/"$PROJECT_PHP_VERSION"/fpm/pool.d/www.conf
114 |
115 |
116 | # -----------------------------------------------------------------------------------------------------
117 |
118 |
119 | # Open search
120 | if [ "$PROJECT_SEARCH_ENGINE" == "opensearch" ]; then
121 | # Check if the configuration already exists in the opensearch.yml file
122 | if grep -q "plugins.security.disabled" /etc/opensearch/opensearch.yml; then
123 | sed -i "s/plugins.security.disabled: .*/plugins.security.disabled: true/" /etc/opensearch/opensearch.yml
124 | else
125 | # Add the configuration to the opensearch.yml file
126 | echo "plugins.security.disabled: true" >> /etc/opensearch/opensearch.yml
127 | fi
128 | sed -i "s/#network.host: .*/network.host: 127.0.0.1/" /etc/opensearch/opensearch.yml
129 | sed -i "s/#http.port: .*/http.port: 9200/" /etc/opensearch/opensearch.yml
130 | sed -i "s|#JAVA_HOME.*|JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre|" /etc/default/opensearch
131 |
132 | /bin/systemctl daemon-reload
133 | /bin/systemctl enable opensearch.service
134 | /bin/systemctl start opensearch.service
135 |
136 | else
137 | # Elastic search
138 | sed -i "s/#network.host: .*/network.host: 127.0.0.1/" /etc/elasticsearch/elasticsearch.yml
139 | sed -i "s/#http.port: .*/http.port: 9200/" /etc/elasticsearch/elasticsearch.yml
140 | if $(dpkg --compare-versions "${PROJECT_VERSION}" "ge" "2.4.0"); then
141 | sed -i "s|#JAVA_HOME.*|JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre|" /etc/default/elasticsearch
142 | else
143 | sed -i "s|#JAVA_HOME.*|JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java|" /etc/default/elasticsearch
144 | fi
145 | if $(dpkg --compare-versions "${PROJECT_VERSION}" "ge" "2.4.6"); then
146 | sed -i "s/xpack.security.enabled: .*/xpack.security.enabled: false/" /etc/elasticsearch/elasticsearch.yml
147 | fi
148 |
149 | mkdir /etc/systemd/system/elasticsearch.service.d
150 | cat <<'EOF' > /etc/systemd/system/elasticsearch.service.d/override.conf
151 | [Service]
152 | Restart=always
153 | EOF
154 |
155 | /bin/systemctl daemon-reload
156 | /bin/systemctl enable elasticsearch.service
157 | /bin/systemctl start elasticsearch.service
158 | fi
159 |
160 | # -----------------------------------------------------------------------------------------------------
161 |
162 |
163 | # Server permissions
164 | mkdir -p /var/www/html
165 |
166 | # Adminer in default
167 | mkdir -p /var/www/html/adminer
168 | curl -sL -o /var/www/html/adminer/index.php https://www.adminer.org/latest-en.php
169 |
170 | # Add php info
171 | mkdir -p /var/www/html/php/
172 | cat <<-EOF > /var/www/html/php/index.php
173 | /etc/nginx/sites-available/010-"$PROJECT_NAME"
20 | upstream fastcgi_backend {
21 | server unix:/run/php/php${PROJECT_PHP_VERSION}-fpm.sock;
22 | }
23 |
24 | server {
25 | listen 80;
26 | listen [::]:80;
27 | listen 443 ssl http2;
28 | listen [::]:443 ssl http2;
29 |
30 | server_name ${PROJECT_URL} www.${PROJECT_URL};
31 | set MAGE_ROOT /var/www/html/${PROJECT_NAME};
32 | include /home/vagrant/extra/${PROJECT_NAME}.nginx.conf;
33 |
34 | ssl_certificate /etc/ssl/certs/www.${PROJECT_URL}.crt;
35 | ssl_certificate_key /etc/ssl/private/www.${PROJECT_URL}.key;
36 | ssl_protocols TLSv1.2 TLSv1.1 TLSv1;
37 |
38 | access_log /var/log/nginx/${PROJECT_NAME}.access.log;
39 | error_log /var/log/nginx/${PROJECT_NAME}.error.log error;
40 | }
41 | EOF
42 | sed -i 's/MAGE_ROOT/$MAGE_ROOT/' /etc/nginx/sites-available/010-"$PROJECT_NAME"
43 | ln -sfn /etc/nginx/sites-available/010-"$PROJECT_NAME" /etc/nginx/sites-enabled/010-"$PROJECT_NAME"
44 |
45 | # Permission script
46 | cat <<-EOF > /home/vagrant/permission.bak
47 | echo 'Applying permissions to $PROJECT_PATH'
48 | cd "$PROJECT_PATH" \\
49 | && sudo find var vendor pub/static pub/media app/etc -type f -exec chmod g+w {} \; \\
50 | && sudo find var vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} \; \\
51 | && sudo find ./var ./generated -type d -exec chmod 777 {} \; \\
52 | && sudo chmod u+x bin/magento \\
53 | && sudo chown -fR :www-data . || :
54 | EOF
55 | grep '[^[:blank:]]' < /home/vagrant/permission.bak > /usr/local/bin/permission
56 | rm -rf /home/vagrant/permission.bak
57 | chmod +x /usr/local/bin/permission
58 |
59 | # Credentials
60 | chmod 600 /home/vagrant/.ssh/id_rsa
61 | chmod 600 /home/vagrant/.ssh/id_rsa.pub
62 | rm -rf /home/vagrant/.ssh/known_hosts /home/vagrant/.ssh/config
63 | echo -e "StrictHostKeyChecking no\n" >> /home/vagrant/.ssh/config
64 | ssh-keyscan -t rsa "${PROJECT_HOST_REPOSITORY}" >> /home/vagrant/.ssh/known_hosts
65 | composer config --global http-basic.repo.magento.com "${PROJECT_COMPOSER_USER}" "${PROJECT_COMPOSER_PASS}"
66 | sudo -u vagrant composer config --global http-basic.repo.magento.com "${PROJECT_COMPOSER_USER}" "${PROJECT_COMPOSER_PASS}"
67 |
68 | # Auth.json
69 | cat <<-EOF > /home/vagrant/auth.json
70 | {
71 | "http-basic": {
72 | "repo.magento.com": {
73 | "username": "${PROJECT_COMPOSER_USER}",
74 | "password": "${PROJECT_COMPOSER_PASS}"
75 | }
76 | }
77 | }
78 | EOF
79 |
80 | # Git global config
81 | if [ "$PROJECT_SOURCE" != "composer" ]; then
82 | sudo -u vagrant git config --global user.name "$PROJECT_GIT_USER"
83 | sudo -u vagrant git config --global user.email "$PROJECT_GIT_EMAIL"
84 | sudo -u vagrant git config --global core.filemode false
85 | fi
86 |
87 | # Reapply rights for vagrant user
88 | chown -R vagrant:vagrant /home/vagrant
89 |
90 | # Execute import sql
91 | if [ -f /home/vagrant/extra/db-dump.sql.gz ]; then
92 | echo '--- Magento db dump import ---'
93 | zcat /home/vagrant/extra/db-dump.sql.gz | mysql --init-command="SET SESSION FOREIGN_KEY_CHECKS=0;" --user=vagrant --password=vagrant "${PROJECT_NAME}"
94 | fi
95 | # Extra pre-build
96 | if [ -f /home/vagrant/extra/100-pre-build.sh ]; then
97 | bash /home/vagrant/extra/100-pre-build.sh
98 | fi
99 |
--------------------------------------------------------------------------------
/provision/110-magento-app.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # ------------------------------------- #
4 | # Fast VM - Magento2 #
5 | # #
6 | # Author: zepgram #
7 | # Git: https://github.com/zepgram/ #
8 | # ------------------------------------- #
9 |
10 | export DEBIAN_FRONTEND=noninteractive
11 |
12 | echo '--- Magento installation sequence ---'
13 |
14 | # Prepare directory
15 | DIRECTORY_BUILD="/home/vagrant"
16 | if [ "$PROJECT_MOUNT_PATH" == "app" ]; then
17 | DIRECTORY_BUILD="/tmp"
18 | fi
19 | PROJECT_BUILD="$DIRECTORY_BUILD/$PROJECT_NAME"
20 | rm -rf "$PROJECT_BUILD" &> /dev/null
21 | chmod -R 777 /tmp
22 | mkdir -p "$PROJECT_BUILD"
23 | chown -fR vagrant:vagrant "$PROJECT_BUILD"
24 |
25 | # Get installation files from source
26 | if [ "$PROJECT_SOURCE" == "composer" ]; then
27 | # Install from magento
28 | sudo -u vagrant composer create-project --no-interaction --no-install --no-progress \
29 | --repository=https://repo.magento.com/ magento/project-"$PROJECT_EDITION"-edition="$PROJECT_VERSION" "$PROJECT_NAME" -d "$DIRECTORY_BUILD"
30 | else
31 | # Install from git
32 | sudo -u vagrant git clone "$PROJECT_REPOSITORY" "$PROJECT_BUILD"
33 | cd "$PROJECT_BUILD"; sudo -u vagrant git fetch --all; git checkout "$PROJECT_SOURCE" --force;
34 | rm -f "$PROJECT_BUILD"/app/etc/config.php "$PROJECT_BUILD"/app/etc/env.php
35 | fi
36 |
37 | # Composer install
38 | echo '--- composer allow-plugins ---'
39 | COMPOSER_VERSION=$(composer -V | cut -d " " -f 3);
40 | if $(dpkg --compare-versions "${COMPOSER_VERSION}" "ge" "2.0"); then
41 | sudo -u vagrant composer config -d "$PROJECT_BUILD" --no-interaction --no-plugins "allow-plugins.magento/*" true
42 | sudo -u vagrant composer config -d "$PROJECT_BUILD" --no-interaction --no-plugins "allow-plugins.laminas/laminas-dependency-plugin" true
43 | sudo -u vagrant composer config -d "$PROJECT_BUILD" --no-interaction --no-plugins "allow-plugins.dealerdirect/phpcodesniffer-composer-installer" true
44 | sudo -u vagrant composer config -d "$PROJECT_BUILD" --no-interaction --no-plugins "allow-plugins.magento-composer-installer" true
45 | fi
46 | sudo -u vagrant COMPOSER_MEMORY_LIMIT=-1 composer install -d "$PROJECT_BUILD" --no-progress --no-interaction
47 |
48 | # Handle two factor auth deactivation
49 | if [ "$PROJECT_DISABLE_TWO_FACTOR_AUTH" == "true" ]; then
50 | sudo -u vagrant COMPOSER_MEMORY_LIMIT=-1 composer require -d "$PROJECT_BUILD" --no-progress --no-interaction markshust/magento2-module-disabletwofactorauth
51 | fi
52 |
53 | # Rsync directory
54 | if [ "$PROJECT_BUILD" != "$PROJECT_PATH" ]; then
55 | rsync -a --remove-source-files "$PROJECT_BUILD"/ "$PROJECT_PATH"/ || true
56 | fi
57 |
58 | # Copy auth.json for sample installation
59 | if [ ! -f "$PROJECT_PATH/auth.json" ] && [ -f /home/vagrant/auth.json ]; then
60 | sudo -u vagrant cp /home/vagrant/auth.json "$PROJECT_PATH"/auth.json
61 | fi
62 |
63 | # Symlink
64 | rm -rf /var/www/html/"$PROJECT_NAME"
65 | ln -sfn "$PROJECT_PATH" /var/www/html/"$PROJECT_NAME"
66 |
67 | # Apply basic rights on regular mount
68 | chown -fR :www-data "$PROJECT_PATH"
69 |
70 | # Search engine argument
71 | SEARCH_ENGINE=""
72 | if $(dpkg --compare-versions "${PROJECT_VERSION}" "ge" "2.4.6"); then
73 | SEARCH_ENGINE="--search-engine=${PROJECT_SEARCH_ENGINE}"
74 | fi
75 |
76 | # Run install
77 | chmod +x "$PROJECT_PATH"/bin/magento
78 | sudo -u vagrant "$PROJECT_PATH"/bin/magento setup:uninstall -n -q
79 | sudo -u vagrant "$PROJECT_PATH"/bin/magento setup:install \
80 | --base-url="http://${PROJECT_URL}/" \
81 | --base-url-secure="https://${PROJECT_URL}/" \
82 | --db-host="localhost" \
83 | --db-name="${PROJECT_NAME}" \
84 | --db-user="vagrant" \
85 | --db-password="vagrant" \
86 | --admin-firstname="magento.admin" \
87 | --admin-lastname="magento.admin" \
88 | --admin-email="${PROJECT_GIT_EMAIL}" \
89 | --admin-user="magento.admin" \
90 | --admin-password="admin123" \
91 | --language="${PROJECT_LANGUAGE}" \
92 | --currency="${PROJECT_CURRENCY}" \
93 | --timezone="${PROJECT_TIME_ZONE}" \
94 | --use-rewrites="1" \
95 | --backend-frontname="admin" \
96 | $SEARCH_ENGINE
97 |
98 | # Install sample data
99 | if [ "$PROJECT_SAMPLE" == "true" ]; then
100 | sudo -u vagrant php -d memory_limit=-1 "$PROJECT_PATH"/bin/magento sampledata:deploy
101 | sudo -u vagrant "$PROJECT_PATH"/bin/magento setup:upgrade
102 | fi
103 |
--------------------------------------------------------------------------------
/provision/120-magento-post.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # ------------------------------------- #
4 | # Fast VM - Magento2 #
5 | # #
6 | # Author: zepgram #
7 | # Git: https://github.com/zepgram/ #
8 | # ------------------------------------- #
9 |
10 | export DEBIAN_FRONTEND=noninteractive
11 |
12 | echo '--- Magento post-installation sequence ---'
13 |
14 | # Magento cli
15 | chmod +x "$PROJECT_PATH"/bin/magento
16 | ln -sf "$PROJECT_PATH"/bin/magento /usr/local/bin/magento
17 |
18 | # Enable nginx
19 | if [ -f "${PROJECT_PATH}/nginx.conf.sample" ] && [ ! -f "${PROJECT_PATH}/nginx.conf" ]; then
20 | sudo -u vagrant cp "$PROJECT_PATH"/nginx.conf.sample "$PROJECT_PATH"/nginx.conf.tmp
21 | fi
22 | if [ -f "${PROJECT_PATH}/nginx.conf" ]; then
23 | sudo -u vagrant cp "$PROJECT_PATH"/nginx.conf /home/vagrant/extra/"${PROJECT_NAME}".nginx.conf;
24 | else
25 | sudo -u vagrant cp "$PROJECT_PATH"/nginx.conf.tmp /home/vagrant/extra/"${PROJECT_NAME}".nginx.conf;
26 | sudo -u vagrant rm -f "$PROJECT_PATH"/nginx.conf.tmp
27 | fi
28 | sudo -u vagrant sed -i "s/fastcgi_buffers 1024 4k;/fastcgi_buffers 16 14k;\n fastcgi_buffer_size 32k;/" /home/vagrant/extra/"${PROJECT_NAME}".nginx.conf;
29 |
30 | # Composer config
31 | if [ "$PROJECT_SOURCE" == "composer" ]; then
32 | # Enable php ini
33 | if [ -f "${PROJECT_PATH}/php.ini.sample" ] && [ ! -f "${PROJECT_PATH}/php.ini" ]; then
34 | sudo -u vagrant cp "$PROJECT_PATH"/php.ini.sample "$PROJECT_PATH"/php.ini
35 | fi
36 | # Enable npm
37 | if [ -f "${PROJECT_PATH}/package.json.sample" ] && [ ! -f "${PROJECT_PATH}/package.json" ]; then
38 | sudo -u vagrant cp "$PROJECT_PATH"/package.json.sample "$PROJECT_PATH"/package.json
39 | fi
40 | # Enable grunt
41 | if [ -f "${PROJECT_PATH}/Gruntfile.js.sample" ] && [ ! -f "${PROJECT_PATH}/Gruntfile.js" ]; then
42 | sudo -u vagrant cp "$PROJECT_PATH"/Gruntfile.js.sample "$PROJECT_PATH"/Gruntfile.js
43 | fi
44 | fi
45 |
46 | # Npm install
47 | if [ -f "${PROJECT_PATH}/package.json" ] && [ -f "${PROJECT_PATH}/Gruntfile.js" ]; then
48 | cd "$PROJECT_PATH" \
49 | && echo 'Executing npm install...' \
50 | && sudo -u vagrant npm install &> /dev/null \
51 | && sudo -u vagrant npm update
52 | fi
53 |
54 | # Change materialization strategy for nfs
55 | if [ "$PROJECT_MOUNT" == "nfs" ] && [ "$PROJECT_MOUNT_PATH" != "app" ]; then
56 | if [ -f "${PROJECT_PATH}/.git/config" ]; then
57 | sudo -u vagrant git --git-dir "$PROJECT_PATH"/.git update-index --assume-unchanged app/etc/di.xml
58 | fi
59 | sudo -u vagrant sed -i 's/- Magento\\\Framework\\\App\\\View\\\Asset\\\MaterializationStrategy\\\Symlink/
- Magento\\\Framework\\\App\\\View\\\Asset\\\MaterializationStrategy\\\Copy/' "$PROJECT_PATH"/app/etc/di.xml
60 | fi
61 |
62 | # Magento config
63 | redis-cli flushall
64 | if $(dpkg --compare-versions "${PROJECT_VERSION}" "gt" "2.2"); then
65 | sudo -u vagrant "$PROJECT_PATH"/bin/magento -n setup:config:set \
66 | --cache-backend=redis \
67 | --cache-backend-redis-server=127.0.0.1 \
68 | --cache-backend-redis-port=6379 \
69 | --cache-backend-redis-db=0 \
70 | --page-cache=redis \
71 | --page-cache-redis-server=127.0.0.1 \
72 | --page-cache-redis-port=6379 \
73 | --page-cache-redis-db=1 \
74 | --page-cache-redis-compress-data=1
75 |
76 | sudo -u vagrant "$PROJECT_PATH"/bin/magento -n setup:config:set \
77 | --session-save=redis \
78 | --session-save-redis-host=127.0.0.1 \
79 | --session-save-redis-port=6379 \
80 | --session-save-redis-db=2
81 |
82 | sudo -u vagrant "$PROJECT_PATH"/bin/magento config:set "admin/security/session_lifetime" "31536000"
83 | sudo -u vagrant "$PROJECT_PATH"/bin/magento config:set "admin/security/lockout_threshold" "180"
84 | sudo -u vagrant "$PROJECT_PATH"/bin/magento config:set "admin/security/password_lifetime" ""
85 | sudo -u vagrant "$PROJECT_PATH"/bin/magento config:set "admin/security/password_is_forced" "0"
86 | sudo -u vagrant "$PROJECT_PATH"/bin/magento config:set "web/secure/use_in_adminhtml" "1"
87 | sudo -u vagrant "$PROJECT_PATH"/bin/magento config:set "web/secure/use_in_frontend" "1"
88 | sudo -u vagrant "$PROJECT_PATH"/bin/magento config:set "web/secure/enable_hsts" "1"
89 | if [ "$PROJECT_SEARCH_ENGINE" == "opensearch" ]; then
90 | sudo -u vagrant "$PROJECT_PATH"/bin/magento config:set "catalog/search/engine" "opensearch"
91 | else
92 | sudo -u vagrant "$PROJECT_PATH"/bin/magento config:set "catalog/search/engine" $PROJECT_SEARCH_ENGINE
93 | fi
94 | else
95 | # Force https on unsecure request for older versions
96 | mysql -u vagrant -pvagrant -e "USE ${PROJECT_NAME}; UPDATE core_config_data set value='https://${PROJECT_URL}/' where path='web/unsecure/base_url';"
97 | fi
98 |
99 | # Set crypt key
100 | if [ -n "$PROJECT_CRYPT_KEY" ] && [ -f /home/vagrant/extra/db-dump.sql ]; then
101 | sudo -u vagrant bin/magento setup:config:set -n --key "${PROJECT_CRYPT_KEY}"
102 | fi
103 |
104 | # Extra post-build
105 | if [ -f /home/vagrant/extra/120-post-build.sh ]; then
106 | bash /home/vagrant/extra/120-post-build.sh
107 | fi
108 |
109 | # Get config from source project
110 | if [ "$PROJECT_SOURCE" != "composer" ]; then
111 | cd $PROJECT_PATH; sudo -u vagrant git checkout app/etc/config.php
112 | fi
113 |
114 | # Clean compiled files
115 | rm -rf "$PROJECT_PATH"/var/generation/
116 | rm -rf "$PROJECT_PATH"/generated/code/
117 | sudo -u vagrant "$PROJECT_PATH"/bin/magento setup:upgrade
118 | sudo -u vagrant "$PROJECT_PATH"/bin/magento deploy:mode:set "$PROJECT_MODE"
119 | sudo -u vagrant "$PROJECT_PATH"/bin/magento cache:enable
120 | sudo -u vagrant "$PROJECT_PATH"/bin/magento cache:flush
121 |
122 | # Restart services
123 | /etc/init.d/php"${PROJECT_PHP_VERSION}"-fpm restart
124 | /etc/init.d/nginx restart
125 | /etc/init.d/mysql restart
126 | /etc/init.d/redis-server restart
127 | /etc/init.d/postfix restart
128 | permission
129 |
--------------------------------------------------------------------------------
/ssh.example/id_rsa:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zepgram/magento2-fast-vm/fea0b9a1b6add1a882087f0615fb5f1ebfcaf896/ssh.example/id_rsa
--------------------------------------------------------------------------------
/ssh.example/id_rsa.pub:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zepgram/magento2-fast-vm/fea0b9a1b6add1a882087f0615fb5f1ebfcaf896/ssh.example/id_rsa.pub
--------------------------------------------------------------------------------