diff --git a/.gitignore b/.gitignore index 33bf56f..3d1cf38 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ +.idea .vagrant vendor/ -composer.lock \ No newline at end of file +composer.lock +magento/ +laravel/ +symfony/ \ No newline at end of file diff --git a/README.md b/README.md index 44099b4..c68e989 100644 --- a/README.md +++ b/README.md @@ -6,13 +6,13 @@ While there is no perfect vagrant box setup that will fit the needs of everyone, Magestead is designed to be configurable like Homestead using the YAML configuration while maintaining a much easier per project workflow that ScotchBox offers. The most obvious change in Magestead is the switch from an Ubuntu box to a CentOS box. This switch is to accommodate the developers who work in a Red Hat/CentOS environment everyday and prefer the package managers and comfort of a system they know. #### What's in the box? -With a CentOS 6.6 core server using NGINX, PHP 5.6, MySQL 5.5, Redis & Memcached, you know you have a development environment with performance! +With a CentOS 6.6 core server using NGINX, PHP 5.6, MySQL 5.6, Redis & Memcached, you know you have a development environment with performance! #### The Full Stack - CentOS 6.6 - NGINX - PHP 5.6 -- MySQL 5.5 +- MySQL 5.6 - Redis - Memcached - PHPUnit @@ -67,7 +67,11 @@ The `bootstrap:` setting is a new setting to magestead and has three different o `See https://github.com/colinmollenhour/Cm_Cache_Backend_Redis for documentation.` -The second `bootstrap:` option is `laravel`. When you choose this option laravel will be downloaded and installed into a laravel directory and a symbolic link is created to the web `public` directory from your laravel `public` directory. The key is already set using composer and the directories of storage and bootstrap/cache are made writable by the server. +New to version `v1.1` is Magento 2 using the option `magento2`. This will download the latest stable release from github, currently `1.0.0-beta`, setup database and install the Magento2 software. Please note that the admin url is left to autogenerate during installation, pay attention to the output when magestead finishes running. It will prompt you with admin login credentials. + +The third `bootstrap:` option is `laravel`. When you choose this option laravel will be downloaded and installed into a laravel directory and a symbolic link is created to the web `public` directory from your laravel `public` directory. The key is already set using composer and the directories of storage and bootstrap/cache are made writable by the server. + + #### Launching The Vagrant Box diff --git a/provision/Magestead.yaml b/provision/Magestead.yaml index e8307d0..ce7b362 100644 --- a/provision/Magestead.yaml +++ b/provision/Magestead.yaml @@ -8,10 +8,13 @@ authorize: ~/.ssh/id_rsa.pub keys: - ~/.ssh/id_rsa +domain: magento.dev + databases: - magestead -# bootstrap: magento +#bootstrap: magento +bootstrap: magento2 # bootstrap: laravel # bootstrap: symfony diff --git a/provision/blackfire.sh b/provision/blackfire.sh old mode 100755 new mode 100644 diff --git a/provision/create-mysql.sh b/provision/create-mysql.sh index 76dd22e..cf4c35b 100644 --- a/provision/create-mysql.sh +++ b/provision/create-mysql.sh @@ -2,4 +2,4 @@ DB=$1; -mysql -uroot -proot -e "CREATE DATABASE IF NOT EXISTS \`$DB\` DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_unicode_ci"; +mysql -uroot -pvagrant -e "CREATE DATABASE IF NOT EXISTS \`$DB\` DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_unicode_ci"; diff --git a/provision/magento-bootstrap.sh b/provision/magento-bootstrap.sh index aa71e6f..0c81b4e 100644 --- a/provision/magento-bootstrap.sh +++ b/provision/magento-bootstrap.sh @@ -1,13 +1,41 @@ #!/usr/bin/env bash +DB=$1; +domain=$2; echo "--- Bootstrapping Magento ---" cp -R /vagrant/provision/stubs/magento-composer.json /vagrant/composer.json cd /vagrant; /usr/local/bin/composer install; +cp -R /vagrant/provision/stubs/services.xml /vagrant/magento/app/etc/services.xml; -cd /vagrant/public; +echo "--- Installing Magento ---" -/usr/local/bin/modgit init; -/usr/local/bin/modgit add Cm_Cache_Backend_Redis git://github.com/colinmollenhour/Cm_Cache_Backend_Redis.git; \ No newline at end of file +cd /vagrant/magento; + +php -f install.php -- \ +--license_agreement_accepted "yes" \ +--locale "en_GB" \ +--timezone "Europe/London" \ +--default_currency "GBP" \ +--db_host "localhost" \ +--db_name "$DB" \ +--db_user "root" \ +--db_pass "root" \ +--session_save "db" \ +--url "$domain" \ +--use_rewrites "yes" \ +--skip_url_validation "yes" \ +--use_secure "no" \ +--use_secure_admin "no" \ +--secure_base_url "$domain" \ +--admin_firstname "RichDynamix" \ +--admin_lastname "Magestead" \ +--admin_email "admin@admin.com" \ +--admin_username "admin" \ +--admin_password "password123" + +echo "Magento admin username = admin"; +echo "Magento admin password = password123"; +echo "Magento installed at http://$domain/. Remember and set your hosts file."; diff --git a/provision/magento2-bootstrap.sh b/provision/magento2-bootstrap.sh new file mode 100644 index 0000000..c93ca01 --- /dev/null +++ b/provision/magento2-bootstrap.sh @@ -0,0 +1,153 @@ +#!/usr/bin/env bash + +DB=$1; +domain=$2; + +echo "--- Bootstrapping Magento 2 ---" + +# Clone the repo +cd /vagrant; +if [ ! -d /vagrant/magento2 ]; then + echo "Cloning Magento 2 Repo" + git clone https://github.com/magento/magento2.git +fi + +echo "Setting Permissions" +# Set permissions +cd magento2; +sudo find . -type d -exec chmod 700 {} \; && sudo find . -type f -exec chmod 600 {} \; && sudo chmod +x bin/magento +/usr/local/bin/composer install; + +echo "Exporting PATH" +# Export the path to use global +export PATH=$PATH:/vagrant/magento2/bin; + +echo "Setting NGINX Server Block" +# Create the NGINX server block +block="server { + listen 80; + server_name $domain; + set \$MAGE_ROOT /vagrant/magento2; + set \$MAGE_MODE developer; + + root \$MAGE_ROOT/pub; + + index index.php; + autoindex off; + charset off; + + location / { + try_files \$uri \$uri/ /index.php?\$args; + } + + location /pub { + alias \$MAGE_ROOT/pub; + } + + location /static/ { + if (\$MAGE_MODE = \"production\") { + expires max; + } + location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ { + add_header Cache-Control \"public\"; + expires +1y; + + if (!-f \$request_filename) { + rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=\$2 last; + } + } + location ~* \.(zip|gz|gzip|bz2|csv|xml)$ { + add_header Cache-Control \"no-store\"; + expires off; + + if (!-f \$request_filename) { + rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=\$2 last; + } + } + if (!-f \$request_filename) { + rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=\$2 last; + } + } + + location /media/ { + try_files \$uri \$uri/ /get.php?\$args; + location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ { + add_header Cache-Control \"public\"; + expires +1y; + try_files \$uri \$uri/ /get.php?\$args; + } + location ~* \.(zip|gz|gzip|bz2|csv|xml)$ { + add_header Cache-Control \"no-store\"; + expires off; + try_files \$uri \$uri/ /get.php?\$args; + } + } + + location /media/customer/ { + deny all; + } + + location /media/downloadable/ { + deny all; + } + + location ~ /media/theme_customization/.*\.xml$ { + deny all; + } + + location /errors/ { + try_files \$uri =404; + } + + location ~ ^/errors/.*\.(xml|phtml)$ { + deny all; + } + + location ~ cron\.php { + deny all; + } + + location ~ (index|get|static|report|404|503)\.php$ { + try_files \$uri =404; + fastcgi_pass 127.0.0.1:9000; + fastcgi_split_path_info ^(.+\.php)(/.+)\$; + fastcgi_index index.php; + + fastcgi_param PHP_FLAG \"session.auto_start=off \n suhosin.session.cryptua=off\"; + fastcgi_param PHP_VALUE \"memory_limit=256M \n max_execution_time=600\"; + fastcgi_read_timeout 600s; + fastcgi_connect_timeout 600s; + fastcgi_param MAGE_MODE \$MAGE_MODE; + + fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name; + include fastcgi_params; + } +} +" +echo "Restart Services" +# Add the block and restart PHP-FPM and NGINX +echo "$block" > "/etc/nginx/conf.d/$domain" +sudo service nginx restart +sudo service php-fpm restart + +echo "Installing Magento 2" +# Run the setup wizard from command line +magento setup:install --base-url=http://$domain/ \ +--db-host=localhost \ +--db-name=$DB \ +--db-user=root \ +--db-password=vagrant \ +--admin-firstname=Magento \ +--admin-lastname=Admin \ +--admin-email=admin@admin.com \ +--admin-user=admin \ +--admin-password=password123 \ +--language=en_GB \ +--currency=GBP \ +--timezone=Europe/London \ +--use-rewrites=1 \ +--session-save=db + +echo "Magento admin username = admin"; +echo "Magento admin password = password123"; +echo "Magento installed at http://$domain/. Remember and set your hosts file."; diff --git a/provision/magestead.rb b/provision/magestead.rb index f543cbc..14d1dd4 100644 --- a/provision/magestead.rb +++ b/provision/magestead.rb @@ -9,11 +9,27 @@ def Magestead.configure(config, settings) # Bootstrap type bootstrap = settings["bootstrap"] ||= nil + # setup domain + domain = settings["domain"] ||= "magestead.dev" + + # Path setting + path = "/vagrant/public" + if (bootstrap == "magento") + path = "/vagrant/magento" + end + if (bootstrap == "laravel") + path = "/vagrant/laravel/public" + end + if (bootstrap == "symfony") + path = "/vagrant/symfony/web" + end + # Prevent TTY Errors config.ssh.shell = "bash -c 'BASH_ENV=/etc/profile exec bash'" # Configure The Box config.vm.box = "richdynamix/magestead" +# config.vm.box = "magestead" config.vm.hostname = settings["hostname"] ||= "magestead" # Configure A Private Network IP @@ -115,22 +131,47 @@ def Magestead.configure(config, settings) if (bootstrap == "magento") config.vm.provision "shell" do |s| s.path = scriptDir + "/magento-bootstrap.sh" - s.args = [settings["databases"][0]] - end + s.args = [settings["databases"][0], domain] + end + + config.vm.provision "shell" do |s| + s.path = scriptDir + "/server.sh" + s.args = [domain, path] + end + + end + + # Bootstrap Magento2 Intallation + if (bootstrap == "magento2") + config.vm.provision "shell" do |s| + s.path = scriptDir + "/magento2-bootstrap.sh" + s.args = [settings["databases"][0], domain] + end end # Bootstrap Laravel Intallation if (bootstrap == "laravel") config.vm.provision "shell" do |s| s.path = scriptDir + "/laravel-bootstrap.sh" - end + end + + config.vm.provision "shell" do |s| + s.path = scriptDir + "/server.sh" + s.args = [domain, path] + end + end # Bootstrap Symfony Intallation if (bootstrap == "symfony") config.vm.provision "shell" do |s| s.path = scriptDir + "/symfony-bootstrap.sh" - end + end + + config.vm.provision "shell" do |s| + s.path = scriptDir + "/server.sh" + s.args = [domain, path] + end end end diff --git a/provision/server.sh b/provision/server.sh new file mode 100644 index 0000000..a86cec9 --- /dev/null +++ b/provision/server.sh @@ -0,0 +1,111 @@ +#!/usr/bin/env bash + +block="server { + listen 80; + server_name $1; + root $2; + autoindex on; + + index index.html index.htm index.php; + + charset utf-8; + + ## + # dont log robots.txt requests + ## + location /robots.txt { + allow all; + log_not_found off; + access_log off; + } + + ## These locations would be hidden by .htaccess normally + location ^~ /app/ { deny all; } + location ^~ /includes/ { deny all; } + location ^~ /lib/ { deny all; } + location ^~ /media/downloadable/ { deny all; } + location ^~ /pkginfo/ { deny all; } + location ^~ /report/config.xml { deny all; } + location ^~ /var/ { deny all; } + location /var/export/ { deny all; } + # deny htaccess files + location ~ /\. { + deny all; + access_log off; + log_not_found off; + } + + ## + # Rewrite for versioned CSS+JS via filemtime + ## + location ~* ^.+\.(css|js)\$ { + rewrite ^(.+)\.(\d+)\.(css|js)\$ \$1.\$3 last; + expires 31536000s; + access_log off; + log_not_found off; + add_header Pragma public; + add_header Cache-Control \"max-age=31536000, public\"; + } + ## + # Aggressive caching for static files + # If you alter static files often, please use + # add_header Cache-Control \"max-age=31536000, public, must-revalidate, proxy-revalidate\"; + ## + location ~* \.(asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|eot|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|odb|odc|odf|odg|odp|ods|odt|ogg|ogv|otf|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|t?gz|tif|tiff|ttf|wav|webm|wma|woff|wri|xla|xls|xlsx|xlt|xlw|zip)\$ { + expires 31536000s; + access_log off; + log_not_found off; + add_header Pragma public; + #add_header Cache-Control \"max-age=31536000, public\"; + add_header Cache-Control \"max-age=31536000, public, must-revalidate, proxy-revalidate\"; + } + + # error pages + error_page 404 /404.html; + location = /404.html { + root /usr/share/nginx/html; + } + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } + + location / { + try_files /maintenance.html \$uri \$uri/ @handler; ## If missing pass the URI to Magento's front handler + expires 30d; ## Assume all files are cachable + } + location @handler { ## Magento uses a common front handler + rewrite / /index.php; + } + location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler + rewrite ^(.*.php)/ \$1 last; + } + + location ~ \.php$ { + #try_files \$uri =404; + + if (!-e \$request_filename) { rewrite / /index.php last; } + + expires off; + fastcgi_pass 127.0.0.1:9000; + fastcgi_split_path_info ^(.+\.php)(/.+)\$; + fastcgi_index index.php; + + fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name; + + ## Store code is defined in administration > Configuration > Manage Stores + fastcgi_param MAGE_RUN_CODE default; + fastcgi_param MAGE_RUN_TYPE store; + + include fastcgi_params; ## See /etc/nginx/fastcgi_params + + } + + rewrite ^/minify/([0-9]+)(/.*.(js|css))\$ /lib/minify/m.php?f=\$2&d=\$1 last; + rewrite ^/skin/m/([0-9]+)(/.*.(js|css))\$ /lib/minify/m.php?f=\$2&d=\$1 last; +} +" + +echo "$block" > "/etc/nginx/conf.d/$1" +sudo service nginx restart +sudo service php-fpm restart \ No newline at end of file diff --git a/provision/stubs/magento-composer.json b/provision/stubs/magento-composer.json index 60f1e57..178bb31 100644 --- a/provision/stubs/magento-composer.json +++ b/provision/stubs/magento-composer.json @@ -8,7 +8,9 @@ "require": { "aydin-hassan/magento-core-composer-installer" : "~1.0", "magento/magento" : "1.9.1.0", - "magento-hackathon/magento-composer-installer": "3.0.*" + "magento-hackathon/magento-composer-installer": "3.0.*", + "inviqa/magento-symfony-container": "0.1.2", + "colinmollenhour/cache-backend-redis": "1.8.1" }, "authors": [ { @@ -27,7 +29,7 @@ } ], "extra": { - "magento-root-dir": "public" + "magento-root-dir": "magento" }, "config": { "bin-dir": "bin" diff --git a/provision/stubs/services.xml b/provision/stubs/services.xml new file mode 100644 index 0000000..e197a71 --- /dev/null +++ b/provision/stubs/services.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file