.htaccess produces 500 Internal Server Error - apache

The content of .htaccess is:
php_value upload_max_filesize 64M
Works on localhost, screws up every hosting server I upload it to.
The error.log says: Invalid command 'php_value', perhaps misspelled or defined by a module not included in the server configuration
Is there another way to change the upload_max_filesize?

If php_value is not recognized as a valid command, it may be because PHP is not installed as an Apache module. Create a php file with the following contents:
<?php phpinfo();
Run the file to show your PHP configuration. Search the page (Ctr+F) for "mod_php". If you don't find it anywhere, this explains your problem.
If you have access to php.ini, you may be able to fix your problem by editing that file instead. At the phpinfo page, look at the value under Loaded Configuration File for the location of the file to edit. On Linux, it will be something such as /usr/local/lib/php.ini
Open the ini file (it's just a text file) and look for the setting you want to change. If it's not present, just add a line and set it as desired: upload_max_filesize=64M
Save the file and restart the Apache server.

If you don't want to remove the php_flag command in .htaccess but want to avoid the error, wrap the command as follows:
<IfModule mod_php5.c>
php_flag display_errors 0
php_flag display_startup_errors 0
</IfModule>
If you're using PHP7, use <IfModule mod_php7.c>

For other readers with the same problem and access to the server, this could also be caused by a misconfiguration of PHP as a module of apache. You can fix it reinstalling the module (or configuring the route to libphp.so by yourself in php.ini).
Have in mind that purge will remove the configuration of the packages which usually is nothing to worry, but you are warned just in case.
sudo apt-get purge libapache2-mod-php libapache2-mod-php7.2
sudo apt-get install libapache2-mod-php

The problem was the hosting provider, they only allow changing this via php.ini

It seems like the php module is not loaded. Make sure, it is installed with
sudo apt-get install libapache2-mod-php
and check if it is enabled in apache with
ll /etc/apache2/mods-enabled/*php*
if it is installed but not enabled, enable it (depending on your php-version) e.g. for PHP 8.0 with
sudo a2enmod php8.0.load
and restart apache
sudo apache2ctl graceful

I too was receiving a 500 internal server error. My error log showed:
Invalid command 'php_value', perhaps misspelled or defined by a module not included in the server configuration
I tried updating upload_max_filesize as suggested but it didn't work for me. The last line of my .htaccess file had:
php_value max_execution_time 120
I removed that line and the site resolved perfectly.

Create .user.ini file
Add the line upload_max_filesize="5M"

Related

Apache - ScriptAlias: Command not found

When I try to run the command ScriptAlias, I always get the error:
ScriptAlias: command not found
I have made sure that the alias mod is enabled through a2enmod alias, and I have ran apt-get update a few times as well. Does anyone know what could be causing this?
I realized that I did not understand how the module worked, and was trying to use the command directly into the command line. I needed to edit the 000-default.conf file instead.

display_errors set to On but shows Off in phpinfo()

I'm on OS X 10.9 (though, it was the same in 10.8)
I'm trying to get display_errors set to On but can't figure it out. I didn't have a php.ini file in /etc so I copied /etc/php.ini.default cp /etc/php.ini.default /etc/php.ini.
I then went into /etc/php.ini and uncommented the line display_errors and set it to On - display_errors=On. Saved the file and went to phpinfo().
For "Configuration File (php.ini)" Path it shows "/etc" and for "Loaded Configuration File" it shows "/etc/php.ini" so I assume that means it's using the correct php.ini file right?
But, when I scroll down in phpinfo() it shows "display_errors" as Off for both Local Value and Master Value.
What am I doing wrong? Is there another place I need to turn display_errors On? I'm using PHP 5.4.17
Edit: Forgot to mention that I've restarted apache several times with sudo apachectl restart and still no change.
Also, I found it weird that before I copied php.ini.default to /etc/php.ini, php was presumably using some default php.ini file but display_errors was still set to Off. Isn't that On by default?
h2ooooooo got it figured out. I uncommented the wrong section to set it to On. It was turing back off later down the page. All good now.

Could not open configuration file /etc/apache2/apache2.conf: No such file or directory

I have just installed Ubuntu & starting with LAMP.
I installed it & it was working just fine till I installed uTorrent. Then after localhost was not opening & I tried with stopping apache & again restarting with it.
I used - sudo service apache2 restart
Now this error is coming - Could not open configuration file /etc/apache2/apache2.conf: No such file or directory
I checked there, there is no such file with this name.
Installed uTorrent is running on 8080 port...can it be problem ?
I really don't know what to do.
Is there an /etc/apache2/httpd.conf ?
If there is, have a look inside it and see what is being included i.e look for anything along the lines of:
Include /etc/apache2/apache2.conf
Basically there error is being thrown because of an incorrect pathname in a Include directive in a conf file

Configuration Issues with PECL and PHP-FPM

I'm using Ubuntu Natty. I recently installed NGINX 1.0.6 and PHP 5.3.8 (with --enable-fpm) from source. Everything went ok and I tested it with an info.php page with phpinfo().
I then installed APC and Memcache using PECL i.e. pecl install apc, etc. That seemed to go ok as well.
However, when I edit my php.ini file and add the extension_dir and extension modules for both APC and Memcache, I get the following when I restart PHP.
Starting php-fpm PHP Warning: Module 'apc' already loaded in Unknown on line 0
<br />
<b>Warning</b>: Module 'apc' already loaded in <b>Unknown</b> on line <b>0</b><br />
PHP Warning: Module 'memcache' already loaded in Unknown on line 0
<br />
<b>Warning</b>: Module 'memcache' already loaded in <b>Unknown</b> on line <b>0</b><br />
done
When I open the info.php file to check what loaded, everything seems ok i.e. I see APC and Memcache references in the information.
But when I uncomment the extensions i.e. ;extension=apc.so and ;extension=memcache.so, there are no errors, but the APC and Memcache listings in PHPinfo no longer appear.
I'm not sure how these extensions are being loaded twice and from where. I'd appreciate some guidance.
Thanks in advance.
EDIT
I'm using PHP-FPM and using lsof -i -P it appears that I have multiple pools of PHP-FPM running. Could this be part of the problem why I am seeing this error?! Is there a way to fix this?!
When you run: php --ini, do you get this:
Configuration File (php.ini) Path: /etc/php5
Loaded Configuration File: /etc/php5/php.ini
Scan for additional .ini files in: /etc/php5
Additional .ini files parsed: /etc/php5/php.ini
If yes, you should re-run your configure script so not to specify the additional ini file directory.

How can I make PHP display the error instead of giving me 500 Internal Server Error [duplicate]

This question already has answers here:
How can I get useful error messages in PHP?
(41 answers)
Closed 5 years ago.
This has never happened before. Usually it displays the error, but now it just gives me a 500 internal server error. Of course before, when it displayed the error, it was different servers. Now I'm on a new server (I have full root, so if I need to configure it somewhere in the php.ini, I can.) Or perhaps its something with Apache?
I've been putting up with it by just transferring the file to my other server and running it there to find the error, but that's become too tedious. Is there a way to fix this?
Check the error_reporting, display_errors and display_startup_errors settings in your php.ini file. They should be set to E_ALL and "On" respectively (though you should not use display_errors on a production server, so disable this and use log_errors instead if/when you deploy it). You can also change these settings (except display_startup_errors) at the very beginning of your script to set them at runtime (though you may not catch all errors this way):
error_reporting(E_ALL);
ini_set('display_errors', 'On');
After that, restart server.
Use php -l <filename> (that's an 'L') from the command line to output the syntax error that could be causing PHP to throw the status 500 error. It'll output something like:
PHP Parse error: syntax error, unexpected '}' in <filename> on line 18
It's worth noting that if your error is due to .htaccess, for example a missing rewrite_module, you'll still see the 500 internal server error.
Be careful to check if
display_errors
or
error_reporting
is active (not a comment) somewhere else in the ini file.
My development server refused to display errors after upgrade to
Kubuntu 16.04 - I had checked php.ini numerous times ... turned out that there was a diplay_errors = off; about 100 lines below my
display_errors = on;
So remember the last one counts!
Try not to go
MAMP > conf > [your PHP version] > php.ini
but
MAMP > bin > php > [your PHP version] > conf > php.ini
and change it there, it worked for me...
Enabling error displaying from PHP code doesn't work out for me. In my case, using NGINX and PHP-FMP, I track the log file using grep. For instance, I know the file name mycode.php causes the error 500, but don't know which line. From the console, I use this:
/var/log/php-fpm# cat www-error.log | grep mycode.php
And I have the output:
[04-Apr-2016 06:58:27] PHP Parse error: syntax error, unexpected ';' in /var/www/html/system/mycode.php on line 1458
This helps me find the line where I have the typo.
If all else fails try moving (i.e. in bash) all files and directories "away" and adding them back one by one.
I just found out that way that my .htaccess file was referencing a non-existant .htpasswd file. (#silly)