Right now, running the Joomla CLI Application requires typing something like php /path/to/site/cli/joomla.php blah:blah
.
Most PHP CLI applications —especially Symfony-based ones— can be called directly, e.g. /path/to/site/cli/joomla.php blah:blah
This constantly gets me. I imagine it's just as annoying for other console power users.
Add the shebang at the top of the file, i.e. the first line of the file should be
#!/usr/bin/env php
Also make the file executable, i.e. chmod +x cli/joomla.php
Installing by a ZIP file does not carry over the UNIX permissions. We might want to tell users to chmod +x cli/joomla.php
somewhere in the documentation?
On Windows the shebang does nothing outside the WSL2. However, it also does NOT produce output — the PHP CLI binary strips it silently. I know this for a fact, as demonstrated by Composer, countless PHP CLI applications, and my own PHP CLI scripts and tools.
Labels |
Added:
No Code Attached Yet
|
Labels |
Added:
?
|
Hi @nyni123
$ ls -l cli/joomla.php
-rwxr-xr-x 1 nicholas staff 3064 Apr 9 15:58 cli/joomla.php
$ head -n 1 cli/joomla.php
#!/usr/bin/env php
$ cli/joomla.php -V
Joomla! 4.3.0-rc3-dev (debug: Yes)
I'll do it myself in a few minutes.
Nope, there are no adverse effects. This is also what most PHP CLI tools do:
# WP-CLI
$ head -n 1 `which wp`
#!/usr/bin/env php
$ ls -l `which wp`
lrwxr-xr-x 1 nicholas admin 29 Feb 25 09:09 /opt/homebrew/bin/wp -> ../Cellar/wp-cli/2.7.1/bin/wp
# Composer
$ head -n 1 `which composer`
#!/usr/bin/env php
$ ls -l `which composer`
lrwxr-xr-x 1 nicholas admin 37 Feb 25 09:09 /opt/homebrew/bin/composer -> ../Cellar/composer/2.5.4/bin/composer
# PHPCS
$ head -n1 `which phpcs`
#!/usr/bin/env php
$ ls -l `which phpcs`
-rwxr-xr-x 1 nicholas staff 3366 Aug 8 2022 /Users/nicholas/.composer/vendor/bin/phpcs
# Rector
$ head -n1 `which rector`
#!/usr/bin/env php
$ ls -l `which rector`
-rwxr-xr-x 1 nicholas staff 3333 Aug 8 2022 /Users/nicholas/.composer/vendor/bin/rector
# PHING
$ head -n1 `which phing`
#!/usr/bin/env php
$ ls -l `which phing`
-rwxr-xr-x 1 nicholas staff 3324 Jul 25 2022 /Users/nicholas/.composer/vendor/bin/phing
# PHPStan
$ head -n1 `which phpstan`
#!/usr/bin/env php
$ ls -l `which phpstan`
-rwxr-xr-x 1 nicholas staff 3330 Dec 30 12:10 /Users/nicholas/.composer/vendor/bin/phpstan
# (My own) Akeeba UNiTE
$ head -n1 `which unite`
#!/usr/bin/env php
$ ls -l `which unite`
-rwxr-xr-x 1 root wheel 1149632 Apr 9 16:05 /usr/local/bin/unite
On any system which has a compatible PHP version in the $PATH
you're able to execute these CLI applications by just calling them as any other executable. This has been tested by yours truly on macOS, Ubuntu Server 20.04, Tuxedo OS 2 (a Debian-based desktop Linux distro), and Windows 11 WSL2.
On any system which does not understand shebangs (e.g. Windows 11 using PowerShell or CMD) it just doesn't execute unless you put the PHP-CLI binary in front of the file path, e.g.
c:\php\php81\php-cli.exe cli/joomla.php -V
Regardless of whether you use the above command line or associate .php files with the PHP CLI binary, the PHP CLI executable on Windows does not print out the shebang, as explicitly documented:
The special shebang first line for Unix does no harm on Windows (as it's formatted as a PHP comment), so cross platform programs can be written by including it.
I can confirm this is the case. I have been using Composer, Phing and various other PHP CLI tools —both third party and my own— on all three major platforms (Windows, macOS, Linux) for years and they all had the shebang.
If you have any other questions I will be glad to answer them, albeit a bit slowly as I'm on Easter vacation :)
Closing as having a pull request.
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2023-04-09 20:33:31 |
Closed_By | ⇒ | richard67 |
Hi @nikosdion ,
Thank you for bringing up this issue and proposing a solution to make the Joomla CLI Application more user-friendly. Before I start working on this, I would like to clarify some details with you.
Your answers will help me better understand the issue and how I can proceed with implementing the proposed solution.
Thank you in advance for your response!