Skip to content

First stab at a prototype for revamping the download instructions page #1287

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

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
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
68 changes: 68 additions & 0 deletions downloads-get-instructions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
$file = 'unknown';
$latestPhpVersion = '8.4';

if (!isset($options)) {
$options = [
'os' => '',
'usage' => '',
'version' => '',
];
}

if ($options['os'] === 'windows') {
if ($options['osvariant'] === 'windows-wsl-debian') {
$options['os'] = 'linux';
$options['osvariant'] = 'linux-debian';
}
if ($options['osvariant'] === 'windows-wsl-ubuntu') {
$options['os'] = 'linux';
$options['osvariant'] = 'linux-ubuntu';
}
}
if ($options['os'] === 'osx') {
if ($options['version'] === 'default') {
$options['version'] = $latestPhpVersion;
}
}

if (in_array($options['usage'], ['fw-drupal', 'fw-laravel', 'fw-symfony', 'fw-wordpress'])) {
$file = "{$options['usage']}";
$options['os'] = null;
}

$multiversion = false;

if (array_key_exists('multiversion', $options)) {
$multiversion = $options['multiversion'] === 'Y';
}

switch ($options['os']) {
case 'linux':
$defaultOrCommunity = ($options['version'] !== 'default' || $multiversion) ? 'community' : 'default';
if ($defaultOrCommunity === 'community' && $options['version'] == 'default') {
$options['version'] = $latestPhpVersion;
}
$file = "{$options['osvariant']}-{$options['usage']}-{$defaultOrCommunity}";
break;
case 'osx':
case 'windows':
$file = "{$options['osvariant']}";
break;
}

$version = $options['version'];
$versionNoDot = str_replace('.', '', $version);

if (file_exists(__DIR__ . "/include/download-instructions/{$file}.php")) {
include __DIR__ . "/include/download-instructions/{$file}.php";
return true;
} else {
?>
<p>
There are no instructions yet. Try using the generic installation from source.
</p>
<?php
return false;
}
?>
217 changes: 154 additions & 63 deletions downloads.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
// Try to make this page non-cached
header_nocache();

$SHOW_COUNT = 4;

$SIDEBAR_DATA = '
<div class="panel">
<a href="/supported-versions.php">Supported Versions</a>
Expand Down Expand Up @@ -39,12 +37,155 @@
"current" => "downloads",
],
);

function option(string $value, string $desc, $attributes = []): string
{
return '<option value="' . $value . '"' . implode(' ', array_keys(array_filter($attributes))) . '>' . $desc . '</option>';
}

$usage = [
'web' => 'Web Development',
'cli' => 'CLI/Library Development',
'fw-drupal' => 'Drupal Development',
'fw-laravel' => 'Laravel Development',
'fw-symfony' => 'Symfony Development',
'fw-wordpress' => 'WordPress Development',
];

$os = [
'linux' => [
'name' => 'Linux',
'variants' => [
'linux-debian' => 'Debian',
'linux-fedora' => 'Fedora',
'linux-redhat' => 'RedHat',
'linux-ubuntu' => 'Ubuntu',
],
],
'osx' => [
'name' => 'macOS',
'variants' => [
'osx-homebrew' => 'Homebrew/Brew',
'osx-homebrew-php' => 'Homebrew/Homebrew-PHP',
'osx-macports' => 'MacPorts',
],
],
'windows' => [
'name' => 'Windows',
'variants' => [
'windows-native' => 'Windows Native Build',
'windows-chocolatey' => 'Windows with Chocolatey',
'windows-scoop' => 'Windows with Scoop',
'windows-wsl-debian' => 'Windows with WSL/Debian',
'windows-wsl-ubuntu' => 'Windows with WSL/Ubuntu',
],
],
];

$versions = [
'8.4' => 'version 8.4',
'8.3' => 'version 8.3',
'8.2' => 'version 8.2',
'8.1' => 'version 8.1',
'default' => 'OS default version',
];

$defaults = [
'os' => 'linux',
'version' => 'default',
'usage' => 'web',
];

$options = array_merge($defaults, $_GET);
if (!array_key_exists('osvariant', $options) || !array_key_exists($options['osvariant'], $os[$options['os']]['variants'])) {
$options['osvariant'] = array_key_first($os[$options['os']]['variants']);
}
?>
<h1>Downloads &amp; Installation Instructions</h1>

<form class="instructions-form" id="instructions-form">
<div class="instructions-row">
I want to use PHP for
<select id="usage" name="usage">
<?php foreach ($usage as $value => $description) { ?>
<?= option($value, $description, [
'selected' => array_key_exists('usage', $options) && $options['usage'] === $value,
]); ?>
<?php } ?>
</select>.
</div>

<div class="instructions-row">
I work with
<select id="os" name="os">
<?php foreach ($os as $value => $item) { ?>
<?= option($value, $item['name'], [
'selected' => array_key_exists('os', $options) && $options['os'] === $value,
]); ?>
<?php } ?>
</select>

<?php if (array_key_exists('os', $options) && array_key_exists('osvariant', $options)) { ?>
<select id="osvariant" name="osvariant">
<?php foreach ($os[$options['os']]['variants'] as $value => $description) { ?>
<?= option($value, $description, [
'selected' => $options['osvariant'] === $value,
]); ?>
<?php } ?>
</select>
<?php } ?>,
and use
<select id="version" name="version">
<?php foreach ($versions as $value => $version) { ?>
<?= option($value, $version, [
'selected' => array_key_exists('version', $options) && $options['version'] === $value,
]); ?>
<?php } ?>
</select>
</div>

<label for="multiversion" class="instructions-label">
I want to be able to use multiple PHP versions:
<input type="checkbox" id="multiversion" name="multiversion" value="Y"
<?= array_key_exists('multiversion', $options) && $options['multiversion'] === 'Y' ? 'checked' : '' ?>/>
</label>
<!--
<label for="source" class="instructions-label">
I want to compile everything from source:
<input type="checkbox" id="source" name="source" value="Y"
<?= array_key_exists('source', $options) && $options['source'] === 'Y' ? 'checked' : '' ?>/>
</label>
-->
<noscript>
<button type="submit" class="button">Update Instructions</button>
</noscript>
</form>

<h2>Instructions</h2>
<div id="instructions" class="instructions">
<?php $instructionsShown = include 'downloads-get-instructions.php'; ?>
</div>

<?php if (!$instructionsShown): ?>

<h2>Source Code</h2>
<?php show_source_releases(); ?>

<hr>
<h2>GPG Keys</h2>
<p>
<a href="/manual/install.general.php">Installing PHP</a> is covered
thoroughly in the PHP documentation.
The releases are tagged and signed in the <a href='git.php'>PHP Git Repository</a>.
The following official GnuPG keys of the current PHP Release Manager can be used
to verify the tags:
</p>

<?php gpg_key_show_keys(true /* activeOnly */); ?>

<p>
<a href="gpg-keys.php">
A full list of GPG keys used for current and older releases is also
available.
</a>
</p>

<h2>Binaries</h2>
Expand All @@ -65,67 +206,17 @@
</ul>
</p>

<h2>Source Code</h2>
<?php $i = 0; foreach ($RELEASES as $MAJOR => $major_releases): /* major releases loop start */
$releases = array_slice($major_releases, 0, $SHOW_COUNT);
?>
<a id="v<?php echo $MAJOR; ?>"></a>
<?php foreach ($releases as $v => $a): ?>
<?php $mver = substr($v, 0, strrpos($v, '.')); ?>
<?php $stable = $i++ === 0 ? "Current Stable" : "Old Stable"; ?>

<h3 id="v<?php echo $v; ?>" class="title">
<span class="release-state"><?php echo $stable; ?></span>
PHP <?php echo $v; ?>
(<a href="/ChangeLog-<?php echo $MAJOR; ?>.php#<?php echo urlencode($v); ?>" class="changelog">Changelog</a>)
</h3>
<div class="content-box">
<?php endif; ?>

<ul>
<?php foreach ($a['source'] as $rel): ?>
<li>
<?php download_link($rel['filename'], $rel['filename']); ?>
<span class="releasedate"><?php echo date('d M Y', strtotime($rel['date'])); ?></span>
<?php
if (isset($rel['md5'])) echo '<span class="md5sum">', $rel['md5'], '</span>';
if (isset($rel['sha256'])) echo '<span class="sha256">', $rel['sha256'], '</span>';
?>
<?php if (isset($rel['note']) && $rel['note']): ?>
<p>
<strong>Note:</strong>
<?php echo $rel['note']; ?>
</p>
<?php endif; ?>
</li>
<?php endforeach; ?>
<li>
<a href="https://windows.php.net/download#php-<?php echo urlencode($mver); ?>">
Windows downloads
</a>
</li>
</ul>
<script>
window.onload = function () {
let form = document.getElementById("instructions-form")

<a href="#gpg-<?php echo $mver; ?>">GPG Keys for PHP <?php echo $mver; ?></a>
</div>
<?php endforeach; ?>
<?php endforeach; /* major releases loop end */ ?>

<hr>
<h2>GPG Keys</h2>
<p>
The releases are tagged and signed in the <a href='git.php'>PHP Git Repository</a>.
The following official GnuPG keys of the current PHP Release Manager can be used
to verify the tags:
</p>

<?php gpg_key_show_keys(true /* activeOnly */); ?>

<p>
<a href="gpg-keys.php">
A full list of GPG keys used for current and older releases is also
available.
</a>
</p>
form.addEventListener('change', function () {
form.submit();
});
}
</script>

<?php
site_footer(['sidebar' => $SIDEBAR_DATA]);
6 changes: 6 additions & 0 deletions include/download-instructions/fw-drupal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<p>
Instructions for installing PHP for Drupal development can be found on:
</p>
<p>
» <a href='https://www.drupal.org/docs/getting-started/installing-drupal'>https://www.drupal.org/docs/getting-started/installing-drupal</a>
</p>
6 changes: 6 additions & 0 deletions include/download-instructions/fw-laravel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<p>
Instructions for installing PHP for Laravel development can be found on:
</p>
<p>
» <a href='https://laravel.com/docs/12.x/installation#installing-php'>https://laravel.com/docs/12.x/installation#installing-php</a>
</p>
6 changes: 6 additions & 0 deletions include/download-instructions/fw-symfony.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<p>
Instructions for installing PHP for Symfony development can be found on:
</p>
<p>
» <a href='https://symfony.com/doc/current/setup.html'>https://symfony.com/doc/current/setup.html</a>
</p>
6 changes: 6 additions & 0 deletions include/download-instructions/fw-wordpress.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<p>
Instructions for installing PHP for WordPress development can be found on:
</p>
<p>
» <a href='https://wordpress.org/support/article/how-to-install-wordpress/'>https://wordpress.org/support/article/how-to-install-wordpress/</a>
</p>
12 changes: 12 additions & 0 deletions include/download-instructions/linux-debian-cli-community.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<p>
On the command line, run the following commands:
</p>
<pre class="shellCommands">
sudo apt-get update
sudo apt-get install -y lsb-release ca-certificates apt-transport-https curl
sudo curl -sSLo /tmp/debsuryorg-archive-keyring.deb https://packages.sury.org/debsuryorg-archive-keyring.deb
sudo dpkg -i /tmp/debsuryorg-archive-keyring.deb
sudo sh -c 'echo "deb [signed-by=/usr/share/keyrings/debsuryorg-archive-keyring.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" &gt; /etc/apt/sources.list.d/php.list'
sudo apt-get update
sudo apt-get install -y php<?= $version; ?>
</pre>
7 changes: 7 additions & 0 deletions include/download-instructions/linux-debian-cli-default.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<p>
On the command line, run the following commands:
</p>
<pre class="shellCommands">
sudo apt update
sudo apt install -y php
</pre>
10 changes: 10 additions & 0 deletions include/download-instructions/linux-fedora-cli-community.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<p>
On the command line, run the following commands:
</p>
<pre class="shellCommands">
sudo dnf install -y dnf-plugins-core
sudo dnf install -y https://rpms.remirepo.net/fedora/remi-release-$(rpm -E %fedora).rpm
sudo dnf module reset php -y
sudo dnf module enable php:remi-<?= $version; ?> -y
sudo dnf install -y php
</pre>
6 changes: 6 additions & 0 deletions include/download-instructions/linux-fedora-cli-default.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<p>
On the command line, run the following commands:
</p>
<pre class="shellCommands">
sudo dnf install -y php
</pre>
Loading