Enable php-logging on server of godaddy hosted wordpress - php

for about a day I'm trying to find a way to see php logs on a server by godaddy where wordpress is hosted.
I can ssh to the server, but I'm not able to edit the php.ini because it's readonly.
I've read that it would be possible to add a custom php.ini to change some settings. I've put one in the public folder where the wordpress site is located and added the line:
error_log = "/php_error.log"
In the same folder I've created the file php_error.log and set the following permissions:
-rw-rw----
As this seemed not to work, I've tried an approach editing the .htaccess file.
# log php errors
php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off
php_flag log_errors on
php_value error_log /php_error.log
Still I don't see any errors in the file.
Is it a problem of the permissions of the error file or should the path be different e.g. html/php_error.log ?

I've finally found a solution.
I have to create a .user.ini file to set custom settings of php.ini.
I've put the file in the root of my public website directory and inserted the following line:
error_log = "/var/www/php_error.log"
It took me quite a while to figure out what the expected path to my log file is. Hopefully this will save some other people a lot of time and headache.

Related

Force error log file in current directory

i have a developement dir on my server but i dont have root access so i cant change which php ini file loads. I ask my host if they would set things up so that i could have a custom php ini file but they dont allow that.
I am always having to go all the way back to the public dir to check the error log file during development. I would like to force the dev folder to create its own error log file. Is there a way to do this without root access. I just want to be able to check errors in the dev dir because its faster to check them.
I have already added a php.ini file to my dev dir. And inside that php ini file i have the error log location code
;just for testing
error_reporting = E_ALL
error_log = '/home/xxxxxxxx/public_html/xxxxxxxxx/xxxxxxx_dev/error_log'
but its probably not doing anything as they dont allow those. Can i do this with htaccess? or is there another way to do this for a local error log?
I am on a linux apache machine.
You can use set_error_handler() to change system default behavior.
function myErrorHandler($errno, $errstr, $errfile, $errline)
{
// do something
}
set_error_handler('myErrorHandler');
This worked in the .htaccess file...
enable PHP error logging
php_flag log_errors on
php_value error_log /home/xxxxxxxxx/xxxxxxx/xxxxxxxxx/xx_dev/error_log
You can set error_log file in .htaccess, for example
# enable PHP error logging
php_flag log_errors on
php_value error_log /home/path/public_html/domain/PHP_errors.log
This file should be writable for apache process user (www-data, apache - see apache config).

Can I set php.ini for individual folders in Linux (Debian)?

I'm new to PHP and server configuration in general, so I apologize in advance if this is a stupid question.
Basically I have LAMP on my laptop (I installed Debian, Apache, MySQL, PHP separately, not as a bundle). The websites on my localhost are located in var/www/html/. I made a subfolder called 'php' (var/www/html/php/) where I'm learning and experimenting with PHP code.
Now, I made a php.ini file in var/www/html/php/ which only contains 2 lines:
display_errors = on
display_startup_errors = on
All I want is for the errors to display so that I know what I'm doing wrong.
Anyway, that didn't work. So I moved the php.ini file to var/www/html/ but it still didn't work. In the end I had to go to the folder where PHP is installed and edit the php.ini file there (i.e. /etc/php5/apache2/php.ini).
I can see the errors now, but what if I don't want to turn on display_errors for every site in my localhost? What if I want to have display_errors=On for some folders and display_errors=off for some folders? How do I do that?
You can use the .htaccess php_value mechanism to modify php values.
For instance, having
php_value display_errors on
On your .htaccess will set this value for every file in that folders and every descending folders.
More informations here: https://secure.php.net/manual/en/configuration.changes.php

Editing php.ini file

I'm using phpinfo to find out where the server's php.ini file is located:
<?php phpinfo() ?>
When I log-onto the server using FTP, I don't see it in the path under Loaded Configuration File.
How can I download/edit the php.ini file?
Can I create a custom php.ini file for one directory (and its sub directories), so that the global PHP settings are not changed?
probably you don't have permissions to view the file.
what you can do is make a custom_settings.php and use ini_set() to change the configurations and include that file where ever need, to change the configuration settings.
Please refer to http://us1.php.net/ini_set
If you have Direct Admin installed, you can login as admin and edit it there.
It should be on location
/etc/php.ini
If not found there, you can search it by using
locate php.ini
If you want to change any values​​, try to do it in .htaccess file
Examples:
php_flag display_errors Off
php_value upload_max_filesize 2M
php_value error_reporting 0
php_flag magic_quotes_gpc Off

PHP display_errors=Off in php.ini settings issue

I have a custom php.ini file I created in my public_html directory. It works as I have checked the settings set are correct using phpinfo().
But the strange problem is the php.ini settings do not seem to apply to all sub_folders in the public_html directory?
Any ideas perhaps theres a setting needed in php.ini to apply to all subdirectories in public_html?
I found the answer myself you have to add the line into .htaccess file so it uses the custom php.ini file you created in public_html instead of having to copy php.ini file in every subdirectory you create.
Add this to .htaccess does the trick obviously replacing username
SetEnv PHPRC /home/USERNAME/public_html/php.ini
Not really a solution, but you can disable overriding the display_error setting by using php_admin_flag in your sites configuration. If it still happens then, you have set an error handler which misbehaves.

PHP.ini does not work

I opened the notepad, inserted 3 lines in it, saved it as php.ini, and uploaded it in public_html, but I am still getting an error that requires to first switch the magic quotes off. The syntax of the three lines is as following:
magic_quotes_gpc = 0
magic_quotes_runtime = 0
magic_quotes_sybase = 0
What am I doing wrong?
use phpinfo() function to see what php.ini file you're actually using
You can probably alter these settings in a .htaccess configuration file as well:
php_flag magic_quotes_gpc off
php_flag magic_quotes_runtime off
php_flag magic_quotes_sybase off
See PHP: How to change configuration settings.
Most hosting companies lets you define a local ini file. Check their support pages, and see where you should put your php.ini file for it to be read by the php engine. If they have an option for this, you don't have to worry about restarting the server.
If you can't find any info about it, create a page with the following code:
<?php phpinfo(); ?>
And look for the property named "Configuration File (php.ini) Path". This is where you should put the file.
It's not meant to be placed in the public_html folder... it should be in your PHP installation folder.
Php.ini is not usually located in public_html. If you can't access your real php.ini, try writing
php_flag magic_quotes_gpc off
in a .htaccess file (in public_html).
Most hosting companies won't let you play around with the php.ini unless you rent a dedicated server from them. On that, you could try on page php.ini settings like the following:
ini_set("magic_quotes_gpc", "0");
ini_set("magic_quotes_runtime", "0");
ini_set("magic_quotes_sybase", "0");
If that doesn't work, then you'll have to ask your hosting company about it.
On CentOS 8 run
service php-fpm restart
To read the edited php.ini file
Well, you have to change your main php.ini which I don't think is in public_html.
Moreover, in order to see the changes you have to restart your php engine.

Categories