{"id":13721071,"url":"https://github.com/davidalger/devenv","last_synced_at":"2025-05-07T13:31:34.415Z","repository":{"id":36431638,"uuid":"40736643","full_name":"davidalger/devenv","owner":"davidalger","description":"Vagrant Development Environment for Mac OS X Hosts","archived":true,"fork":false,"pushed_at":"2018-12-06T16:27:03.000Z","size":812,"stargazers_count":20,"open_issues_count":0,"forks_count":13,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-04-12T02:22:32.312Z","etag":null,"topics":["magento2","magento2-devbox","magento2-vagrant"],"latest_commit_sha":null,"homepage":"","language":"Vim script","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"osl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/davidalger.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-08-14T21:24:30.000Z","updated_at":"2023-01-28T14:22:12.000Z","dependencies_parsed_at":"2022-09-06T05:20:29.942Z","dependency_job_id":null,"html_url":"https://github.com/davidalger/devenv","commit_stats":null,"previous_names":[],"tags_count":43,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidalger%2Fdevenv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidalger%2Fdevenv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidalger%2Fdevenv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidalger%2Fdevenv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/davidalger","download_url":"https://codeload.github.com/davidalger/devenv/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223924078,"owners_count":17226001,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["magento2","magento2-devbox","magento2-vagrant"],"created_at":"2024-08-03T01:01:12.154Z","updated_at":"2024-11-14T10:31:01.601Z","avatar_url":"https://github.com/davidalger.png","language":"Vim script","funding_links":[],"categories":["Dev boxes"],"sub_categories":["Vagrant"],"readme":"# Development Environment\n\nThis setup relies on Vagrant and VirtualBox (or [VMWare Fusion](#vmware-provider) if that's what you prefer) running on Mac OS X to power the virtualized developer environment. These dependencies are installed as part of the setup process using [Homebrew](http://brew.sh) and [Homebrew Cask](https://caskroom.github.io/).\n\nIt is setup with different machines running different versions of PHP. The machines provide all the necessary components to build on Magento, including support for running multiple PHP versions side-by-side if necessary ([see below for details](#virtual-machines)). The nodes run a traditional LAMP stack, with Nginx sitting in front of Apache as a proxy for static assets and for SSL termination. It also includes [Xdebug](http://xdebug.org) pre-configured to connect to your IDE on the host machine.\n\n## System Requirements\n\n* Mac OS X 10.11 or later\n* An HFS+ **Case-sensitive** partition mounted at `/Volumes/Server` or `/server`\n\n    *Note: The environment should install and run from a case-insensitive mount, but this is not recommended for two reasons: a) the majority of deployments are done to case-sensitive file-systems, so development done on a case-sensitive mount is less error prone (ex: autoloaders may find a class in development, then fail on production); b) mysql will behave differently as it pertains to [identifier case sensitivity](https://dev.mysql.com/doc/refman/5.0/en/identifier-case-sensitivity.html) potentially causing unexpected behavior*\n\n## Environment Setup\n\n1. The install process will install brew on the host machine for gathering dependencies where not already present. If you already have brew installed, however, it is recommended to run the following commands, then cleanup any major issues it reports:\n\n    ```bash\n    brew update\n    brew doctor\n    ```\n\n2. Install technical dependencies and setup the environment, entering your account password when prompted (this may happen a few times):\n\n    ```bash\n    curl -s https://raw.githubusercontent.com/davidalger/devenv/master/vagrant/bin/install.sh | bash\n    source /etc/profile\n    ```\n\n3. Run the following to start up the virtual machine. This may take a while on first run\n\n    ```bash\n    cd /server\n    vagrant up web72\n    ```\n\n4. To SSH into the vm, you can use `vcd` or `vcd web` to connect and automatically mirror your working directory\n\n### Optional Steps\n\n1. Install the compass tools used for scss compilation\n\n    ```bash\n    sudo gem update --system\n    sudo gem install compass\n    ```\n\n2. Generate an RSA key pair. The generated public key will be used to authenticate remote SSH connections\n\n    ```bash\n    ssh-keygen -f ~/.ssh/id_rsa\n    ```\n\n    *Note: When prompted, enter a memorable passphrase (you’ll need to use it later)*\n\n3. Because of GitHub's rate limits on their API it can happen that Composer will silently fail when running the m2setup.sh tool. To prevent this from happening, create an OAuth token via the [GitHub Settings](https://github.com/settings/tokens) area in your GitHub account. You can read more about these tokens [here](https://github.com/blog/1509-personal-api-tokens). Add this token to the composer configuration by running:\n\n    ```bash\n    composer config -g github-oauth.github.com \"\u003coauthtoken\u003e\"\n    ```\n\n4. Create a Magento 2 build available at m2.demo:\n\n    ```bash\n    vagrant ssh -- m2setup.sh --sampledata --hostname=m2.demo\n    echo \"10.19.89.14 m2.demo\" | sudo tee -a /etc/hosts \u003e /dev/null\n    ```\n\n### Quick Reference\n\n| hostname      | ip           | role     | description                                        |\n| ------------- | ------------ | -------- | -------------------------------------------------- |\n| dev-host      | 10.19.89.1   | host     | this is the host machine for the environment       |\n| [dev-web72]   | 10.19.89.16  | app      | App node running PHP 7.2 / Percona Server 5.6      |\n| [dev-web71]   | 10.19.89.15  | app      | App node running PHP 7.1 / Percona Server 5.6      |\n| [dev-web70]   | 10.19.89.14  | app      | App node running PHP 7.0 / Percona Server 5.6      |\n\n## Virtual Machines\n\n### Web Application\nThis node is setup to run services required to run web applications. Nginx is setup to deliver static assets directly and act as a proxy for anything else. Apache is setup with mod_php to delivery the web application and sits behind Nginx on an internal port. Redis has been setup for a cache data store such that it never writes information to disk.\n\nRun `vhosts.sh` to generate vhosts for all sites and reload apache. This will be automatically run once when the machine is provisioned, and may be subsequently run within the guest environment (use --help for available options).\n\nThe IP address of this node is fixed at `10.19.89.10`. This IP should be used in `/etc/hosts` on the host machine to facilitate loading applications running within the vm from a browser on the host.\n\n#### Virtual Host Configuration\nVirtual hosts are created automatically for each site by running the `vhosts.sh` script. These .conf files are based on a template, or may manually be configured on a per-site basis by placing a `.\u003cservice\u003e.conf` file in the root site directory where `\u003cservice\u003e` is the name of the service the file is to configure (such as nginx or httpd).\n    \nTo configure the virtual host configuration and reload services, run `vhosts.sh` within the guest machine. Running `vhosts.sh --reset-config --reset-certs` will wipe out all generated certificates and service configuration, creating it from scratch.\n\nThe `vhosts.sh` script looks for the pretense of three locations within each directory contained by `/sites` to determine if a given directory found in `/sites` is in fact in need of a virtual host. These locations are as follows:\n\n* /sites/example.dev/pub\n* /sites/example.dev/html\n* /sites/example.dev/htdocs\n\nIf any of these three paths exist, a virtual host will be created based on the template found in `/server/vagrant/etc/httpd/sites.d/__vhost.conf.template`. The `DocumentRoot` will be configured using the first of the above three paths found for a given site directory. The `ServerName` will match the name of the sites directory (example.dev above) and a wildcard `ServerAlias` is included to support relevant sub-domains. When a file is found at `/sites/example.dev/.vhost.conf` it will be used in leu of the template file. Any updates to this file will be applied to the host configuration on subsequent runs of the `vhosts.sh` script.\n\n#### PHP Versions\n\n* PHP 7.2\n* PHP 7.1\n* PHP 7.0\n\n#### SSL\nWhen the `web` VM is provisioned, a root CA is automatically generated and stored at `/server/.shared/ssl/rootca/certs/ca.cert.pem` if it does not already exist.\nDuring vhost discovery and configuration, a wildcard cert, signed by the root CA, is automatically generated for it. Nginx is configured accordingly.\n\nThis means that all vhosts support SSL on both the naked domain and any immediate subdomain. \nSince these certs are all signed by the persistent root CA, if the root CA is added to the host as a trusted cert, the SSL cert for any vhost will automatically be valid.\n\n##### Mac\nTo add the generated root CA to your trusted certs list on the host machine, run this command (after vagrant up has been run):\n\n```bash\nsudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain /server/.shared/ssl/rootca/certs/ca.cert.pem\n```\n\n##### Windows\nTo add the generated root CA to your certificate manager on Windows you will need to copy the `ca.cert.pem` file to a location on your Windows system like `C:\\certs\\ca.cert.pem` and then open a Command Prompt window in Administrator mode to execute the following command\n\n```bash\ncertutil –addstore -enterprise –f \"Root\" c:\\certs\\ca.cert.pem\n```\n\n### Database Server\n\nEach machine has an instance of Percona Server 5.6.x installed. Since this is a development environment, the root mysql password has been left blank. The data from the default machine is persisted in `/server/mysql/data`, data from other nodes persisted at `/server/mysql/\u003cNAME\u003e` where `\u003cNAME\u003e` is the name of machine the data is for.\n\nTo allow for custom database settings without modifying the default my.cnf file directly, files found at `vagrant/etc/my.cnf.d/*.cnf` will be copied onto this node and are applied via the `!includedir` directive in the `/etc/my.cnf` defaults file. Example use case: create the file `vagrant/etc/my.cnf.d/lower_case_table_names.cnf` with the following contents and then re-provision the vm:\n\n    [mysqld]\n    lower_case_table_names = 1\n\n***WARNING:*** Because data is persisted to the host machine via an NFS mount, attempts to forcefully shutdown (aka run `vagrant destroy`) a machine may cause data corruption and will fail subsequent mysql start operations unless the vm has first been halted and/or the mysql service stopped gracefully prior to vm destruction. The recommended sequence to wipe the vm and create from scratch is halt, destroy, then up.\n\n#### Common Problems\n##### Percona Server fails to start\nWhen this happens you'll see something like the following when attempting to provision or boot the vm:\n\n    TASK [Starting mysql service] **************************************************\n    fatal: [web]: FAILED! =\u003e {\"changed\": false, \"failed\": true, \"msg\": \"Starting MySQL (Percona Server). ERROR! The server quit without updating PID file (/var/lib/mysql/dev-web70.pid).\\n\"}\n\nThis happens (per above warning) when the mysql service fails to shutdown cleanly. To solve this issue, proceed through the following steps:\n\n***WARNING:*** If this is done and there is a running mysql instance using these ib* files, irreversible data corruption could occur. Please be careful!\n\n1. Verify that Virtual Box reports none of the virtual machines as still running. If machines are still running, you will need to halt each of them before proceeding.\n\n    ```bash\n    VBoxManage list runningvms | grep \"Server_\"\n    ```\n\n2. Restart the `rpc.lockd` service on the host\n\n    ```bash\n    sudo launchctl unload /System/Library/LaunchDaemons/com.apple.lockd.plist\n    sudo launchctl load /System/Library/LaunchDaemons/com.apple.lockd.plist\n    ```\n\n    Starting in MacOS 10.12.4 the rpc.lockd service is protected by System Integrity Protection, preventing you from reloading it via launchctl. If you see the message `Operation not permitted while System Integrity Protection is engaged` you will need to kill the `rpc.lockd` service instead. The service configuration has KeepAlive enabled, so the desired effect is accomplised, although in a much more heavy-handed fashion. Do this by running `sudo kill \u003cPID\u003e` where `\u003cPID\u003e` is replaced with the number `lsof` (per following step) displays under the PID column for the `rpc.lockd` command.\n\n3. Verify no locks exist on your `ib*` files (command should return nothing)\n\n    ```bash\n    sudo lsof /server/mysql/*/ib*\n    ```\n\n4. Destroy and restart the virtual machine\n\n    ```bash\n    vagrant destroy -f\n    vagrant up web72\n    ```\n\nIf the above does not succeed in bringing it back online, try rebooting the host machine. If that still does not solve the issue, it is likely you will have to help mysqld out a bit with recovery. Check `/var/log/mysqld.log` for more info.\n\n## Development Notes\n\n### Session Storage\nIt is well recognized that PHP cannot store sessions on an NFS mount. Since `/var/www/sites/` is mounted in the vm via an NFS mount, this causes trouble with storing session files inside the document root. Magento 2 seems to handle this just fine and stores it's sessions in the configured session location. Magento 1 requires a workaround to function.\n\nTo workaround this issue, replace the `var/session` directory with a soft-link pointing at the default php session store:\n\n```bash\nrm -rf var/session\nln -s /var/lib/php/session var/session\n```\n\nAlternately, you may use an alternative session storage mechanism such as redis or memcached to store sessions and avoid the problem altogether.\n\n## VMWare Provider\n\nUsing VMWare Fusion is a supported (but non-default) setup. There are additional steps involved to use it due to differences in how Virtual Box and VMX configure network interfaces and handle NFS mounts and you'll need to install a few additional dependencies manually.\n\nAlso note that the VMWare provider for vagrant requires an paid license in addition to the VMWare Fusion license you may already have.\n\nTo install additional dependencies, run the following commands:\n\n    brew cask install vmware-fusion vagrant-vmware-utility\n    sudo chown $(whoami) /opt/vagrant-vmware-desktop/\n\n    vagrant plugin install vagrant-vmware-desktop\n    vagrant plugin license vagrant-vmware-desktop \u003cpath_to\u003e/license.lic\n\nFinally, for NFS mounts to function, run the following to add the necessary exports to your `/etc/exports` file on the host machine and restart nfsd. Please note that the IP network range may be different on your machine. Use ifconfig to check on the vmnetX interfaces for the right IP range (If you haven't already, you'll need to attempt to start a VM for these interfaces to be created)\n\n```bash\nMAPALL=\"-mapall=$(id -u):$(grep ^admin: /etc/group | cut -d : -f 3)\"\nMOUNT_DIR=\"$(readlink /server || echo /server)\"\nprintf \"%s\\n%s\\n\" \\\n    \"$MOUNT_DIR/sites/ -alldirs -network 192.168.122.0 -mask 255.255.255.0 $MAPALL\" \\\n    \"$MOUNT_DIR/mysql/ -alldirs -network 192.168.122.0 -mask 255.255.255.0 $MAPALL\" \\\n    | sudo tee -a /etc/exports \u003e /dev/null\nsudo nfsd restart\n```\n\nStart VMs enforcing use of the `vmware_desktop` provider by using something like the following:\n\n    vagrant up web71 --provider vmware_desktop\n\n# License\nThis project is licensed under the Open Software License 3.0 (OSL-3.0). See included LICENSE file for full text of OSL-3.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidalger%2Fdevenv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavidalger%2Fdevenv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidalger%2Fdevenv/lists"}