I've been working on a development LAMP server for some months with no issue.
Recently, whenever I update a file on the webserver, the changes I make are not taking affect. I've confirmed that the modified file has been uploaded to the filesystem from a shell, but none of the additions are taking effect when I run the file in a browser.
Anyone have any idea of what this could be?
EDIT:
Okay I found the issue. The file I was making an update to was a PHP include in another folder. At the top of the parent file was this line:
ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . '/usr/share/xxxx/zzzz');
For unknown reasons, this stopped working (possibly the include_path in the ini was somehow changed).
I had to change the PHP includes to contain the full path to the includes and then my updates began to work.
You can see cached version (try to to force refresh - CTLR-F5) Or you changing the files in the different location than they are being served from. Check your httpd config and see if both location matches.
Related
I have the following code in a php/html file:
<?php
include('sample.php');
include_once('foo.php');
include('bar.php');
?>
On my dev server (php's built-in server), everything is working fine, on the production server (apache2) though I get a blank page when accessing the file.
The only way to get to the actual page is by removing all 3 includes, removing a single one or two of them does not resolve the problem. In the included files I do include files, which might get loaded more than once with include_once. Apart from that I have no glue why there is an error since everything is working on my dev server and some of the included files work well in other parts of the app.
It is probable that the configuration of include_path on your dev server contains ., which means: if file is included with relative path, try to find it in the current directory. This setting is probably not present on the prod server (see for yourself with phpinfo()).
I was having problems with my PHP website (SuiteCRM) not being able to log users in and I found it was due to not being able to write on the sessions directory.
I am able to fix it by creating the directory /tmp/php_sessions and giving it write permissions for the Apache user www-data. I see the directory get populated with files as users log in.
However, Ubuntu Xenial is deleting my entire tmp directory on reboots, so I have to redo this all over again every time. I decided to move my save_path elsewhere.
After changing things in my php.ini file, and restarting Apache, I can check that they are effective by running this simple script:
<?php
echo ini_get("session.save_path");
phpinfo();
?>
This shows me a double confirmation of the new path, first echoing /var/tmp/php_sessions and then, in the middle of all the phpinfo information, showing the same value as both Local Value and Master value for directive session.save_path.
BUT the directory that php is using is still the first one, /tmp/php_sessions! It seems that my setting is being ignored.
Am I overlooking something? Where could that old setting be buried? Or how can I make the new one effective?
(P.S. - I am not using a redis handler as in another similar SO question)
Ok, I solved my own problem and the general answer is as follows:
There are two more things that can be changing the path and need to be checked,
the PHP code of the application might be changing the ini directive, search the code for ini_set(session.save_path
the PHP code might be using the session_save_path PHP command to override the ini. Search the code for that also (and notice the two underscores _!)
And the specific answer for my case was that SuiteCRM uses session_save_path command to set its path with a value coming from the file config.php found at the web root. That's where I found the old setting, and changing it solved my problem (for good, I hope).
I have just setup the LAMP server on Debian. The initial tests were fine. After that, I've decided to change the home directory from "/var/www/" to something like "/home/user/public_html/". I did this changes in "/etc/apache2/sites-available/default".
The problem I am facing now is, that the PHP does not work in the new home folder. PHP sites are now parsed as text files and I can see the full source in browser (when clicking on view page source).
What can I do, that the PHP will also work under that path (and not only under /var/www)?
Look in php.ini in your php folder. There should be entries to change to 'doc_root' as well as 'extension_dir'. Make sure these are set, then restart Apache and it should work.
I am developing a website on php, I have installed wamp on my personal computer and my website files are in the www folder of wamp.
now considering www as my root folder i have a template folder in the root folder and header.inc.html file in the template folder. when I try to include this header.inc.html file in any other php file using an absolute path include('/template/header.inc.html'); it gives me error "Failed to open stream: No such file or directory", but when I create a simple html link using the same absolute path it works perfectly and opens the file. below is my test code
<?php
echo 'headerfile';
include('/template/header.inc.html');
?>
if I give the full path for example C:/wamp/www/template/header.inc.html to the include function it works fine.
I am confused that this problem is occurring on my wamp server only and it would work perfectly on any webhost server, or maybe the same problem will exist on a webhost
I would appreciate any help that would clarify my confusion, Thanks.
Absolute paths on the server start from the server's hard disk (C:\).
Absolute paths on the client start from the root of the website (http://example.com/).
You can make use of __DIR__ to make some file on disk relative to the php-file on disk itself:
include(__DIR__.'/template/header.inc.html');
This should solve your issue.
The difference is not that easy to explain because both types of paths - even related - are two pair of shoes. I suggest you start with a very basic HTML website tutorial that explains how to link on your website and where files are located and how that is related to the webserver configuration.
HTML pages live in the client's browser that know nothing about your server's folder structure, and they're relative to the domain name eg. http://example.com/.
PHP programs run on the server side and they deal with the server folders. You shouldn't hardcode full paths in your php programs, because it will cause problems whenever you'll move them between the development server and the live host (just to name an example). Therefore in php files you should either use relative paths to your file, or use the __DIR__ magic constant that gets substituted with the directory where the php file is.
1.) First approach: include('template/header.inc.html');
2.) Second approach: include(__DIR__ .'/template/header.inc.html');
In your case (working on a development machine) both the client and the server is the same box, that might be confusing you.
Okay, I've tried everything, this is by far the best place it seems, I want to make Document Root here httpdocs/[folder]/html and I have php include files that I want to go above the root (require '../[folder]/file.php'] but not be able to access further than /var/www/vhosts/example.com/httpdocs. I know I'm being limited by open_basedir because the value is still httpdocs/[folder]/html in phpinfo() but for the life of me I can't change that local value!
This is what I've tried so far:
I've seen this - How to include file outside document root? - and created a 'vhost.conf' that is stil sitting in the conf directory, reconfigured the file, restarted apache...nothing. It's a good post but it seems a little out of date.
I edited php.ini itself to open_basedir = '/var/www/vhosts/example.com/httpdocs, uploaded it back up to where it was, reconfigured, restarted - nothing
I pulled out 'httpd.conf' edited it by adding the same lines from the other conf file,(vhost.conf), put it back in - nothing, I then tried to do what godaddy says here - http://help.godaddy.com/article/1616 and added the line php_admin_value open_basedir none' to 'httpd.conf - with no luck either.
It is now 0435 and I can barely keep my eyes open - this site is suppose to launch tomorrow at 2000! Thanks in advance to anyone who is willing/able to read and/or help.
Update: Thanks for a quick response, here are the best answers I can give you:
Does it give you an error?
Yes, I get a server error and through my server error log, specifically:
PHP Warning: require() [function.require]: open_basedir restriction in effect. File(/var/www/vhosts/[example.com]/httpdocs/[folder]/[folder where secure php files exist]/[file.php]) is not within the allowed path(s):
So I'm 99.99% sure its because of the open_basedir restriction.
Are you sure that your webserver is set as the owner of vhosts/ ?
I'm pretty sure, I'm kinda new to controlling servers and I don't really know what that means exactly but I have a virtual dedicated server through Godaddy, running Parallels Plesk v10.3.1, I did the above file moving going through Shell SSH.
In Plesk, I can change the 'Document root' to anything below /var/www/vhosts/example.com and Plesk will change the 'open_basedir' to anything I set. For example, If I set the document root to 'httpdocs' in Plesk then 'open_basedir' is changed to the same folder and everything works fine. The problem is I don't want public access to everything in /httpdocs/[folder]
My goal is I want to change 'document root' to /httpdocs/[folder]/html and 'open_basedir to /httpdocs but I can't change that local value in open_basedir for some reason. I want to do this for security purposes so people can only directly access the non important php files, but php itself I want to give more access to folders.
Are you trying to include using relative or absolute paths?
My paths in the php file that I'm trying to include/require to files above 'document root' looks exactly like this format:
require '../[folder where secure php files exist]/file.php';
If I'm understanding you correctly, I'm not using the entire path of the server.
ANSWER: (This was changed to the answer):
Apparently, in Plesk 10, Plesk's program sets whatever the 'document root' path will be, to the 'open_basedir' BUT there is no user friendly way to change 'open_basedir' in Plesk 10!!!
So instead it is a little bit of a hack, you have to first go here:
/usr/local/psa/admin/conf/templates/default/service/php.php
Then change both of these lines in the file, (line 11 and 29):
echo "php_admin_value open_basedir {$OPT['dir']}/:/tmp/\n";
to this:
echo "php_admin_value open_basedir /var/www/vhosts/[your.domain]/httpdocs/:/tmp/\n";
or to wherever you want the restriction to stop.
Then make sure your run these lines is SSH:
/usr/local/psa/admin/sbin/httpdmng --reconfigure-all
/etc/init.d/httpd stop
/etc/init.d/httpd start
But I'm having a new problem now. The 'document root' is pointing to the correct folder:
/var/www/vhosts/[my.domain]/httpdocs/[folder]/html
without any error however when the server gets to a:
require '../[folder]/[file.php]';
It skips through it like its not even there! Not giving me an error msg or anything. It's also skipping all my embedded css files, js files, images, videos...its not going to any of the directories! I have a feeling it's a 'php.ini' setting or something weird that Plesk is doing.
Solved: The last issue was because I never worked with accessing files above the root. PHP is allowed to go above the root but you can't do this:
src="../img/imagefile.jpg"
in HTML.
So after restructuring all my site files my website is now up and running! Thanks to all that helped, hopefully someone won't have to do that again. Also, I saw a post where Plesk is updating this because it is a big issue. Someone who works for Parallels said, http://forum.parallels.com/showthread.php?t=113236 this will be an option in the next version, so until then it's hack time!!