Last active
August 2, 2018 19:52
-
-
Save kjbrum/a2076f30e472364d66da019bde50d81a to your computer and use it in GitHub Desktop.
Vagrant files for Magento 2 (Credit: https://github.com/klierik/magento2-vagrant)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
echo "==================================================" | |
echo "Setting up Magento 2 Vagrant box with..." | |
echo "- Ubuntu 14.04 LTS" | |
echo "- Apache 2.4" | |
echo "- PHP 7.0" | |
echo "- MySQL 5.6(manual)" | |
echo "- Git" | |
echo "- Node LTS (using https://github.com/tj/n)" | |
echo "- Npm packages (Grunt)" | |
echo "- Composer" | |
echo "==================================================" | |
echo "==================================================" | |
echo "SET LOCALES (1 of 11)" | |
echo "==================================================" | |
export DEBIAN_FRONTEND=noninteractive | |
export LANGUAGE=en_US.UTF-8 | |
export LANG=en_US.UTF-8 | |
export LC_TYPE=en_US.UTF-8 | |
export LC_ALL=en_US.UTF-8 | |
locale-gen en_US en_US.UTF-8 | |
dpkg-reconfigure locales | |
echo "==================================================" | |
echo "RUN UPDATE (2 of 11)" | |
echo "==================================================" | |
apt-get update | |
apt-get upgrade | |
echo "==================================================" | |
echo "INSTALLING APACHE (3 of 11)" | |
echo "==================================================" | |
apt-get -y install apache2 | |
if ! [ -L /var/www ]; then | |
rm -rf /var/www | |
ln -fs /vagrant /var/www | |
fi | |
VHOST=$(cat <<EOF | |
<VirtualHost *:80> | |
DocumentRoot "/var/www" | |
ServerName vagento.dev | |
<Directory "/var/www"> | |
AllowOverride All | |
</Directory> | |
SetEnv MAGE_IS_DEVELOPER_MODE true | |
</VirtualHost> | |
EOF | |
) | |
echo "$VHOST" > /etc/apache2/sites-available/000-default.conf | |
echo "ServerName localhost" | sudo tee /etc/apache2/conf-available/localhost.conf | |
a2enconf localhost | |
a2enmod rewrite | |
service apache2 restart | |
echo "==================================================" | |
echo "INSTALLING PHP (4 of 11)" | |
echo "==================================================" | |
apt-get -y update | |
add-apt-repository ppa:ondrej/php | |
apt-get -y update | |
apt-get -y install php7.0 php7.0-mcrypt php7.0-curl php7.0-cli php7.0-mysql php7.0-gd php7.0-intl php7.0-xsl php7.0-zip php7.0-mbstring | |
phpenmod mcrypt | |
phpenmod mbstring | |
service apache2 restart | |
echo "==================================================" | |
echo "INSTALLING GIT (5 of 11)" | |
echo "==================================================" | |
apt-get -y install git | |
echo "==================================================" | |
echo "INSTALLING NODE & NPM PACKAGES (6 of 11)" | |
echo "==================================================" | |
# Node | |
git clone https://github.com/tj/n.git | |
(cd n/; make install) | |
rm -rf n/ | |
n lts | |
# npm | |
npm install -g grunt-cli # Grunt | |
echo "==================================================" | |
echo "INSTALLING COMPOSER (7 of 11)" | |
echo "==================================================" | |
curl --silent https://getcomposer.org/installer | php | |
mv composer.phar /usr/local/bin/composer | |
cd /vagrant | |
composer install | |
echo "==================================================" | |
echo "INSTALLING and CONFIGURE NTP (8 of 11)" | |
echo "==================================================" | |
apt-get -y install ntp | |
echo "==================================================" | |
echo "INSTALLING MYSQL and CONFIGURE DATABASE (9 of 11)" | |
echo "==================================================" | |
sudo apt-get install pwgen | |
MYSQL_ROOT_PASSWORD=`pwgen 10 1` | |
MYSQL_MAGENTO_DB=magento2 | |
MYSQL_MAGENTO_USER=magento2 | |
MYSQL_MAGENTO_PASSWORD=`pwgen 10 1` | |
echo "mysql-server mysql-server/root_password password $MYSQL_ROOT_PASSWORD" | sudo debconf-set-selections | |
echo "mysql-server mysql-server/root_password_again password $MYSQL_ROOT_PASSWORD" | sudo debconf-set-selections | |
sudo apt-get -y install mysql-server-5.6 mysql-client-5.6 | |
echo "create database $MYSQL_MAGENTO_DB;" | mysql -u root -p$MYSQL_ROOT_PASSWORD | |
echo "GRANT ALL ON $MYSQL_MAGENTO_DB.* TO $MYSQL_MAGENTO_USER@localhost IDENTIFIED BY '$MYSQL_MAGENTO_PASSWORD';" | mysql -u root -p$MYSQL_ROOT_PASSWORD | |
echo "==================================================" | |
echo "INSTALLING MAGENTO 2 (10 of 11)" | |
echo "==================================================" | |
MAGENTO_ADMIN_USER=admin | |
MAGENTO_ADMIN_PASSWORD=admin123 | |
[email protected] | |
cd /vagrant/bin | |
php magento setup:install --db-user=$MYSQL_MAGENTO_USER \ | |
--db-name=$MYSQL_MAGENTO_DB --db-password=$MYSQL_MAGENTO_PASSWORD \ | |
--admin-user=$MAGENTO_ADMIN_USER --admin-password=$MAGENTO_ADMIN_PASSWORD \ | |
--admin-email=$MAGENTO_ADMIN_EMAIL --admin-firstname=Admin --admin-lastname=Admin \ | |
--base-url=http://vagento.dev/ --backend-frontname=admin \ | |
--language=en_US --currency=USD --timezone=America/Chicago | |
crontasks=`tempfile` | |
cat > $crontasks <<_EOF | |
*/1 * * * * /usr/bin/php -c /etc/php/7.0/cli/php.ini /vagrant/bin/magento cron:run | |
*/1 * * * * /usr/bin/php -c /etc/php/7.0/cli/php.ini /vagrant/update/cron.php | |
*/1 * * * * /usr/bin/php -c /etc/php/7.0/cli/php.ini /vagrant/bin/magento setup:cron:run | |
_EOF | |
crontab $crontasks && rm -f $crontasks | |
cd /vagrant | |
mv package.json.sample package.json | |
mv Gruntfile.js.sample Gruntfile.js | |
npm install | |
npm update | |
echo "==================================================" | |
echo "CLEANING (11 of 11)" | |
echo "==================================================" | |
apt-get -y autoremove | |
apt-get -y autoclean | |
echo "==================================================" | |
echo "============= INSTALLATION COMPLETE ==============" | |
echo "==================================================" | |
echo "." | |
echo "." | |
echo "." | |
echo "." | |
echo "." | |
echo "==================================================" | |
echo "=============== USEFUL INFORMATION ===============" | |
echo "==================================================" | |
echo "# MySQL DB: $MYSQL_MAGENTO_DB" | |
echo "# MySQL root password: $MYSQL_ROOT_PASSWORD" | |
echo "# MySQL $MYSQL_MAGENTO_USER password: $MYSQL_MAGENTO_PASSWORD" | |
echo "#" | |
echo "# Magento admin user: $MAGENTO_ADMIN_USER" | |
echo "# Magento admin password: $MAGENTO_ADMIN_PASSWORD" | |
echo "# Magento admin email: $MAGENTO_ADMIN_EMAIL" | |
echo "==================================================" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
Vagrant.configure("2") do |config| | |
# All Vagrant configuration is done here. The most common configuration | |
# options are documented and commented below. For a complete reference, | |
# please see the online documentation at vagrantup.com. | |
# Every Vagrant virtual environment requires a box to build off of. | |
# config.vm.box = "precise64" | |
# config.vm.box = "precise32" | |
config.vm.box = "trusty64" | |
# The url from where the 'config.vm.box' box will be fetched if it | |
# doesn't already exist on the user's system. | |
# config.vm.box_url = "http://files.vagrantup.com/precise64.box" | |
# config.vm.box_url = "http://files.vagrantup.com/precise32.box" | |
config.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box" | |
# Prefer VMware Fusion before VirtualBox | |
config.vm.provider "vmware_fusion" | |
config.vm.provider "virtualbox" | |
# Provision | |
config.vm.provision :shell, :path => "bootstrap.sh" | |
# Create a forwarded port mapping which allows access to a specific port | |
# within the machine from a port on the host machine. In the example below, | |
# accessing "localhost:8080" will access port 80 on the guest machine. | |
config.vm.network :forwarded_port, guest: 80, host: 8910 | |
config.vm.network :forwarded_port, guest: 22, host: 2210 | |
# Synced folder | |
# config.vm.synced_folder ".", "/vagrant", id: "vagrant-root", owner: "vagrant", group: "www-data", mount_options: ["dmode=775,fmode=664"] | |
config.vm.synced_folder ".", "/vagrant", id: "vagrant-root", owner: nil, group: nil, :nfs => { :mount_options => ["dmode=775","fmode=664","actimeo=1","vers=3","udp","noatime"] } | |
# VirtualBox settings | |
config.vm.provider :virtualbox do |vb| | |
# Setup our memory and cpus (use 1/2 of available) | |
host = RbConfig::CONFIG['host_os'] | |
if host =~ /darwin/ | |
memory = `sysctl -n hw.memsize`.to_i / 1024 / 1024 / 2 | |
cpus = `sysctl -n hw.ncpu`.to_i / 2 | |
elsif host =~ /linux/ | |
memory = `grep 'MemTotal' /proc/meminfo | sed -e 's/MemTotal://' -e 's/ kB//'`.to_i / 1024 / 2 | |
cpus = `nproc`.to_i / 2 | |
else # Fallback (Windows) | |
memory = 4096 | |
cpus = 2 | |
end | |
vb.customize ["modifyvm", :id, "--memory", memory] | |
vb.customize ["modifyvm", :id, "--cpus", cpus] | |
vb.customize ["modifyvm", :id, "--ioapic", "on"] # Enable using multiple cpus | |
end | |
# Host Manager | |
config.hostmanager.enabled = true | |
config.hostmanager.manage_host = true | |
config.hostmanager.ignore_private_ip = false | |
config.hostmanager.include_offline = true | |
config.vm.define 'vagento' do |node| | |
node.vm.hostname = 'vagento' | |
node.vm.network :private_network, ip: '192.168.10.10' | |
node.hostmanager.aliases = %w(vagento.dev) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Setup a Magento 2 site | |
# By: Kyle Brumm | |
# https://gist.github.com/kjbrum/a2076f30e472364d66da019bde50d81a | |
# Install Magento 2 | |
echo "Installing Magento 2..." | |
git clone [email protected]:magento/magento2.git . | |
git checkout tags/2.1.5 # Set the version you would like to use | |
rm -rf .git | |
# Download Vagrantfile | |
echo "Downloading Vagrantfile..." | |
vfile="https://gist.githubusercontent.com/kjbrum/a2076f30e472364d66da019bde50d81a/raw/magento2-vagrantfile" | |
curl -s $vfile > Vagrantfile | |
# Download bootstrap.sh | |
echo "Downloading bootstrap.sh..." | |
bfile="https://gist.githubusercontent.com/kjbrum/a2076f30e472364d66da019bde50d81a/raw/magento2-bootstrap.sh" | |
curl -s $bfile > bootstrap.sh | |
# Install Vagrant | |
echo "Installing Vagrant..." | |
vagrant up | |
# Open the website to login | |
open http://vagento.dev/admin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
One liner install: