under Apache + PHP as module you can set
php_value post_max_size 8M
inside a .htaccess.
How can I do this under Apache + PHP-FPM?
I'm using the FastCgiExternalServer directive, but want to keep the functionality within the .htaccess file (if possible).
Thank you!
I've found an somewhat elegant way to do it: .user.ini files
It seems to be the .htaccess version for PHP-FPM.
You can use
SetEnv PHP_VALUE "post_max_size = 8M"
or
SetEnv PHP_ADMIN_VALUE "post_max_size = 8M"
in the apache configuration.
Related
I have try to put these 2 lines
php_value post_max_size 30M
php_value upload_max_filesize 30M
In my root .htaccess file but that brings me "internal server error" message.
php5 is running on the server
I don't have access to php.ini so I think htaccess is my only chance.
Can you tell me where the mistake is?
php_value upload_max_filesize 30M is correct.
You will have to contact your hosters -- some don't allow you to change values in php.ini
If you are getting 500 - Internal server error that means you don't have permission to set these values by .htaccess. You have to contact your web server providers and ask to set AllowOverride Options for your host or to put these lines in their virtual host configuration file.
php_value memory_limit 30M
php_value post_max_size 100M
php_value upload_max_filesize 30M
Use all 3 in .htaccess after everything at last line. php_value post_max_size must be more than than the remaining two.
What to do to correct this is create a file called php.ini and save it in the same location as your .htaccess file and enter the following code instead:
upload_max_filesize = "250M"
post_max_size = "250M"
If your web server is running php5, I believe you must use php5_value. This resolved the same error I received when using php_value.
I also face internal server error message for inserting
php_value upload_max_filesize 5M in my .htaccess file in PHP Laravel Project from c-Panel.
Then I solve it by the following logic -
Create a file named - .user.ini in my Project root Directory
Insert the following code in .user.ini file
upload_max_filesize = 5M
post_max_size = 5M
Both commands are correct
php_value post_max_size 30M
php_value upload_max_filesize 30M
BUT to use the .htaccess you have to enable rewrite_module in Apache config file. In httpd.conf find this line:
# LoadModule rewrite_module modules/mod_rewrite.so
and remove the #.
I have try to put these 2 lines
php_value post_max_size 30M
php_value upload_max_filesize 30M
In my root .htaccess file but that brings me "internal server error" message.
php5 is running on the server
I don't have access to php.ini so I think htaccess is my only chance.
Can you tell me where the mistake is?
php_value upload_max_filesize 30M is correct.
You will have to contact your hosters -- some don't allow you to change values in php.ini
If you are getting 500 - Internal server error that means you don't have permission to set these values by .htaccess. You have to contact your web server providers and ask to set AllowOverride Options for your host or to put these lines in their virtual host configuration file.
php_value memory_limit 30M
php_value post_max_size 100M
php_value upload_max_filesize 30M
Use all 3 in .htaccess after everything at last line. php_value post_max_size must be more than than the remaining two.
What to do to correct this is create a file called php.ini and save it in the same location as your .htaccess file and enter the following code instead:
upload_max_filesize = "250M"
post_max_size = "250M"
If your web server is running php5, I believe you must use php5_value. This resolved the same error I received when using php_value.
I also face internal server error message for inserting
php_value upload_max_filesize 5M in my .htaccess file in PHP Laravel Project from c-Panel.
Then I solve it by the following logic -
Create a file named - .user.ini in my Project root Directory
Insert the following code in .user.ini file
upload_max_filesize = 5M
post_max_size = 5M
Both commands are correct
php_value post_max_size 30M
php_value upload_max_filesize 30M
BUT to use the .htaccess you have to enable rewrite_module in Apache config file. In httpd.conf find this line:
# LoadModule rewrite_module modules/mod_rewrite.so
and remove the #.
I have configured php configuration for each domain account like below in the file
/etc/sentora/configs/apache/phpconfig/domain_user.conf
That file i have made like below. For only the particular domain.
<Directory "/var/sentora/hostdata/domain_user/">
php_value upload_max_filesize 512M
php_value post_max_size 512M
php_value max_execution_time 100
php_value max_input_time 100
php_value memory_limit 512M
php_value file_uploads Off
</Directory>
Also I have configured below in the file "/etc/sentora/configs/apache/httpd.conf" correctly.
IncludeOptional /etc/sentora/configs/apache/phpconfig/*.conf
So it is working for me if i have changed my domain php version to 5.6, But its not working when I am checking after changed the php version to 7.0
It seems like when my server core php version is 5.6 its working on the version 5.6.
php_value {key} {value} was working when I used in mod_php but not in fastcgi
My phpinfo like below when its 7.0
enter image description here
And when my domain is in php 5.6 my phpinfo look like below.
enter image description here
Can anyone help me to out from this?
Thanks in advance.
Use this:
php_value auto_prepend_file /path/to/includefile/includefile.php
Then put your php_values in there
I've installed EasyPHP WAMP for local development only (I'm not hosting any websites).
Is there a way to set custom php settings for separate virtual hosts?
Currently and out-of-the-box, the php.ini file is loaded from: C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\binaries\php\php_runningversion\php.ini It would be nice if, say, I could drop in a custom php.ini file into the virtual host directory to override settings in the original php.ini This way, I could better emulate a production server's environment on a per-site basis.
I've seen this work with online hosting accounts. But I can't figure out how to make this work on my machine.
Using custom php.ini files is pretty straighforward for CGI/FastCGI based PHP installations but it isn't feasible when running PHP as Apache module (mod_php) because the whole server runs a single instance of the PHP interpreter.
My advice:
Set from PHP itself as many settings as you can:
ini_set('memory_limit', '16M');
date_default_timezone_set('Europe/Madrid')
...
In other words, directives that can be changed at runtime.
Set the rest of stuff from per-directory Apache setting files (aka .htaccess):
php_flag short_open_tag off
php_value post_max_size 50M
php_value upload_max_filesize 50M
i.e., settings that need to be defined before the script starts running
Please have a look at the Runtime Configuration for further details.
Sometimes, you'll actually need different settings in development and production. There're endless ways to solve that with PHP code (from creating a boolean constant from the $_SERVER['HTTP_HOST'] variable to just having a config.php file with different values) but it's trickier with .htaccess. I normally use the <IfDefine> directive:
<IfDefine DEV-BOX>
#
# Local server directives
#
SetEnv DEVELOPMENT "1"
php_flag display_startup_errors on
php_flag display_errors on
php_flag log_errors off
#php_value error_log ...
</IfDefine>
<IfDefine !DEV-BOX>
#
# Internet server directives
#
php_flag display_startup_errors off
php_flag display_errors off
php_flag log_errors on
php_value error_log "/home/foo/log/php-error.log"
</IfDefine>
... where DEV-BOX is a string I pass to the local Apache command-line:
C:\Apache24\bin\httpd.exe -D DEV-BOX
If you run Apache as service, the -D DEV-BOX bit can be added in the Windows registry, e.g.:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Apache2.4\Parameters\ConfigArgs
Related: Find out how PHP is running on server (CGI OR fastCGI OR mod_php)
Developing Multiple Domains on One Machine?
Embedding php.ini settings in the httpd-vhost.conf, typically found in your server root under conf/extra/, is a great way to solve this common problem. If you never knew you could do this, see the PHP.net Manual under How To Change Configuration Settings. This will solve the pesky include_path problem, without adding configuration code to your bootstrapping code or anything else.
Of course, to use this effectively as localhost, you would need to make copies of a <VirualHost> block and configure each accordingly. Then, comment out all virtual host blocks except the one that you want to use!
Alternatively, one could start Apache with the -f option to point the server daemon to a different httpd.conf upon starting. Each httpd.conf would require an "if module block," such as and <IfModule phpx_module> block. Be sure to remember to account for Apache logging!
httpd -f /usr/local/apache2/conf/domains/fooDomain.conf
httpd -f /usr/local/apache2/conf/domains/barDomain.conf
Virtual Host Block With php.ini statements.
<VirtualHost 127.0.0.1:80>
UseCanonicalName On
ServerName localhost:80
ServerAdmin you#localhost
CustomLog "/var/www/someDomain.com/data/logs/httpd_access_log" common
ErrorLog "/var/www/someDomain.com/data/logs/httpd_error_log"
LogLevel warn
DocumentRoot "/var/www/someDomain.com/public"
<Directory "/var/www/someDomain.com/public">
# disable directory listing
Options -Indexes +FollowSymLinks
AllowOverride FileInfo
Require all granted
</Directory>
<IfModule alias_module>
# Alias /webpath /full/filesystem/path
ScriptAlias /cgi-bin/ "/var/www/someDomain.com/scripts/cgi-bin/"
</IfModule>
<IfModule php7_module>
# Use php7_module in opening statement above if on PHP 7+
# Domain specific PHP configuration options.
# The Apache process user must own any of the following directories.
php_admin_value include_path "/var/www/someDomain.com/application/controllers:/var/www/someDomain.com/application/models:/var/www/someDomain.com/application/views"
# Errors and Logging
php_admin_flag display_startup_errors off
php_admin_flag display_errors off
php_admin_flag html_errors off
php_admin_flag log_errors on
php_admin_value error_log "/var/www/someDomain.com/data/logs/php_error_log"
# File Related
php_admin_flag file_uploads on
php_admin_value upload_tmp_dir "/var/www/someDomain.com/data/uploads"
php_admin_value upload_max_filesize 10M
php_admin_value max_file_uploads 5
# Sessions
php_value session.save_handler "files"
php_value session.save_path "/var/www/someDomain.com/data/sessions"
# Caching
php_value soap.wsdl_cache_dir "/var/www/someDomain.com/data/cache/sopa.wsdl"
</IfModule>
</VirtualHost>
If you could use the %{SERVER_NAME} variable in conjunction with the <IfModule phpx_module> blocks to form a compound conditional, you could have just one httpd.conf`, or include a extra/php.conf with all the domain specific PHP.ini settings (in blocks, also). However, as long as "localhost" is the domain target, it will not do what you want. Thus, my answer in the virtual host block above.
Simple way to use custom php.ini file for vhost using Fast CGI is to copy the php.ini into a folder in the host like "customini".
After that to your vhost directive and add this simple line :
FcgidInitialEnv PHPRC "/path_to_your_custom_ini_dir_for_this_vhost/"
BE SURE TO HAVE / to your path no \, (it won't work with \)
Restart Apache.
That's all!
Full sample (on Windows Server here) :
<VirtualHost *:80>
DocumentRoot "C:/APACHE/htdocs/vhost/myvhost"
ServerName www.vhost.com
FcgidInitialEnv PHPRC "C:/APACHE/customini/myvhost/"
</VirtualHost>
Several commentors have mention Vagrant which is an excellent solution.
If you're not interested in using Vagrant, you can investigate using FastCGI as your interface to Apache and using the SetEnv PHPRC... suggestion proposed on this blog:
Apache & PHP: Multiple PHP.ini Configuration Files (Sunday, February 8, 2009)
Source: http://hyponiq.blogspot.com/2009/02/apache-php-multiple-phpini.html
The second work-around is to use the PHPRC environment variable
configurable in Apache using the SetEnv directive. This directive
allows you to set an environment variable that is then passed to any
CGI script and/or Server Side Include (SSI) set in any static (x)HTML
page (or other document type). In this instance, you'd be telling each
PHP-CGI instance where to find its configuration settings. The example
would be (coinciding with the previous one):
# vhosts.conf
NameVirtualHost *:81
<VirtualHost *:81>
ServerAdmin admin#example.com
ServerName vhost.example.com
DocumentRoot "C:/path/to/doc/root"
ErrorLog "logs/vhost.example.com-errors.log"
# Set the PHPRC environment variable
SetEnv PHPRC "C:/path/to/doc/root/php.ini"
<Directory "C:/path/to/doc/root">
# ... yadda, yadda, yadda ...
# you get the point!
</Directory>
</VirtualHost>
However, the PHP documentation changing the runtime
configuration
suggests that you can use certain values like php_value to try
loaalong with, possibly the SetEnv directive.
He suggests another option not using FastCGI, instead leveraging the php_value, php_flag etc. configuration options.
Other's seem to have had some success with executing scripts through FastCGI though, see: Separate php.ini for different virtual hosts
Other suggestions involve the PHPINI directive, which may be pertinent for your needs, see: How do I limit PHP apps to their own directories and their own php.ini?
I was able to install PHPMyAdmin through the command line on my new Ubuntu server. But now when I try to access it I get "You don't have permission to access /phpmyadmin/index.php on this server.".
I believe it has to do with these lines in the .conf file for it since they refer to mod_php and I am using php-fastcgi instead of mod-php (for memory usage purposes).
<IfModule mod_php5.c>
AddType application/x-httpd-php .php
php_flag magic_quotes_gpc Off
php_flag track_vars On
php_flag register_globals Off
php_admin_flag allow_url_fopen Off
php_value include_path .
php_admin_value upload_tmp_dir /var/lib/phpmyadmin/tmp
php_admin_value open_basedir /usr/share/phpmyadmin/:/etc/phpmyadmin/:/var/lib/phpmyadmin/
</IfModule>
I have tried commenting out the tags, but the php settings don't work outside of it so there must be a way to do this with PHP FastCGI. Does anyone know how to do this?
I am new to using PHP FastCGI.
Turns out I just had to add to the option "ExecCGI" to the apache.conf file for PHPMyAdmin. I had to put this under (within) the directory tag.
You need to check the file ownership if it is for web user, on phpmyadmin directory