How to save sessions outside of webroot; - php

I am trying to save sessions outside of the web root. my website root folder is
public_html -> example.com
The sessions folder i have created is a sibling of the public_html folder. I don't know how to reach it. I tried below but i get an error.
session.save_path = /sessions;
How do i solve this?

The path you give needs to be in quotes; that may be all that's wrong here:
session.save_path = "/sessions"
You mentioned that "the sessions folder is a sibling of public_html" so I'm assuming that public_html is actually at the top-level of your filesystem. This would be unusual, though. Are you sure there is not more to the path? (You can double check by running pwd -P while in the directory, if you're using a UNIX-like system. You'll get back the full path to the directory.)
You also don't need a semicolon. That semicolon makes me a little wary, though: are you adding that configuration to your php.ini file? It's not something you'd add to just any piece of PHP code.
If you don't have access to php.ini and still need to change the save path, see session_save_path in the manual.

Related

PHP restricted to document root, not file system root

I'm trying to change a text file located inside the /etc/nginx directory via php. I'm using fopen() to do this, however, I cannot access any directory outside my websites root folder.
For example, I have my website stored in the absolute path: /webroot/mywebsite/ and if I attempt to read anything outside that folder, like /etc/nginx, fopen() dies.
I have tried just using ../../etc/nginx but it cannot find it
I have tried running PHP as root
I have tried adding the user 'http' to the root group
I have tried setting the open_basedir variable in php.ini
I have tried symlinking the /etc folder to the /webroot folder, but it cannot find it
I have checked my Nginx config and all php configs are not overriding open_basedir
I have confirmed the php.ini I am editing does in fact change in phpinfo();
I have NOT tried chmodding the root directory of my Arch install. I fear this will break something
When I echo out realpath("index.php") it returns "/webroot/mywebsite/index.php"
This is how I've been confirming if I have access to my root directory, but it has not changed. I have no idea what else I can try. My old Debian install let me just use the absolute path. This is my new Arch install and this is the first time I've experienced this. I suspect it may be a permission issue, but I do not want to mas modify my entire OS root. Any other suggestions? Thanks
Well. I'm very surprised I was not able to find this answer after literally 4 hours of googling but here it is. Hopefully I save someone the trouble.
The problem was located here: /lib/systemd/system/php-fpm.service
Find the line "ProtectSystem=full" and set it to "false". Ta-da, I now have access everywhere.

How to get php include_path to work on a custom directory '/var/custom_directory'?

I thought php include path was a pretty simple concept. I've done it many times, but now am having trouble getting it to work.
I am running an
centos 7.1 server on azure with Apache/2.4.6 PHP/5.4.16
When I modify the include_path within php.ini. The error after restarting apache shows
Failed opening required 'xfile' (include_path='.:/var/custom_directory')...
The include path is in the proper file format.
I might have an ownership problem.
I can place my files inside the default usr/share/php directory and the pages "include". However when I try to put my own directory inside of /var they do not.
I have done this before so I do not know why it isn't working now.
I have chowned and chmod these directories and their contents to death. Even mimicing the server that works's directories. Switching ownership to apache and giving full grant access just trying to get it to see the file from my /var/www/html/index.php
Am I missing something?
Is there something I need to enable or grant access or modify in the php or http.conf files?
Further information:
This is the only php.ini file included in the system /etc/php.ini
The purpose of the include path is to provide coding / user files behind the firewall.
I don't think this maters, but my vm is in Azure.
Putting something like this
include('/var/custom_directory/file.php');
Doesn't work as well. Why?
The include_path ini setting sets the path, it doesn't add to it, so if you change it you most likely mean to add an extra path, e.g.:
include_path = ".:/usr/share/php:/var/custom_directory"
This ensures that both your own custom_directory and the standard /usr/share/php directory are in the path.
(N.B. On Linux the path seperator is a colon (:), on Windows it is a semi-colon (;))
However
You probably don't want to mess around with the php.ini setting, as this will affect all php files. If you put another site on your server which tries to include a file with the same name as one in your custom directory you're going to end up in a confusing situation.
I suggest you either qualify your includes:
include('../custom_directory/file.php');
include('/var/custom_directory/file.php');
include(SOURCE_DIR . 'file.php');
Or use set_include_path at the start of your script:
$path = '/var/custom_directory';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
I got a quick test to test your requirement.
(environment: CentOs 7.1, Apache/2.4.6 and PHP/5.4.16.)
I created a ‘includes’ folder in ‘/var/www/’ folder besides ‘html’, shows like:
Then I set include_path = ".:/var/www/includes" in php.ini.
In the includes folder I put a test class file named phpinfo.class.php with simple code:
class phpInfo{
public function echoinfo(){
phpinfo();
}
}
And in html folder, there is a test PHP file with simple code:
require('phpinfo.class.php');
phpInfo::echoinfo();
It worked fine to me.
So you may double check your files and path.
update
I moved the includes folder under to /var/ beside 'html', and modified the php.ini, and still worked fine to me, and the setting of include_path will be shown in the php runtime environment, we can check the configuration.

php access files outside of apache

I have a project where Red5 is recording videos. I need PHP to be able to access the videos and move them so they can be accessed by HTML.
How can I do this?
I found this post: Accessing files outside the document root with Apache
But it involves updating some file that was never specified. And I'm not sure it is a viable solution in this case anyway.
lee
PHP by default can already access files outside the web root, unless restricted with an open_basedir directive (or safe mode, but hope you're not in that cage).
It's normally a good practice to insert within a VirtualHost configuration an open_basedir restriction. You can specify multiple directories separated by : on Linux and ; on windows.
php_admin_value open_basedir /var/www/s/stage:/usr/share/php:/your/dir
To access those files either use an absolute path or a path relative to the position of the PHP file called. (So you'll have to ../ to reach levels above).
Also be sure that directories in which you want to write to are assigned to the webserver user and have write permission.

MKDIR is not working correctly?

i'm using Xampp. When I tried to do this earlier, it worked, but now it is not working.
I'm trying to make a directory in my www folder to hide it from baddies who steal files.
Each user gets their own folder in uploads to put their files on.
Xampp uses apache, and Xampp is a local web server. It allows me to design websites without the need of an online host. The www folder is in my C:\program files\xampp\php\www\ and I need to make a directory there. I know it's possible because i've done this before, I have just forgotten how to make it happen.
When I make a directory I use:
$uploaddir1 = "xampp/php/www/uploads/".$esclcusername."/";
mkdir($uploaddir1,0777);
Do I need to include C:\program files\ before xampp?
And finally, how would this be possible on a real online web host?
I saw your question here and searched some on google. This is what i found:
mkdir("D:/hshome/rubygirl58/gameparody.com/clansites/".$sitename."/lib", 0777)
So yes, I think you have to include the complete path.
Greetings,
Younes
you need to make sure that you give permisions to the parent folder to create dirs in it (0777)
to get the full path you can use dirname(FILE) wich will return the path for the directory of the file in wich it is runned

Why do I have to copy the libmysql.dll to the apache/bin directory to get the PHP extension to load properly?

I'm on a Windows machine. This seems like it should be unnecessary, but when I do it, everything suddenly works. Is there something wrong with my path? Do I need to add something to it to avoid having to copy DLLs?
Apache like any application will assume that the file is located in the same directory as the Current Directory path (check out http://en.wikipedia.org/wiki/Working_directory). If it's not there. The current working directory is USUALLY the same directory that httpd.exe (main executable) is in but it can actually be different if you do something like
C:\Apache2>bin\httpd.exe
In this case the Current Working directory is C:\Apache2 rather than C:\Apache2\bin.
If if the file isn't found there the application will naturally traverse the PATH environment variable. The PATH environment variable is a semi-colon or comma separate list of paths) to find the file.
Start -> Run -> Type "cmd.exe" and then in the Command Prompt type "echo %PATH%" to see the current path you have.
Finally, if the file wasn't found it will just error out.
As a tip you can actually track what files an application is trying to load and where they load them from by using Process Monitor. http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx
I've used this tool to solve load DLL problems in Apache before and other applications as well. Just simply add a filter for the app you are running and have it only sniff out file reads.
I donot know the internals of MySQL and apache.
My thought is this. Internal of your application is using libmysql.dll. And it seems that path is not proper so it searches in PATH environmental variable. apache/bin will be there in PATH directory. So it is taking the dll from this path. If the dll is not present in that path I think it fails to load and hence fails.
EDIT: Added the solutions which were added in comments
Try rebooting your machine. I had the same issue with mysqlpp library. Path was pointing to mysql bin dir but it still couldnt find libmysql.dll – Daniel (Jan 26 at 6:55)
Apache might be running with credentials different from your own (almost certainly so if you're running it as a service.) Try placing the dirs in the SYSTEM path, not the USER path. – moocha (18 hours ago)

Categories