{"componentChunkName":"component---src-templates-blog-post-js","path":"/blog/highlighting-phps-files-in-nginx","result":{"data":{"allGhostPost":{"edges":[{"node":{"title":"Highlighting .phps Files in Nginx","html":"

In most Apache and mod_php setups, .phps are not executed as php files, but are rather passed to mod_php which highlights them as PHP code and displays them to the browser.

\n

When I switched to Nginx, I still wanted to share php files that way. A quick and easy way to "fix" that is as follows:

\n

Example: info.phps

\n\n

The whole thing is made out of 1 file: phps.php

\n

Once you download that file:

\n
    \n
  1. Put it in a directory that has a recursive o+x (all its parents have o+x)
  2. \n
  3. Chown the files to you:you
  4. \n
  5. Chmod the files 664
  6. \n
\n

All that is left now is the Nginx configuration:

\n
location ~ \\.phps$ {\n    try_files $uri =404;\n    fastcgi_pass    unix:/var/run/php5-fpm.sock;\n    fastcgi_param   DOCUMENT_ROOT    $document_root;\n    fastcgi_param   SCRIPT_NAME      $uri;\n    fastcgi_param   SCRIPT_FILENAME  /path/to/phps.php;\n    include fastcgi_params;\n}\n
\n

And you are done! Rehash Nginx and voila!

\n","published_at":"2012-12-26T21:24:00.000+02:00","slug":"highlighting-phps-files-in-nginx","tags":[],"plaintext":"In most Apache and mod_php setups, .phps are not executed as php files, but are\nrather passed to mod_php which highlights them as PHP code and displays them to\nthe browser.\n\nWhen I switched to Nginx, I still wanted to share php files that way. A quick\nand easy way to \"fix\" that is as follows:\n\nExample: info.phps [http://kmlnsr.me/info.phps]\n\nThe whole thing is made out of 1 file: phps.php [http://kmlnsr.me/phps.phps]\n\nOnce you download that file:\n\n 1. Put it in a directory that has a recursive o+x (all its parents have o+x)\n 2. Chown the files to you:you\n 3. Chmod the files 664\n\nAll that is left now is the Nginx configuration:\n\nlocation ~ \\.phps$ {\n try_files $uri =404;\n fastcgi_pass unix:/var/run/php5-fpm.sock;\n fastcgi_param DOCUMENT_ROOT $document_root;\n fastcgi_param SCRIPT_NAME $uri;\n fastcgi_param SCRIPT_FILENAME /path/to/phps.php;\n include fastcgi_params;\n}\n\n\nAnd you are done! Rehash Nginx and voila!","meta_description":null}}]}},"pageContext":{"slug":"highlighting-phps-files-in-nginx","prev":"duplicity-amazon-s3-backups","next":"mirroring-private-git-repositories-locally-the-easy-way"}},"staticQueryHashes":["3649515864"]}