Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save macouella/b97e27f61285adddb9cd4d081944f209 to your computer and use it in GitHub Desktop.
Save macouella/b97e27f61285adddb9cd4d081944f209 to your computer and use it in GitHub Desktop.
Setting up a fast Magento development server for OSX

Disabling unused magento modules to speed up development

Optional - I have done some testing and the following modules are easily disabled. Run at your own discretion!

bin/magento module:disable --clear-static-content Magento_ConfigurableSampleData Magento_SampleData Magento_MsrpSampleData Magento_DownloadableSampleData Magento_BundleSampleData Magento_CustomerSampleData Magento_ThemeSampleData Magento_SwatchesSampleData Magento_TaxSampleData Magento_CmsSampleData Magento_WidgetSampleData Magento_WishlistSampleData Magento_ReviewSampleData Magento_OfflineShippingSampleData Magento_SalesRuleSampleData Magento_SalesSampleData Magento_ProductLinksSampleData Magento_GroupedProductSampleData Magento_CatalogSampleData Magento_CatalogRuleSampleData Magento_GoogleOptimizer Magento_GoogleAdwords Magento_GoogleAnalytics Magento_Analytics Magento_QuoteAnalytics Magento_CustomerAnalytics Magento_WishlistAnalytics Magento_ReviewAnalytics Magento_SalesAnalytics Amazon_Core Klarna_Core Amazon_Login Amazon_Payment Klarna_Ordermanagement Klarna_Kp Amazon_Core Klarna_Core Amazon_Login Amazon_Payment Klarna_Ordermanagement Klarna_Kp Amazon_Core Klarna_Core Amazon_Login Amazon_Payment Klarna_Ordermanagement Klarna_Kp Temando_Shipping Dotdigitalgroup_Email Magento_CatalogAnalytics Magento_Marketplace Magento_NewRelicReporting Magento_OfflinePayments Magento_Braintree Magento_Paypal Magento_Sitemap Magento_Swagger Magento_Swatches Magento_SwatchesLayeredNavigation  Magento_Ups Magento_Usps Magento_Captcha Magento_ReleaseNotification  Magento_Vault Magento_InstantPurchase Magento_LayeredNavigation Magento_Multishipping Magento_OfflineShipping Magento_ProductVideo Magento_CatalogWidget Magento_AdminNotification Magento_CurrencySymbol Magento_Dhl Magento_Weee Magento_Fedex Magento_Robots Magento_Authorizenet Magento_SendFriend Magento_Signifyd

bin/magento setup:di:compile
// Edit app/etc/env.php
[
// ... the rest of your env.php
'cache' => [
'frontend' => [
'default' => [
'backend' => 'Cm_Cache_Backend_Redis',
'backend_options' =>
[
'server' => '127.0.0.1',
'database' => '0',
'port' => '6379'
],
],
'page_cache' => [
'backend' => 'Cm_Cache_Backend_Redis',
'backend_options' => [
'server' => '127.0.0.1',
'port' => '6379',
'database' => '1',
'compress_data' => '0'
]
]
]
]
]
# /usr/local/etc/php/7.1/conf.d/ext-xdebug.ini
# After running pecl install xdebug, add this file to your php.ini. Note that the dir may differ.
# Refer to the post-install message to find out where xdebug was installed.
# Also - remove xdebug.so from php.ini
[xdebug]
zend_extension="/usr/local/Cellar/[email protected]/7.1.19/pecl/20160303/xdebug.so"
xdebug.remote_autostart = 0 # disable autostarting, as we'll manually start the debugger if we need it
# If you need it autostart to debug scripts with vscode / phpstorm
# xdebug.remote_enable = 1
# xdebug.remote_autostart = 1

Magento2 Development Server Setup

WARNING If you previously have nginx installed, valet will override your nginx.conf config! If you don't mind, skip this part. Otherwise, ensure that you back up your nginx configuration. By default, the config is here: $(brew --prefix)/etc/nginx/nginx.conf

Installing mysql

Note that we have to install 5.7 because Magento requires it. If you wish to keep your current brew mysql, replace all mysql commands below with a direct all to the 5.7 mysql bin.

brew update
brew install [email protected]
brew link [email protected] --force --overwrite
echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.zshrc-local # replace with your bash entry point
source ~/.zshrc-local
brew services start [email protected]
# Access the mysql server with mysql -u root

Installing redis

brew install redis
redis-server # runs redis
redis-cli monitor # use this to confirm that magento is connected

Installing valet

composer global require laravel/valet
echo 'export PATH=$PATH:~/.composer/vendor/bin' >> ~/.zshrc-local # replace with your bash entry script
valet install
valet trust # run valet commands without sudo

# Common commands
valet restart
valet park [dir] - maps the folder to nginx

Creating the db

You can use the mysql console as normal or through a custom valet cli command. (below)
# Copy make_db.php to ~/.valet/Extensions/
valet restart
valet db valgento # we are naming our db valgento

Okay. Now it's time for Magento

With these instructions, we'll install the latest version of Magento with sample data. If you want to change valgento.test to something else, replace all occurences of valgento in the script.

Pre reqs: Grab an accessToken pair from https://marketplace.magento.com/customer/accessKeys/.

composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition valgento # use the public private pair for username and password when prompted.
cd valgento
bin/magento setup:install --admin-firstname=FIRSTNAME --admin-lastname=LASTNAME [email protected] --admin-user=admin --admin-password='abcd123' --base-url='http://valgento.test' --db-name='valgento' --backend-frontname=admin --use-rewrites=1
bin/magento sampledata:deploy
bin/magento setup:upgrade

Optimising Magento for Development

# cd [your magento dir]
bin/magento deploy:mode:set developer
# Update env.php as per this gist (enable redis)
bin/magento cache:clean
bin/magento cache:flush

Turn on display errors

In bootstrap.php uncomment display_errors.

Turn on Logging

System > Configuration > Advanced > Developer > Log Settings > Enabled => Yes

Show errors in html

rename errors/local.xml.sample to errors/local.xml

Disable Cache

System > Cache Management > Select All [check-boxes] > Actions = Disable > Submit

Disable Compilation

System > Tools > Compilation > Disable

Next, visit valgento.test to see your hard work in action!

<?php
// Put this file in your ~/.valet/Extensions directory!
// Then restart valet
// And execute valet db [db_name] to easily create a new database. Hehe.
/**
* Create a new database on your local machine.
*/
$app->command('db [name]', function ($name) {
if(!$name) {
warning('Please specify a database name');
return;
}
if($error = CommandLine::run('mysql -uroot -e "create database '.$name.'"')) {
warning($error);
} else {
info('The database '.$name.' has been created');
}
})->descriptions('Create a new database');

OSX PHP setup

Install brew

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Install PHP. Replace 71 with your preferred version

brew update
brew install php71
brew install composer
sudo mkdir /usr/local/sbin
sudo chown -R $(whoami) /usr/local/sbin
brew link php71 --force

# tip: brew doctor shows problems with your setup
# Ensure php71 is in the path, replace .zshrc-local with your own entry bash script
echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.zshrc-local
echo 'export PATH="/usr/local/opt/[email protected]/sbin:$PATH"' >> ~/.zshrc-local
echo 'ALIAS

source ~/.zshrc-local

pecl install xdebug

Test the install

composer -V
pear version
php --ini # shows config files, check that the xdebug ini file you created above was loaded.
# /usr/local/etc/php/7.1/conf.d/php-memory-limits.ini
; Max memory per instance
memory_limit = -1
;The maximum size of an uploaded file.
upload_max_filesize = 512M
;Sets max size of post data allowed. This setting also affects file upload. To upload large files, this value must be larger than upload_max_filesize
post_max_size = 512M
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment