Jaslabs: High performance Software

High Performance Software

How to override php.ini

This tip is for people running apache and php. I know it works with freebsd version 5.0/php 4.X/apache 2.X. I am not sure about other operating systems/webservers/php versions.

As an example scenario, A client of mine needed a php script that would allow him to upload any type of file to his server. He also wanted the default max of 4 mb to changed to 30mb. His website was being hosted on a shared server, so there was no access to php.ini. Here is how this can be done.

1) Create a file called .htaccess in the same directory as your php script (this will apply to any php script that is in this directory).

2) for each value you want to override, use the following format: php_value php_var_name php_var_value

Example:

php_value memory_limit 34M
php_value post_max_size 33M
php_value upload_max_filesize 32M
php_value max_execution_time 600

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • DZone
  • Slashdot
  • StumbleUpon
  • Technorati

7 Comments so far

  1. Matt November 13th, 2006 6:26 am

    Thanks! My scenario exactly.

  2. justin November 13th, 2006 4:50 pm

    No problem! I’m glad our articles could help you out.

  3. Colin March 1st, 2007 6:34 am

    Hi,
    I confirm it works on Debian Sarge with PHP 5.2.1 and Apache 2.2.

    Thanx for the advice!

  4. sjake April 19th, 2007 8:47 am

    Thanx! Had some trouble figuring out how to override upload_max_filesize until I came across your site. Keep up the good work.

  5. Adnan April 28th, 2007 10:40 am

    Thanks for this … came in very handy! :)

    Adnan.

  6. Ismail September 21st, 2007 5:00 am

    this worked great

    Thanks

  7. Sarab January 31st, 2008 5:59 am

    Hii

    plz let me know how to override the dynamic extension.
    i want to override PDF extension. the name of the extension is :extension=php_pdf.dll

    Thanks.
    Sarab

Leave a reply