Skip to content

Commit

Permalink
bump versions and change default mysql and php versions
Browse files Browse the repository at this point in the history
dump versions for mysql, php, xdebug, apcu, memcache etc
change default php version from 7.2 to 7.4
change default mysql version from 5.7 to 8.0
  • Loading branch information
marcofaul committed Jul 14, 2020
1 parent 3f8e8cf commit 73aafd0
Show file tree
Hide file tree
Showing 14 changed files with 238 additions and 154 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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+
Expand Down
4 changes: 4 additions & 0 deletions Todo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Todo List

- [ ] Code cleanup (sprintf, backslash php methods etc)
- [ ] Pipline tests
Binary file modified bin/ngrok
100755 → 100644
Binary file not shown.
97 changes: 87 additions & 10 deletions cli/Valet/Mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand All @@ -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);
}

Expand All @@ -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.
*
Expand All @@ -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));
}
}

Expand All @@ -108,7 +161,7 @@ public function verifyType($type)
*/
public function supportedVersions()
{
return ['mysql@5.7', 'mariadb'];
return self::SUPPORTED_MYSQL_FORMULAE;
}

/**
Expand All @@ -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');
Expand All @@ -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);
Expand All @@ -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');

Expand All @@ -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);
}

Expand All @@ -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
Expand All @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions cli/Valet/Pecl.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down
3 changes: 2 additions & 1 deletion cli/Valet/PeclCustom.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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(
Expand Down
20 changes: 11 additions & 9 deletions cli/Valet/PhpFpm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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/';
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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'));
}

Expand Down
2 changes: 1 addition & 1 deletion cli/Valet/Script.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
Expand Down
1 change: 1 addition & 0 deletions cli/includes/compatibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.';

Expand Down
2 changes: 1 addition & 1 deletion cli/includes/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

/**
Expand Down
Loading

0 comments on commit 73aafd0

Please sign in to comment.