Created
November 1, 2017 10:50
-
-
Save StyxOfDynamite/28cd33be53975edd62676b3166502eb8 to your computer and use it in GitHub Desktop.
Magento 2 - MacOS Local Setup with Valet
This file contains 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
<?php | |
// Put this file in your ~/.valet/Extensions directory! | |
/** | |
* Create a new database on your local machine. | |
*/ | |
$app->command('db [name]', function ($name) { | |
if (! $name) { | |
warning('Please specify a database name'); | |
return; | |
} | |
$create_db_command = sprintf("mysql -uroot -e \"create database %s\"", $name); | |
$create_user_command = sprintf("mysql -uroot -e \"create user '%s'@'localhost' identified by '%s'\"", $name, $name); | |
$grant_privileges_command = sprintf("mysql -uroot -e \"grant all privileges on %s.* to '%s'@'localhost'\"", $name, $name); | |
$commands = compact('create_db_command', 'create_user_command', 'grant_privileges_command'); | |
foreach ($commands as $command) { | |
if ($error = CommandLine::run($command)) { | |
warning($command); | |
warning($error); | |
return; | |
} | |
} | |
info('The database '.$name.' has been created'); | |
})->descriptions('Create a new database'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
db.php
to~/.valet/Extensions
valet db magento_2
cd /var/www/magento2 && valet link magento-2