Running phar file from browser

Hi
I am trying to run a simple phar file from a web browser with apache.
I got this from the PHP manual

<?php
// creating the phar archive:
try {
    $phar = new Phar('myphar.phar');
    $phar['index.php'] = '<?php echo "Hello World"; ?>';
    $phar['index.phps'] = '<?php echo "Hello World"; ?>';
    $phar->setStub('<?php
Phar::webPhar();
__HALT_COMPILER(); ?>');
} catch (Exception $e) {
    // handle error here
}
?>

The manual says

display Hello World if one browses to /myphar.phar/index.php

However when I do this I get a Not Found

If I navigate to /myphar.phar I still get Not Found but the phar file is downloaded.

How do I set things up so that phar file will work as expected?

Here is how I am attempting to access

https://192.168.100.226/myphar.phar/

I solved this by adding the following to the httpd.conf

AddType application/x-httpd-php .php .phar

3 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.