diff --git a/README.md b/README.md index 8b8435c..691ddf0 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ If you have valet or valet+ installed. It is recommended to remove it first: 8. Run the `valet install` command. Optionally add `--with-mariadb` to use MariaDB instead of MySQL This will configure and install Valet+ and DnsMasq, and register Valet's daemon to launch when your system starts. 9. Once Valet+ is installed, try pinging (or just visit [http://foobar.test](http://foobar.test) any `*.test` domain on your terminal using a command such as `ping -c1 foobar.test`. If Valet+ is installed correctly you should see this domain responding on `127.0.0.1`. If not you might have to restart your system. Especially when coming from the Dinghy (docker) solution. -> :info: If you get something like "Site can't be reached." Try to change the domain like so +> :information_source: If you get something like "Site can't be reached." Try to change the domain like so > `valet domain host` ## Differences from Valet+ diff --git a/Todo.md b/Todo.md new file mode 100644 index 0000000..5a1153c --- /dev/null +++ b/Todo.md @@ -0,0 +1,4 @@ +# Todo List + +- [ ] Code cleanup (sprintf, backslash php methods etc) +- [ ] Pipline tests diff --git a/bin/ngrok b/bin/ngrok old mode 100755 new mode 100644 index d91fa50..e69de29 Binary files a/bin/ngrok and b/bin/ngrok differ diff --git a/cli/Valet/Mysql.php b/cli/Valet/Mysql.php index fac49a6..ce4bc58 100644 --- a/cli/Valet/Mysql.php +++ b/cli/Valet/Mysql.php @@ -17,6 +17,13 @@ class Mysql const MYSQL_FORMULA_NAME = 'mysql@'; const MYSQL_57_VERSION = '5.7'; + const MARIA_DB = 'mariadb'; + const MYSQL_80_VERSION = '8.0'; + const SUPPORTED_MYSQL_FORMULAE = [ + 'mysql5.7' => self::MYSQL_FORMULA_NAME . self::MYSQL_57_VERSION, + 'mysql8.0' => self::MYSQL_FORMULA_NAME . self::MYSQL_80_VERSION, + 'mariadb' => self::MARIA_DB + ]; const MYSQL_57_FORMULA = self::MYSQL_FORMULA_NAME . self::MYSQL_57_VERSION; const MYSQL_DEFAULT_FORMULA = self::MYSQL_57_FORMULA; @@ -59,7 +66,7 @@ public function __construct( * * @param $type */ - public function install($type = 'mysql@5.7') + public function install($type = self::MYSQL_DEFAULT_FORMULA) { $this->verifyType($type); $currentlyInstalled = $this->installedVersion(); @@ -71,7 +78,7 @@ public function install($type = 'mysql@5.7') $this->files->copy(__DIR__ . '/../stubs/limit.maxfiles.plist', static::MAX_FILES_CONF); $this->cli->quietly('launchctl load -w ' . static::MAX_FILES_CONF); - if (!$this->installedVersion()) { + if (!$currentlyInstalled) { $this->brew->installOrFail($type); } @@ -87,6 +94,52 @@ public function install($type = 'mysql@5.7') } } + /** + * Switch between versions of installed MySQL. Switch to the provided version. + * + * @param $version + * + * @return void + */ + public function switchTo(string $version): void + { + $currentVersion = $this->installedVersion(); + + if (!\array_key_exists($version, self::SUPPORTED_MYSQL_FORMULAE)) { + throw new DomainException("This version of MySQL is not available. The following versions are available: " . implode( + ' ', + \array_keys(self::SUPPORTED_MYSQL_FORMULAE) + )); + } + + // If the current version equals that of the current MySQL version, do not switch. + if ($version === $currentVersion) { + info('Already on this version'); + return; + } + + $installed = $this->brew->installed(self::SUPPORTED_MYSQL_FORMULAE[$version]); + if (!$installed) { + $this->brew->ensureInstalled(self::SUPPORTED_MYSQL_FORMULAE[$version]); + } + + // Unlink the current PHP version. + if (!$this->unlinkMysql($currentVersion)) { + return; + } + + $this->stop(); + $this->install(); + + + $shell = \preg_replace('/\s+/', '', $this->cli->runAsUser('echo $SHELL')); + $mysqlPath = \preg_replace('/\s+/', '', $this->cli->runAsUser('which mysql')); + $this->cli->runAsUser(\sprintf('export PATH="%s:$PATH" >> %s', $mysqlPath, $shell)); + $this->cli->runAsUser('source ' . $shell); + + info("Valet is now using " . self::SUPPORTED_MYSQL_FORMULAE[$version]); + } + /** * check if type is valid. * @@ -97,7 +150,7 @@ public function install($type = 'mysql@5.7') public function verifyType($type) { if (!\in_array($type, $this->supportedVersions())) { - throw new DomainException('Invalid Mysql type given. Available: mysql@5.7/mariadb'); + throw new DomainException('Invalid Mysql type given. Available: ' . \implode('/', self::SUPPORTED_MYSQL_FORMULAE)); } } @@ -108,7 +161,7 @@ public function verifyType($type) */ public function supportedVersions() { - return ['mysql@5.7', 'mariadb']; + return self::SUPPORTED_MYSQL_FORMULAE; } /** @@ -130,7 +183,7 @@ public function installedVersion($default = false) * * @param string $type */ - private function removeConfiguration($type = 'mysql@5.7') + private function removeConfiguration($type = self::MYSQL_DEFAULT_FORMULA) { $this->files->unlink(static::MYSQL_CONF); $this->files->unlink(static::MYSQL_CONF . '.default'); @@ -141,7 +194,7 @@ private function removeConfiguration($type = 'mysql@5.7') */ public function stop() { - $version = $this->installedVersion('mysql@5.7'); + $version = $this->installedVersion(self::MYSQL_DEFAULT_FORMULA); info('[' . $version . '] Stopping'); $this->cli->quietly('sudo brew services stop ' . $version); @@ -153,7 +206,7 @@ public function stop() * * @param string $type */ - public function installConfiguration($type = 'mysql@5.7') + public function installConfiguration($type = self::MYSQL_DEFAULT_FORMULA) { info('[' . $type . '] Configuring'); @@ -164,7 +217,7 @@ public function installConfiguration($type = 'mysql@5.7') } $contents = $this->files->get(__DIR__ . '/../stubs/my.cnf'); - if ($type === 'mariadb') { + if ($type === self::MARIA_DB) { $contents = \str_replace('show_compatibility_56=ON', '', $contents); } @@ -179,11 +232,35 @@ public function installConfiguration($type = 'mysql@5.7') */ public function restart() { - $version = $this->installedVersion() ?: 'mysql@5.7'; + $version = $this->installedVersion() ?: self::MYSQL_DEFAULT_FORMULA; info('[' . $version . '] Restarting'); $this->cli->quietlyAsUser('brew services restart ' . $version); } + + /** + * Unlink a MySQL version, removing the binary symlink. + * + * @param $version + * @return bool + */ + private function unlinkMySQL(string $version): bool + { + $isUnlinked = true; + + info("[$version] Unlinking"); + output($this->cli->runAsUser('brew unlink ' . $version, function () use (&$isUnlinked) { + $isUnlinked = false; + })); + if ($isUnlinked === false) { + warning("Could not unlink MySQL version!" . PHP_EOL . + "There appears to be an issue with your MySQL $version installation!" . PHP_EOL . + "See the output above for more information."); + } + + return $isUnlinked; + } + /** * Set root password of Mysql. * @param string $oldPwd @@ -193,7 +270,7 @@ public function setRootPassword($oldPwd = '', $newPwd = self::MYSQL_ROOT_PASSWOR { $alreadyRootPW = $this->cli->runAsUser('mysql -u root -proot -e"quit"'); - if(strpos($alreadyRootPW, 'mysql: [Warning] Using a password on the command line interface can be insecure.') !== false) { + if (\strpos($alreadyRootPW, 'mysql: [Warning] Using a password on the command line interface can be insecure.') !== false) { info('[mysql] Password of root user is already set to root'); return; } diff --git a/cli/Valet/Pecl.php b/cli/Valet/Pecl.php index 5a60544..72ebc23 100644 --- a/cli/Valet/Pecl.php +++ b/cli/Valet/Pecl.php @@ -43,7 +43,7 @@ class Pecl extends AbstractPecl */ const EXTENSIONS = [ self::XDEBUG_EXTENSION => [ - '7.4' => '2.9.0', + '7.4' => '2.9.5', '7.3' => '2.9.0', '7.2' => '2.9.0', '7.1' => '2.9.2', @@ -53,7 +53,7 @@ class Pecl extends AbstractPecl 'extension_type' => self::ZEND_EXTENSION_TYPE ], self::APCU_EXTENSION => [ - '7.4' => '5.1.17', + '7.4' => '5.1.18', '7.3' => '5.1.17', '7.2' => '5.1.17', '7.1' => '5.1.17', @@ -70,7 +70,7 @@ class Pecl extends AbstractPecl 'extension_type' => self::NORMAL_EXTENSION_TYPE ], self::MEMCACHE_EXTENSION => [ - '7.4' => '3.1.3', + '7.4' => '3.1.5', '7.3' => '3.1.3', '7.2' => '3.1.3', '7.1' => '3.1.3', diff --git a/cli/Valet/PeclCustom.php b/cli/Valet/PeclCustom.php index 086b1b3..048af4e 100644 --- a/cli/Valet/PeclCustom.php +++ b/cli/Valet/PeclCustom.php @@ -53,6 +53,7 @@ class PeclCustom extends AbstractPecl */ const EXTENSIONS = [ self::IONCUBE_LOADER_EXTENSION => [ + '7.4' => 'https://downloads.ioncube.com/loader_downloads/ioncube_loaders_dar_x86-64.tar.gz', '7.3' => 'https://downloads.ioncube.com/loader_downloads/ioncube_loaders_dar_x86-64.tar.gz', '7.2' => 'https://downloads.ioncube.com/loader_downloads/ioncube_loaders_dar_x86-64.tar.gz', '7.1' => 'https://downloads.ioncube.com/loader_downloads/ioncube_loaders_dar_x86-64.tar.gz', @@ -139,7 +140,7 @@ public function install(string $extension, string $url): void $extensionDirectory = $this->getExtensionDirectory(); $extensionAlias = $this->getExtensionAlias($extension); - if ($this->extensionIsMissing($extensionDirectory, $extensionAlias)) { + if ($this->extensionIsMissing($extensionDirectory)) { info("[PECL-CUSTOM] $extension is not available from PECL, downloading from: $url"); $this->downloadExtension( diff --git a/cli/Valet/PhpFpm.php b/cli/Valet/PhpFpm.php index ad288cc..b0f926d 100644 --- a/cli/Valet/PhpFpm.php +++ b/cli/Valet/PhpFpm.php @@ -13,6 +13,7 @@ class PhpFpm const PHP_V72_VERSION = '7.2'; const PHP_V73_VERSION = '7.3'; const PHP_V74_VERSION = '7.4'; + const PHP_DEFAULT_VERSION = self::PHP_V74_VERSION; const SUPPORTED_PHP_FORMULAE = [ self::PHP_V56_VERSION => self::PHP_FORMULA_NAME . self::PHP_V56_VERSION, @@ -26,7 +27,8 @@ class PhpFpm const EOL_PHP_VERSIONS = [ self::PHP_V56_VERSION, self::PHP_V70_VERSION, - self::PHP_V71_VERSION + self::PHP_V71_VERSION, + self::PHP_V72_VERSION ]; const LOCAL_PHP_FOLDER = '/usr/local/etc/valet-php/'; @@ -66,7 +68,7 @@ public function __construct(Brew $brew, CommandLine $cli, Filesystem $files, Pec public function install(): void { if (!$this->hasInstalledPhp()) { - $this->brew->ensureInstalled($this->getFormulaName(self::PHP_V71_VERSION)); + $this->brew->ensureInstalled($this->getFormulaName(self::PHP_DEFAULT_VERSION)); } if (!$this->brew->hasTap(self::VALET_PHP_BREW_TAP)) { @@ -508,20 +510,20 @@ public function fix(bool $reinstall = false): void output($this->cli->runAsUser('brew uninstall php74')); } - // If the current php is not 7.2, link 7.2. + // set default php version + // If the current php is not the given default, link it. info('Installing and linking new PHP homebrew/core version.'); - output($this->cli->runAsUser('brew uninstall ' . self::SUPPORTED_PHP_FORMULAE[self::PHP_V72_VERSION])); - output($this->cli->runAsUser('brew install ' . self::SUPPORTED_PHP_FORMULAE[self::PHP_V72_VERSION])); - output($this->cli->runAsUser('brew unlink ' . self::SUPPORTED_PHP_FORMULAE[self::PHP_V72_VERSION])); - output($this->cli->runAsUser('brew link ' . self::SUPPORTED_PHP_FORMULAE[self::PHP_V72_VERSION] . ' --force --overwrite')); + output($this->cli->runAsUser('brew uninstall ' . self::SUPPORTED_PHP_FORMULAE[self::PHP_DEFAULT_VERSION])); + output($this->cli->runAsUser('brew install ' . self::SUPPORTED_PHP_FORMULAE[self::PHP_DEFAULT_VERSION])); + output($this->cli->runAsUser('brew unlink ' . self::SUPPORTED_PHP_FORMULAE[self::PHP_DEFAULT_VERSION])); + output($this->cli->runAsUser('brew link ' . self::SUPPORTED_PHP_FORMULAE[self::PHP_DEFAULT_VERSION] . ' --force --overwrite')); if ($this->brew->hasTap(self::DEPRECATED_PHP_TAP)) { info('[brew] untapping formulae ' . self::DEPRECATED_PHP_TAP); $this->brew->unTap(self::DEPRECATED_PHP_TAP); } - warning("Please check your linked php version, you might need to restart your terminal!" . - "\nLinked PHP should be php 7.2:"); + warning(\sprintf("Please check your linked php version, you might need to restart your terminal! \nLinked PHP should be php %s:", self::PHP_DEFAULT_VERSION)); output($this->cli->runAsUser('php -v')); } diff --git a/cli/Valet/Script.php b/cli/Valet/Script.php index 2974a82..b14b44b 100644 --- a/cli/Valet/Script.php +++ b/cli/Valet/Script.php @@ -37,7 +37,7 @@ public function portCheck(): void $result = $this->cli->run($command); if($result !== '') { - warning(sprintf('%s port (%s) is already in use.', $service, $port)); + info(sprintf('%s port (%s) is already in use.', $service, $port)); } } } diff --git a/cli/includes/compatibility.php b/cli/includes/compatibility.php index 0cd6f13..8005125 100644 --- a/cli/includes/compatibility.php +++ b/cli/includes/compatibility.php @@ -11,6 +11,7 @@ exit(1); } +//@TODO: do we really need this check? if (PHP_VERSION_ID <= 70200) { echo 'Valet requires PHP 7.2 or later.'; diff --git a/cli/includes/helpers.php b/cli/includes/helpers.php index e87f017..4a0c163 100644 --- a/cli/includes/helpers.php +++ b/cli/includes/helpers.php @@ -8,7 +8,7 @@ * Define the ~/.valet path as a constant. */ define('VALET_HOME_PATH', $_SERVER['HOME'] . '/.valet'); -define('VALET_SERVER_PATH', realpath(__DIR__ . '/../../server.php')); +define('VALET_SERVER_PATH', \realpath(__DIR__ . '/../../server.php')); define('VALET_STATIC_PREFIX', '41c270e4-5535-4daa-b23e-c269744c2f45'); /** diff --git a/cli/templates/404.php b/cli/templates/404.php index d51be9f..41e7788 100755 --- a/cli/templates/404.php +++ b/cli/templates/404.php @@ -13,163 +13,162 @@ - - -
-
-
-
-
-
- + + +
+
+
+
+
+
+ +
+
-
-
-