Where is "./" in php.ini extensions directory pointing to? - php

I don't want to look like a noob, but this is really annoying me. Do you know where does the
; Directory in which the loadable extensions (modules) reside.
extension_dir = "./"
pointing to?

./ points to the current directory.
Edit
I haven't found any definition of what the current directory is while parsing a php.ini file, this post suggests that it is relative to the php.ini files location.

Just adding in for future searches
Running phpinfo on the cli (php -a<enter>phpinfo();<enter>) gave me this among the output.
extension_dir => /usr/lib/php/20131226 => /usr/lib/php/20131226

It appears that "current directory" is, as far as PHP is concerned, whatever directory "pwd" prints.
The easiest way to see this is to run php -r 'echo getcwd();'
I can also determine this is by typing zend_extension="xdebug.so" inside my php.ini . Next, I create two folders anywhere: One empty, and the other I copy my xdebug.so into.
When I open a terminal inside my empty folder and run php, it generates a warning about not being able to find xdebug.so. In contrast, if I open the terminal in the folder with the extension and run php at the prompt, there are no warnings.
I couldn't determine where this maps to when running php through apache. I tried the document root, HTTPD_ROOT, /usr/bin. Nothing. I'm making this note incase someone who knows more about apache can shed some light on this.
As far as, extension_dir's default location. That is compiled in. You can find the value for your extension_dir by finding the file build-defs.h. It's defined in the macro PHP_EXTENSION_DIR build-defs.h is created by a template file during the configure stage of compilation.

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.

Why does PHP refuse to enable cURL on Windows

I am using PHP 5.5.25 with Apache 2.4 on Windows 7 x64 and I am unable to activate the cURL module. I have looked around and tried all I could think of. Please assist:
In php.ini, the line extension=php_curl.dll is active and the file php_curl.dll is present in the extensions directory C:\php\ext
In php.ini when I set extension_dir = ext, none of the extensions load. I get several messages when Apache starts, similar to Unable to load dynamic libraryext\php_openssl.dll- The specified module could not be found.
When I use the full path and set extension_dir = C:\php\ext, all the extensions load fine, except for cURL. I get the error: Unable to load dynamic libraryC:\php\ext\php_curl.dll- The specified module could not be found.
I have tried renaming the extension to php_curl.new.dll and adjusting php.ini but I get an error message about the new filename. I have also downloaded a fresh new copy of the DLL from windows.php.net, but that made no difference.
I have checked the file permissions for php_curl.dll (Right-click on the file >> Properties >> Security tab) and they are the same as the permissions for extensions that load successfully
I have copied and pasted libeay32.dll and ssleay32.dll from the PHP bin directory to the System32 and SysWOW64 directories as instructed by a response to this question
I am certain that I am editing the right php.ini since the PHP startup error messages changed when I changed the extension_dir value from ext to C:\php\ext as I explained above.
I have made sure to restart the Apache server between php.ini configuration changes.
If in a PHP script I execute var_dump(file_exists('C:\php\ext\php_curl.dll'));, I get boolean True so PHP can see the file!
What else could explain why the cURL module is not enabled?
I think you'll need libssh2.dll in your PATH too.
Credit goes to #Steven Hilder for pointing me in the right direction.
The problem was that Windows could not see libssh2.dll, another DLL that was in PHP's directory. Copying this file to C:\Windows\SysWOW64 and C:\Windows\System32, along with the other two DLL files from my OP (libeay32.dll and ssleay32.dll) worked.
I am uncomfortable with this solution though because when the time comes to update to a new PHP version I will have a harder time remembering to overwrite these DLLs with the new version.
Therefore, I decided to remove all 3 DLLs from the System32 and SysWOW64 directories. Instead, I just added the PHP bin directory to the Windows' PATH variable, so that the next time the OS is looking for a missing file, it will also look in that directory. This has the added bonus that if a similar problem with another DLL occurs, it will be resolved automatically.
To add the PHP bin to Windows' PATH:
From the Start Menu search bar, search for and select Advanced system settings
Click Environment Variables. Scroll down the list of System variables to select Path and click Edit... to open the current PATH setting
Append ;C:\php or whatever directory has php.exe to the current setting (semi-colon is used to separate paths).
on windows the cURL execution wants SSL certificate. may be because of that others error is showing.
Put the below code before curl_exec(curlHandle) to ignore checking for SSL certificate
//to ignore the SSL certificate in windows
curl_setopt($curlHandle, CURLOPT_SSL_VERIFYPEER,false);

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.

I can not find my php.ini file

While learning to set up php to be able to send mail I came across the need to edit the php.ini file. The problem is that when I go to <localhost>/~username/phpinfo.php it tells me it is located at /Library/Server/Web/Config/php however the Web directory does not exist on my server. So where is my php.ini file? I have looked at answers to the same question by others and still was not able to find it. If I need to create it, how do I go about doing that?
I am using a macbook pro as my server running Yosemite.
Thanks in advance!
UPDATE:
So it looks like I found my php.ini file but it is not where php says it is looking phpinfo.php says its looking in /Library/Server/Web/Config/php should I copy the file to this location? also my file is actually named php.ini.default, does this need to be named as just php.ini?
execute this command
locate php.ini
This will give you a list of all files with names where 'php.ini' is a part of it.
E.g.
/etc/php.ini
/etc/php.ini.rpmnew
/home/myuser/mywebsite.com/demo/local_php.ini
...
I'd rather do this:
php -i | grep ini
It will give you the info for ini configuration in the php console client. If you are executing apache or nginx you can see all the PHP settings with
<?php
echo phpinfo();

What php libraries need to copy to windows system dir and why?

As you know Apache couldn't load curl modules, when its dll's are not in windows system dir even when your php path exists in system variable PATH. I want to ask,
why it could happen?
do you know other examples of same behavior, when you need to copy anything in win dir?
ps,
PHPIniDir "F:/php" <- is set
PATH=F:/php
php.ini is in F:/php and it successfully loaded
never copy php files to widows folder:
1.- Add php to windows PATH
2.- change extension_dir to FULL PATH
3.- see phpinfo for more information, paths etc...
4.- to add module:
extension = module_name.dll in php.ini
good luck

Categories