Htaccess php tips and tricks for the Apache HTTPD Web Server, mostly these tips show you how to run customized versions with customized php.ini files, I require custom php.ini files because they are so useful!

Even more detailed php tips can be found at custom php.ini tips and tricks

Table of Contents

  1. Introduction
    1. PHP htaccess tips
      1. Setup PHP when run as CGI / suexec
      2. Use a custom php.ini with mod_php or php as a cgi
        1. PHP run as Apache Module (mod_php)
        2. Custom php.ini with wrapper for FastCGI and PHP
      3. htaccess Guide Sections

« Custom HTTP Headers | .htaccess Tutorial Index | » SEO Search Engine Friendly Redirects without mod_rewrite


PHP htaccess tips

  • When php run as CGI
  • Use a custom php.ini with mod_php or php as a cgi
    • When php run as Apache Module (mod_php)
    • When cgi php is run with wrapper (FastCGI)

Setup PHP when run as CGI / suexec

Place your php.ini file in the dir of your cgi'd php, in this case /cgi-bin/, .htaccess might look something like:

AddHandler php-cgi .php .htm
Action php-cgi /askapache.com/cgi-bin/php5.cgi

Use a custom php.ini with mod_php or php as a cgi

Article: Custom PHP.ini tips and tricks

PHP run as Apache Module (mod_php)

Add this to your root .htaccess file. Say your php.ini is in folder /askapache.com/ini/

SetEnv PHPRC /askapache.com/ini

Custom php.ini with wrapper for FastCGI and PHP

You can use FastCGI on php by creating a php binary for cgi execution, then you create a fcgi wrapper script that execs the php using FastCGI

Article: Custom php.ini/FastCGI/DreamHost

#!/bin/sh
export PHP_FCGI_CHILDREN=3
export PHPRC=/askapache.com/ini
exec /askapache.com/cgi-bin/php.cgi
# or
#exec /askapache.com/cgi-bin/php.cgi -c /askapache.com/ini/php.ini

htaccess Guide Sections

  • htaccess tricks for Webmasters
  • HTTP Header control with htaccess
  • PHP on Apache tips and tricks
  • SEO Redirects without mod_rewrite
  • mod_rewrite examples, tips, and tricks
  • HTTP Caching and Site Speedups
  • Authentication on Apache
  • htaccess Security Tricks and Tips
  • SSL tips and examples
  • Variable Fun (mod_env) Section
  • .htaccess Security with MOD_SECURITY
  • SetEnvIf and SetEnvIfNoCase Examples

« Custom HTTP Headers | .htaccess Tutorial Index | » SEO Search Engine Friendly Redirects without mod_rewrite


PHP htaccess tips and tricks - AskApache

Charles Torvalds
10 Apr 2007

  • Site Map WireShark GNU Non-GNU Tor Project cURL TLDP - Documentation
  • Htaccess Files Hacking Htaccess Javascript Linux Optimization PHP Security Shell Scripting WordPress
  • Base64 Image Converter Raw HTTP Header Debugger Graphical ASCII Text Generator Mac Address Vendor Lookup Who Am I – Your IP Information Request Method Security Scanner .htpasswd file Generator Compress CSS DNS Tracer
Copyright © 2025 AskApache
  • Site Map
  • Htaccess Files
  • Hacking
  • Htaccess
  • Javascript
  • Linux
  • Optimization
  • PHP
  • Security
  • Shell Scripting
  • WordPress
  • Base64 Image Converter
  • Raw HTTP Header Debugger
  • Graphical ASCII Text Generator
  • Mac Address Vendor Lookup
  • Who Am I – Your IP Information
  • Request Method Security Scanner
  • .htpasswd file Generator
  • Compress CSS
  • DNS Tracer
Exit mobile version