Title pretty much says it all. I've been tearing my hair out trying to get this working all day. I'm in the process of creating a PHP-based login system and I need to do some debugging. The most useful thing to me right now would be the ability to write debugging messages to a file at certain points throughout a PHP program. Based on the documentation, it looks like this is what error_log() is supposed to do, but despite everything I've tried, I have had absolutely no success. Full list of everything I've tried below:
Added the following to /etc/php/7.0/apache2/php.ini
error_reporting = E_ALL
display_errors = On
log_errors = On
Additionally, tried setting error_log to locations within /usr/, /var/www/http/, and /home/
Used ini_set() and error_reporting() to set all of those variables, including error_log from within a PHP file
Manually creating the files that are supposed to be written to, and setting their owning user and group to www-data and their permissions to 777
Last but not least, reinstalling libapache2-mod-php7.0 and php7.0, to no avail
Basically everything short of using my laptop to break the 3rd story window of my office building immediately prior to jumping to my prospective death
I really can't find anthing else to try on Google, so I figured I'd ask the experts, and here I am. If anyone can provide any suggestions, it would be greatly appreciated.
I guess the logs are written to sys logs because in error_log() you didn't provide the destination.
Try the following code
error_log("An error occured", 3, "/var/tmp/my-errors.log");
Be sure this file can be read by php either fpm or www-data depending on your configuration you can create it before with touch and add permissions manually with chmod
3 means that destination is a file
If you use apache then check in httpd.conf or any other place(v where it may be present the location of ErrorLog
ErrorLog "/var/log/apache2"
Then check if this file has following user group with ls -la ll etc.
-rwxrwxr-x 1 www-data www-data
Something like this should appear.
The other option is to set following in proper php.ini (CLI and apache have different php.ini files)
error_log = /var/log/phperrors.log
then
touch /var/log/phperrors.log
chown www-data: /var/log/phperrors.log
chmod +rw /var/log/phperrors.log
There are no miracles but if it still doesn't work you can write and register your own error handler with set_error_handler() you can find examples how to do it in php manual. It's more like hack but it will work for sure. If it won't then it means that errors are not triggered at all then you should look if you edit the correct php.ini or use ini_set() before error is triggered.
Related
I'm getting this error on an avatar upload on my site. I've never gotten it before and nothing was changed recently for me to begin getting this error...
Warning: is_writable() [function.is-writable]:
open_basedir restriction in effect.
File(/) is not within the allowed path(s):
Modify the open_basedir settings in your hosting account and set them to none. Find the open_basedir setting given under 'PHP Settings' area of your Plesk/cPanel. Set it to 'none' from the dropdown given there.
I have shown them in the Plesk panel picture.
To resolve this error, you must edit the file httpd.conf.
Way before it can be seen in phpinfo in apache2handler section directive Server Root.
For example, in my case this way - / etc / httpd / httpd.conf.
Open the file httpd.conf, find the mention of the parameter open_basedir. And set it to none. (php_admin_value open_basedir none)
If you're running this with php file.php. You need to edit php.ini
Find this file:
: locate php.ini
/etc/php/php.ini
And append file's path to open_basedir property:
open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/:/etc/webapps/:/run/media/andrew/ext4/protected
For me the problem was bad/missing config values for the Plesk server running the whole thing.
I just followed the directions here:
http://davidseah.com/blog/2007/04/separate-php-error-logs-for-multiple-domains-with-plesk/
You can configure PHP to have a separate error log file for each VirtualHost definition. The trick is knowing exactly how to set it up, because you can’t touch the configuration directly without breaking Plesk.
Every domain name on your (dv) has its own directory in /var/www/vhosts. A typical directory has the following top level directories:
cgi-bin/
conf/
error_docs/
httpdocs/
httpsdocs/
...and so on
You’ll want to create a vhost.conf file in the domain directory’s conf/ folder with the following lines:
php_value error_log /path/to/error_log
php_flag display_errors off
php_value error_reporting 6143
php_flag log_errors on
Change the first value to match your actual installation (I used /tmp/phperrors.log). After you’re done editing the vhost.conf file, test the configuration from the console with:
apachectl configtest
…or if you don’t have apachectl (as Plesk 8.6 doesn’t seem to)…
/etc/init.d/httpd configtest
And finally tell Plesk that you’ve made this change.
/usr/local/psa/admin/bin/websrvmng -a
Laravel
If you have this problem when using Laravel.
Only go to folder bootstrap/cache and rename config.php to anything you want and reload site.
If used ispconfig3:
Go to Website section -> Options -> PHP open_basedir:
In this field has described allowed paths and each path is separated
with ":"
/var/www/clients/client2/web3/image:/var/www/clients/client2/web3/web:/var/www/...
and so on
So here must put the path that you want to have access, in my case is:
/var/www/clients/client2/web3/image:
The problem appears because:
When a script tries to access the filesystem, for example using include, or fopen(), the location of the file is checked. When the file is outside the specified directory-tree, PHP will refuse to access it.
The path you're refering to is incorect, and not withing the directoryRoot of your workspace. Try building an absolute path the the file you want to access, where you are now probably using a relative path...
if you have this kind of problem with ispconfig3 and got an error like this
open_basedir restriction in effect.
File(/var/www/clients/client7/web15) is not within the allowed
path(s):.........
To solve it (in my case) , just set PHP to SuPHP in the Website's panel of ispconfig3
Hope it helps someone :)
I had this problem # one of my wordpress sites after updating and/or moving :)
Check in database table 'wp_options' the 'upload_path' and edit it properly...
For Plesk, you can change or set the openbase dir settings via the panel
https://support.plesk.com/hc/en-us/articles/360006170513-How-to-add-custom-or-additional-path-to-the-open-basedir-option-for-Plesk-domain-
Edit the php.ini or .user.ini that is located within the main directory
open_basedir = none
If you are running a PHP IIS stack and have this error, it is usually a quick permission fix.
If you administer the windows server yourself and have access, try this FIRST:
Navigate to the folder that is giving you grief on writing to and right click it > open properties > security.
See what users have access to the folder, which ones have read only and which have full. Do you have a group that is blocking write?
The fix will be specific to your IIS setup, are you using Anonymous Authentication with specific user IUSR or with the Application Pool identity?
At any rate, you are going to end up adding a new full write permission for one of IUSR, IIS_IUSRS, or your application pool identity - like I said, this is going to vary depending on your setup and how you want to do it, you can go down the google rabbit hole on this one (one such post - IIS_IUSRS and IUSR permissions in IIS8) For me, i use anon with my app pool identity so i can get away with MACHINE_NAME\IIS_IUSRS with full read/write on any temp or upload folders.
I do not need to add anything extra to my open_basedir = in the php.ini.
In addition to #yogihosting's answer, if you are using DirectAdmin, then follow these steps:
Go to the DirectAdmin's login page. Usually, its port is 2222.
Login as administrator. Its username is admin by default.
From the "Access Level" on the right panel, make sure you are on "Admin Level". If not, change to it.
From the "Extra Features" section, click on "Custom HTTPD Configurations".
Choose the domain you want to change.
Enter the configurations you want to change in the textarea at the top of the page. You should consider the existing configuration file and modify values based on it. For example, if you see that open_basedir is set inside a <Directory>, maybe you should surround your change in the related <Directory> tag:
<Directory "/path/to/directory">
php_admin_value open_basedir none
</Directory>
After making necessary changes, click on the "Save" button.
You should now see your changes saved to the configuration file if they were valid.
There is another way of editing the configuration file, however:
Caution: Be careful, and use the following steps at your own risk, as you may run into errors, or it may lead to downtime. The recommended way is the previous one, as it prevents you from modifying configuration file improperly and show you the error.
Login to your server as root.
Go to /usr/local/directadmin/data/users. From the listed users, go to one related to the domain you want to change.
Here, there is an httpd.conf file. Make a backup from it:
cp httpd.conf httpd.conf.back
Now edit the configuration file with your editor of choice. For example, edit existing open_basedir to none. Do not try to remove things, or you may experience downtime. Save the file after editing.
Restart the Apache web server using one of the following ways (use sudo if needed):
httpd -k graceful
apachectl -k graceful
apache2 -k graceful
If your encounter any errors, then replace the main configuration file with the backed-up file, and restart the web server.
Again, the first solution is the preferred one, and you should not try the second method at the first time. As it is noted in the caution, the advantage of the first way is that it prevents saving your bad-configured stuff.
Hope it helps!
I am using an Apache vhost-File to run PHP with application-specific ini-options on my windows-server. Therefore I use the -d option of the php-command.
I am setting the open_basedir for every application as one of these options.
I needed to set multiple urls as open_basedir, including an UNC-Path, and the syntax for this case was a bit hard to find. You have to seperate the paths with semicolons and if your first path starts with a driveletter you might have to start the list with a semicolon too. At least that's what works for me.
Example:
php.exe -d open_basedir=;d:/www/applicationRoot;//internal.unc.path/ressource/
I uploaded my codeigniter project on Directadmin panel. I was getting same error.
Then I change in php settings.
open_basedir =
session.save_path = ./temp/
Then it worked for me.
As most do not find a solution, the solutions are broad for WordPress most even don't know fully why things are they are.
I've found out you will have to enable IP for your server in especially when using Cerber in some cases it can think you are not uploading .png instead you are uploading .js files.
The server IP needs to be whitelisted. Even the uploaders in some rare cases.
A great to know is to have a tmp folder 755 in your base directory, you actually do not need a folder called tmp.: "Also remember / properly inedited as below:
open_basedir = "/home/user/site.com/:/tmp"
upload_tmp_dir = /home/user/site.com/tmp
The best option for quick setup is in Cpanel where you use the MultiPHP INI Editor you can actually save and both .htaccess and php.ini will be updated as well as settings being initiated at the same time on site.
It's NOT recommended to have basedir as "none" since you are enabling root files that can be edited with just a single file editor in WordPress. If that truly is possible.
Check \httpdocs\bootstrap\cache\config.php file in plesk to see if there are some unwanted paths.
Just search
open_basedir =
in php.ini and disable it. That's the simplest solution to solve this issue.
Before Changes open_basedir =
After Changes ;open_basedir =
P.s - After changes don't forget to restart your server.
Enjoy ;)
Modify the open_basedir settings in your PHP configuration (See Runtime Configuration).
The open_basedir setting is primarily used to prevent PHP scripts for a particular user from accessing files in another user's account. So usually, any files in your own account should be readable by your own scripts.
Example settings via .htaccess if PHP runs as Apache module on a Linux system:
<DirectoryMatch "/home/sites/site81/">
php_admin_value open_basedir "/home/sites/site81/:/tmp/:/"
</DirectoryMatch>
I'm having:
Ubuntu Linux 12.04 LTS
Apache Web Server(Apache httpd 2.4.16)
PHP 5.5.29
Now, whenever something goes wrong in code I always see a white screen in my browser window with no output at all. So, I googled for the solution and come to know that I have to turn the error reporting on in order to get the detailed errors/exceptions/warnings/etc.
And for this I come to know that I need to change php.ini file which Apache web server is making use of.
I opened up the file '/etc/php5/apache2/php.ini' by selecting it with my mouse, right click on the file '/etc/php5/apache2/php.ini', selected the option 'Open With Sublime Text2' and open up the file in Sublime Text Editor.
I did one small change on line no.466 of '/etc/php5/apache2/php.ini' file as follows :
display_errors = Off //Old code present on line no.466 of php.ini
display_errors = On //New code changed by me on line no.466 of php.ini
I am not sure is this the only change I need to make to '/etc/php5/apache2/php.ini' file to get errors/warnings/exceptions/etc. Please guide me in detail regarding the changes I need to make to the file '/etc/php5/apache2/php.ini' to get all the possible errors/warnings/exceptions/etc.
Now when I tried to save this file I got a pop-up saying 'Unable to save /etc/php5/apache2/php.ini'.
I'm the owner of my laptop, the system is mine, I am the administrator of my system and still I can't make any change to the file. This is really an un-understandable, useless and strange stuff for me. Previously when I was using PHP on my windows machine such weird things and headache never happened.
Please someone take me out of this bloody mess by giving descriptive and step by step answer.
Few people are saying I have to open up the terminal and type commands there. But I'm not getting What is terminal? Where it is? How to open it? What is root user and what is sudo user? What does each of the users do? What's the difference in between them? The purpose of graphical text editor is to manipulate files and this Ubuntu is preventing me from doing it.
Everything is strange here with Ubuntu Linux. What's the use of it? etc.
What is terminal?
Terminal is an interface where you execute your commands. More details here. Its like cmd in windows.
Where it is? How to open it?
Open the Dash (Dash is similar to the Start button in windows)
and type terminal.
The black board like icon with >_ is your terminal, click on it.
This is what a terminal looks like.
What is root user and what is sudo user? What does each of the users
do? What's the difference in between them?
Quoted from Ubuntu docs
In Linux (and Unix in general), there is a SuperUser named root. The Windows equivalent of root is the Administrators group. The SuperUser can do anything and everything, and thus doing daily work as the SuperUser can be dangerous. You could type a command incorrectly and destroy the system. Ideally, you run as a user that has only the privileges needed for the task at hand. In some cases, this is necessarily root, but most of the time it is a regular user.
By default, the root account password is locked in Ubuntu. This means that you cannot login as root directly or use the su command to become the root user. However, since the root account physically exists it is still possible to run programs with root-level privileges. This is where sudo comes in - it allows authorized users to run certain programs as root without having to know the root password.
Editing the php.ini file:
Now that you know what terminal is, open the terminal and type:
sudo vi /etc/php5/apache2/php.ini
Note: There are various other editors, like nano, gedit etc.
You'll be prompted to enter the password:
[sudo] password for user:
Just type in the password and hit enter. You'll see the contents of php.ini in the terminal. Now, scroll and search for the line Display_errors =off. You will have to change this to Display_errors =on, to do this change press i, make your changes, press esc, press shift+q type wq! and hit enter.
Now, you will have to restart apache to have the changes take effect. So, type:
sudo service apache2 restart
and hit enter. Thats it. Hope that gives you an idea :)
Regarding php.ini
You can do runtime change in all settings of your php.ini or by editing php.ini.
You should keep error_reporting false by default. And in development you can make reporting on runtime.
error_reporting(E_ALL);
ini_set("display_errors", 1);
Do this only if you are in development mode to see all fatal/parse errors or set error_log to your desired file to log errors instead of display_errors in production (this requires log_errors to be turned on).
Regarding file changes
php.ini needs to be edited by root user.
So you can edit by terminal:
Open terminal
Switch user as root
Edit php.ini by vi editor and do changes.
Restart apache server
Or If you still want to edit by sublime
Open php.ini by sublime with root access
You need do required changes in php.ini
Restart apache server
Terminal
The terminal is an interface in which you can type and execute text based commands.
Think of it like cmd in windows.
How to run it:
Open the Dash (Super/window Key) or Applications and type terminal, or use the keyboard shortcut by pressing Ctrl+Alt+T.
As this is to broad, and you actualy don't need terminal for your problem; for a great explanation of terminal please see: What is a terminal and how do I open and use it?.
Display error settings in php.ini
There are 2 settings you must edit:
error_reporting = E_ALL
Make sure it only have the value E_ALL.
E_ALL = Show all errors, warnings and notices including coding standards.
E_NOTICE = Show notices
E_STRICT = Show coding standard warnings
if you put ~ in-front it, it means Except.
display_errors = On
Unix-like OS file permissions
In unix-like OSes, files and directories are owned by a user and distinct permissions (read, write, run) apply to the owner.
These are very simplified explanation:
The '/etc/php5/apache2/php.ini' file is owned by root and with write permission only for root, so you can't edit it unless you are the user root itself.
But there is a way for you to edit files owned by another user, and that is with a command: sudo (superuser do ...), or gksu/gksudo for graphical interfaces software.
You may think that your username is another administrator/SuperUser, so why can't you just edit and save the file? Well, in actual you are not. Your user is just a regular user, but with permission to do SuperUser task. In other word you are just a sudo user (sudoers).
So the only way for you to save the changes you made, is to run Sublime Text using root privilege.
This can be achieved from the terminal by executing it via command: sudo sublime or gksu sublime.
Or without terminal:
via Dash (press super/window key), just type gksu sublime and press enter (you will be asked for your password).
This makes you run sublime text editor as root user, so now you can open the '/etc/php5/apache2/php.ini' file and edit it and save it.
(If you don't have gksu, install it via Ubuntu Software Installer.)
I use gksudo and gedit to do the job.
gksudo makes it possible to open a graphical interface. Gedit is the default text editor for GNOME. If you have KDE, then will you use kedit.
First I find the correct location of the used configuration file. You can find it easily making a php file calling the function php_info.
The content of the php file is a call to one function:
phpinfo();
That is it. I always have a file info.php in the documentroot of apache (in Ubuntu /var/www. Then I make a call to that file with:
http://localhost/info.php
and a document containing a lot of information will be returned. In it, you have a configuration value:
Loaded Configuration File
The value on that line is the php file that is used by the apache server. You should edit that file in order to see errors displayed. Lets call that value %phpini-file%.
Next I open a terminal
(see https://help.ubuntu.com/community/UsingTheTerminal)
and type
gksudo gedit %phpini-file%
and I do traverse the file until I see error handling and logging.
After that you will find the variables that you would like to be changed.
On a development machine I set the variable error_reporting to:
error_reporting = E_ALL
The documentation in the file gives you good suggestions.
Underneath that variable you have the variables display_errors, display_startup_errors and log_errors. I always give those variables the values On on my development machine.
Some lines below that you have the variable track_errors. I put it to On.
After making those changes will you have to restart apache.
The way I do it is:
sudo /etc/init.d/apache2 restart
It is equivalent to
sudo service apache2 restart
but it is how I have remembered it.
Instead of a terminal you can type ALT + F2 and you will see a command line appear in the midst of your screen. Next you type your command and the action will be performed.
Root is the user that has all privileges on an unix based system. Sudo is an abbreviation of super user do and makes it possible to execute commands as if someone is root. The whole root concept makes it safe that not any user can do anything on the system. You must be root or otherwise get sudo privileges in order to make changes on the system.
You just need to press
Ctrl + Alt + T
and you'll see a window appearing, which is nothing but the Terminal.
There you just need to type :
sudo gedit /etc/php5/apache2/php.ini
[Gedit is nothing but the default linuk editor]
After that you'll be asked to enter the password, where you need to enter your system's password.
The file will open in the editor, just find Display_Errors in that page and replace off with on, so it will be :
Display_Errors=on
After the changes save and close that file.
And just restart your apache by typing this command on the TERMINAL again :
sudo /etc/init.d/apache2 restart
I'm getting an error on production server but am unable to figure out what it is. Blank page with 500 response code isn't very helpful and adding ini_set to output the error doesn't help because I'm using Symfony and that has another way of dealing with errors that will take me 2 days to figure out.
Apache logs php errors and php is supposed to log php errors, phpinfo tells me that log_errors is on and error_log is /var/log/php.log. That file contains a warning of 1.5 years ago so I guess Symfony is messing things up somewhere.
Try Apache/httpd log. After figuring out what config files are used and where the log is I can't find anything in there after getting a 500 error. Does it take a while before that gets written?
Stuck here and not sure how to figure out what it is that's causing the error. Are there any other options? I guess Symfony should log it somewhere but Symfony/app/logs is empty, there was a very large dev.log there but after renaming it it isn't created again.
Make sure that the file that you have set PHP to log to in the php.ini file is in the group for which the http server runs as. Typically this user is www-data
chown /var/log/php_errors.log root::www-data
chmod 664 /var/log/php_errors.log
sudo apache2 restart
Nothing was written to the php error log because the permissions were set wrong and user running httpd could not write to it.
hopefully someone can shed some light on my problem. I just reinstalled my OS (lubuntu 12.10) and have set up my local server. Everything seems to be working properly except for the one file I'm currently working on. When I try to run it in the browser, it downloads and/or gives a Server Error (HTTP Error 500).
I don't suppose it's an Apache or PHP problem since other files work just fine, but I don't think there's anything wrong with the code in the file in question.
What else could be causing this issue?
There is no need to "suppose" or devise "more than likely" cause or guess "what else".
HTTP Error 500 means there is something verbose in the server's error_log.
Just open it end get the exact explanation of the problem.
Please, do not take blind action, out of mere guess. You can make things worse.
This problem is more then likely caused by a permissions issue.
The Apache server runs as www-data:www-data. What this means is that it is possible to have some permission issues with files that were created by another user.
To solve this, you should either add your user to the www-data group and set the /var/www directory to inherit the group www-data, or you can use chown to change the ownership of all the files to be on the www-data group.
To keep security in your system, you should also make sure that all your files have a permission set of 660, meaning that the owner and anybody of the user group of the file can both read and write, but any other user will not be able to do anything with it.
If you have a php script that does run more than 30 seconds (default) you have to change value of max_execution_time by using ini_set function.
I have a bit PHP code that needs to change the group of files using chgrp(). The code worked on another server (php 5.2), but when migrated to a new server (php 5.3), it stopped working
chgrp(): Operation not permitted.
I've double checked that the user account apache has write permissions to the file (and that it is the owner just to be doubly sure). I've also double checked that PHP safe_mode is off.
Any other tips?
I guess you're trying to assign a group to the target file/directory that apache group is not a member of that, as it has mentioned in the chgrp documentation:
Only the superuser may change the group of a file arbitrarily; other users may change the group of a file to any group of which that user is a member.
I'm not sure what's the idea behind it, but it says you should not be able to assign your files/directories to a group that you're not a member of them; therefor apache user can't assign any of its files/directories to most of the groups you might be thinking of (by default configuration).
P.S. You might be able to chmod and chown with the same privileges your apache user has, but again, it's not permitted to assign those files to another group that you're not a member of them.
So the issue just stopped happening. I literally started adding some debug statements and was refreshing the logs when I added a new statement and then I noticed the error stopped showing up in the logs all of a sudden. I'm guessing something needed to be restarted and that happened in between my debugging. I'm not sure. But in theory safe_mode off, file exists, and apache user being owner/creator of the file should have worked from the start.