We can easily execute a PHP file on our remote server (using SSH) as part of a Bash script:
ssh host "php /scripts/clear-cache.php"
In the example above, we run the clear-cache.php
file on our remote server (for example, within a Bash script that deploys a new version to production).
Of course, replace host
with the actual host defined in the SSH config
file or use the connection details (user@host
).
As mentioned in php.net, the -f
option (php -f
) is optional so we can directly provide the path of the file that needs to be run.