Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update issues with valet on arch linux #141

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cli/Valet/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ public function prune(): void
*/
public function get(string $key, $default = null)
{
if (!$this->files->exists($this->path())) {
return $default;
}

$config = $this->read();

return array_key_exists($key, $config) ? $config[$key] : $default;
Expand Down
6 changes: 6 additions & 0 deletions cli/Valet/Contracts/PackageManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,10 @@ public function restartNetworkManager(): void;
* Get package name by service
*/
public function packageName(string $name): string;

/**
* This function will determine whether a package manager supports versioned
* packages e.g php78-cli, php-78-gd etc
*/
public function supportsVersionedPackages(): bool;
}
4 changes: 4 additions & 0 deletions cli/Valet/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ public function get(string $path): string
*/
public function put(string $path, string $contents, ?string $owner = null): string
{
if (!$this->exists($path)) {
$this->ensureDirExists(dirname($path), user());
}

$status = file_put_contents($path, $contents);

if ($owner) {
Expand Down
6 changes: 5 additions & 1 deletion cli/Valet/Nginx.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ public function uninstall(): void
*/
public function configuredSites(): Collection
{
if (!$this->files->exists(VALET_HOME_PATH . '/Nginx')) {
return collect([]);
}

return collect($this->files->scandir(VALET_HOME_PATH . '/Nginx'))
->reject(function ($file) {
return str_starts_with($file, '.');
Expand Down Expand Up @@ -176,7 +180,7 @@ public function installServer($phpVersion = null): void
*/
private function rewriteSecureNginxFiles(): void
{
$domain = $this->configuration->get('domain');
$domain = $this->configuration->get('domain', 'test');

$this->siteSecure->reSecureForNewDomain($domain, $domain);
}
Expand Down
9 changes: 9 additions & 0 deletions cli/Valet/PackageManagers/Apt.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,13 @@ public function packageName(string $name): string
}
throw new \InvalidArgumentException(\sprintf('Package not found by %s', $name));
}

/**
* This function will determine whether a package manager supports versioned
* packages e.g php78-cli, php-78-gd etc
*/
public function supportsVersionedPackages(): bool
{
return true;
}
}
9 changes: 9 additions & 0 deletions cli/Valet/PackageManagers/Dnf.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,13 @@ public function packageName(string $name): string
}
throw new \InvalidArgumentException(\sprintf('Package not found by %s', $name));
}

/**
* This function will determine whether a package manager supports versioned
* packages e.g php78-cli, php-78-gd etc
*/
public function supportsVersionedPackages(): bool
{
return true;
}
}
9 changes: 9 additions & 0 deletions cli/Valet/PackageManagers/Eopkg.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,13 @@ public function packageName(string $name): string
}
throw new \InvalidArgumentException(\sprintf('Package not found by %s', $name));
}

/**
* This function will determine whether a package manager supports versioned
* packages e.g php78-cli, php-78-gd etc
*/
public function supportsVersionedPackages(): bool
{
return true;
}
}
9 changes: 9 additions & 0 deletions cli/Valet/PackageManagers/PackageKit.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,13 @@ public function packageName(string $name): string
}
throw new \InvalidArgumentException(\sprintf('Package not found by %s', $name));
}

/**
* This function will determine whether a package manager supports versioned
* packages e.g php78-cli, php-78-gd etc
*/
public function supportsVersionedPackages(): bool
{
return true;
}
}
9 changes: 9 additions & 0 deletions cli/Valet/PackageManagers/Pacman.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,13 @@ public function packageName(string $name): string
}
throw new \InvalidArgumentException(\sprintf('Package not found by %s', $name));
}

/**
* This function will determine whether a package manager supports versioned
* packages e.g php78-cli, php-78-gd etc
*/
public function supportsVersionedPackages(): bool
{
return false;
}
}
9 changes: 9 additions & 0 deletions cli/Valet/PackageManagers/Yum.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,13 @@ public function packageName(string $name): string
}
throw new \InvalidArgumentException(\sprintf('Package not found by %s', $name));
}

/**
* This function will determine whether a package manager supports versioned
* packages e.g php78-cli, php-78-gd etc
*/
public function supportsVersionedPackages(): bool
{
return false;
}
}
17 changes: 13 additions & 4 deletions cli/Valet/PhpFpm.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function install(?string $version = null, bool $installExt = true): void
{
$version = $version ?: $this->getCurrentVersion();
$version = $this->normalizePhpVersion($version);
if ($version === '') {
if ($version === '' && !$this->pm->supportsVersionedPackages()) {
return;
}

Expand Down Expand Up @@ -297,9 +297,18 @@ private function installExtensions(string $version): void
{
$extArray = [];
$extensionPrefix = $this->pm->getPhpExtensionPrefix($version);
foreach (self::COMMON_EXTENSIONS as $ext) {
$extArray[] = "{$extensionPrefix}{$ext}";

if (($this->pm instanceof \Valet\PackageManagers\Pacman)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, instead of adding if else statement here, can we relay on methods from PackageManager?

Copy link
Author

@Stephan-MC Stephan-MC Aug 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, i have to leave it as such since php for pacman automatically ships in with all extensions (except php-apache, php-apcu, php-cgi, php-dblib, php-embed, php-enchant,php-geoip, php-gd which am not sure if they're all php extensions).

The only package needed by valet here is php-gd. Don't know how it works for other package managers though.

Please enlighten me on how i can takle this problem

foreach (self::COMMON_EXTENSIONS as $ext) {
$extArray[] = "{$extensionPrefix}{$ext}";
}

} else {
foreach (['gd'] as $ext) {
$extArray[] = "{$extensionPrefix}{$ext}";
}
}

$this->pm->ensureInstalled(implode(' ', $extArray));
}

Expand Down Expand Up @@ -400,6 +409,6 @@ private function validateIsolationVersion(string $version): void
*/
private function getDefaultVersion(): string
{
return $this->normalizePhpVersion(PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION);
return !$this->pm->supportsVersionedPackages() ? '' : $this->normalizePhpVersion(PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION);
}
}
4 changes: 4 additions & 0 deletions cli/Valet/SiteSecure.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ private function unTrustCa(): void
*/
private function trustCa(string $caPemPath): void
{
if (!$this->files->exists($this->caCertificatePath)) {
$this->caCertificatePath = str_replace('local/', '', $this->caCertificatePath);
}

$this->files->copy($caPemPath, sprintf('%s%s.crt', $this->caCertificatePath, $this->caCertificatePem));
$this->cli->run('sudo update-ca-certificates');

Expand Down
43 changes: 29 additions & 14 deletions cli/Valet/Valet.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,22 +142,27 @@ public function migrateConfig(): void
return;
}

// Fetch FPM running process
$fpmVersions = $this->getRunningFpmVersions($oldHomePath);
$fpmVersions = [];

// Stop running fpm services
if (count($fpmVersions)) {
foreach ($fpmVersions as $fpmVersion) {
PhpFpmFacade::stop($fpmVersion);
if ($this->files->isDir($oldHomePath)) {
// Fetch FPM running process
$fpmVersions = $this->getRunningFpmVersions($oldHomePath);

// Stop running fpm services
if (count($fpmVersions)) {
foreach ($fpmVersions as $fpmVersion) {
PhpFpmFacade::stop($fpmVersion);
}
}
}

if ($this->files->exists($oldHomePath . '/valet.sock')) {
PhpFpmFacade::stop();
}
if ($this->files->exists($oldHomePath . '/valet.sock')) {
PhpFpmFacade::stop();
}

// Copy directory
$this->files->copyDirectory($oldHomePath, $newHomePath);

// Copy directory
$this->files->copyDirectory($oldHomePath, $newHomePath);
}

// Replace $oldHomePath to $newHomePath in Certificates, Valet.conf file
$this->updateNginxConfFiles();
Expand Down Expand Up @@ -194,15 +199,24 @@ private function updateNginxConfFiles(): void
$oldHomePath = OLD_VALET_HOME_PATH;
$nginxPath = $newHomePath . '/Nginx';

$siteConfigs = $this->files->scandir($nginxPath);
$siteConfigs = [];

if ($this->files->isDir($nginxPath)) {
$siteConfigs = $this->files->scandir($nginxPath);
}

foreach ($siteConfigs as $siteConfig) {
$filePath = \sprintf('%s/%s', $nginxPath, $siteConfig);
$content = $this->files->get($filePath);
$content = str_replace($oldHomePath, $newHomePath, $content);
$this->files->put($filePath, $content);
}

$sitesAvailableConf = $this->files->get(Nginx::SITES_AVAILABLE_CONF);
$sitesAvailableConf = '';
if ($this->files->exists(Nginx::SITES_AVAILABLE_CONF)) {
$sitesAvailableConf = $this->files->get(Nginx::SITES_AVAILABLE_CONF);
}

$sitesAvailableConf = str_replace($oldHomePath, $newHomePath, $sitesAvailableConf);
$this->files->put(Nginx::SITES_AVAILABLE_CONF, $sitesAvailableConf);

Expand All @@ -216,6 +230,7 @@ private function getRunningFpmVersions(string $homePath): array
$runningVersions = [];

$files = $this->files->scandir($homePath);

foreach ($files as $file) {
preg_match('/valet(\d)(\d)\.sock/', $file, $matches);
if (count($matches) >= 2) {
Expand Down
2 changes: 1 addition & 1 deletion cli/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
Configuration::install();
Nginx::install();
PhpFpm::install();
DnsMasq::install(Configuration::get('domain'));
DnsMasq::install(Configuration::get('domain', 'test'));
Mailpit::install();
ValetRedis::install();
Nginx::restart();
Expand Down