Set php.ini Values Using .htaccess

Written by David Walsh on Tuesday, November 4, 2008


Did you know that you can set php.ini values right inside the .htaccess file? It’s actually very easy.

The .htaccess Code

#format
php_value setting_name setting_value

#example
php_value  upload_max_filesize  10M

Of course you could simply place these in the .htaccess file, but .htaccess is a viable alternative if your host doesn’t allow you to touch the php.ini file.


Follow via RSS Epic Discussion

Commenter Avatar November 04 / #
Elmas says:

I’ll be needing something like that soon enough, thx for the tip :)

Commenter Avatar November 04 / #
quard says:

Yeah, but this is not worked if PHP working as FastCGI :)

Commenter Avatar November 04 / #
Binny V A says:

Another option is setting it in PHP – using the ini_set() function.

Commenter Avatar November 04 / #
Ahmed says:

huh @guard?

So this could work for httpd.conf’s values too? Or this one cannot be overridden?

Commenter Avatar November 04 / #

I actually used this just the other day. I was trying to use the “Import” feature of WordPress to import a bunch of posts and crap from an “Export” of another WordPress blog (XML File). WordPress was telling me there was a piddly 2MB limit. But apparently, this isn’t a limitation of WordPress but rather set by PHP running on the server. I upped it, but apparently it maxed at 8MB on my server, which was 2MB too small for my 10MB file. Booooo.

Commenter Avatar November 04 / #

I’ll remember that one, thanks !

.htaccess has a lot of capabilities, do you know if there’s a reference for it, or a listing of the possibilities somewhere ?

Commenter Avatar November 05 / #
quard says:

@Ahmed: php_flag and _php_value can be written in httpd.conf in FastCGI, but not in .htaccess file. if PHP is running as module, you can do anything with .htaccess

David Walsh November 05 / #
david says:

@Chris Coyier: The upload limit is the one I change the most.

@Antoine Leclair: I haven’t found one great one — Google usually yields the best results.

Commenter Avatar November 06 / #
Name says:

Another way to do it is to use PHP’s native ini_set() function

Commenter Avatar November 06 / #
fred says:

Readers may be interested by reading this page on the PHP documentation : How to change configuration settings. That is said you can also use the ini_set php function, which is an alternative to the .htaccess method.

@Antoine Leclair: There is always the official documentation. You can find it for the last version of Apache, and you have a .htaccess tutorial.

Commenter Avatar November 07 / #
Иван says:

Consider reading the following, to get better understading of .htaccess and how it works. It really depends on your httpd.conf what you can do with the .htaccess file.

http://httpd.apache.org/docs/2.2/howto/htaccess.html
http://httpd.apache.org/docs/2.2/mod/core.html#allowoverride

Commenter Avatar May 21 / #

Wow that’s exactly what I needed to simplify my life. Thank you!

Of course you could simply place
these in the .htaccess file, but
.htaccess is a viable alternative if
your host doesn’t allow you to touch
the .htaccess file.

Maybe you meant httpd.conf? Or php.ini?

Commenter Avatar December 18 / #
divyesh says:

hi,
i am using mootools ans jquery and ligthbox in my project. but i have not access jquery with lightbox.

http://www.immobelgica.be/en/search/apartment/for-sale/belgium/east__flanders/aalst/38548/5/

in above url i have user jquery for thumb image move on mouse hover and when click on image that time i user lightbox for vieew image. that is ok but i also use lightbox for email to friend and page is not open in middle and same window like image.

please reply me on my mail..

have a nice time

Thank for help..

Commenter Avatar December 21 / #

I am not an experienced coder. I have access to the .htaccess file. What exactly do I need to put in the file to increase my Upload file size limit? I’d greatly appreciate any help. Thank you all!

Be Heard!

I want to hear what you have to say! Share your comments and questions below.

Name*:
Email*:
Website:  


© David Walsh 2007-2010. Contact David Walsh. Powered by the remarkable MooTools javascript framework.