I can't see the errors on MAMP PRO [duplicate] - php

I search the path where the php.ini file is located in our Linux Ubuntu server, and I found many php.ini files when executing the command find / -name php.ini. So how can I know exactly from a PHP script web page where the php.ini is located?

php --ini
For the webserver-SAPIs use phpinfo()
Here's some sample output:
bash-3.2# php --ini
Configuration File (php.ini) Path: /usr/local/php5/lib
Loaded Configuration File: /usr/local/php5/lib/php.ini
Scan for additional .ini files in: /usr/local/php5/php.d
Additional .ini files parsed: /usr/local/php5/php.d/10-extension_dir.ini,
/usr/local/php5/php.d/20-extension-opcache.ini,
/usr/local/php5/php.d/40-openssl.ini,
/usr/local/php5/php.d/50-extension-apcu.ini,
/usr/local/php5/php.d/50-extension-curl.ini,
/usr/local/php5/php.d/50-extension-gmp.ini,
/usr/local/php5/php.d/50-extension-imap.ini,
/usr/local/php5/php.d/50-extension-intl.ini,
/usr/local/php5/php.d/50-extension-mcrypt.ini,
/usr/local/php5/php.d/50-extension-mssql.ini,
/usr/local/php5/php.d/50-extension-pdo_pgsql.ini,
/usr/local/php5/php.d/50-extension-pgsql.ini,
/usr/local/php5/php.d/50-extension-propro.ini,
/usr/local/php5/php.d/50-extension-raphf.ini,
/usr/local/php5/php.d/50-extension-readline.ini,
/usr/local/php5/php.d/50-extension-xdebug.ini,
/usr/local/php5/php.d/50-extension-xsl.ini,
/usr/local/php5/php.d/60-extension-pecl_http.ini,
/usr/local/php5/php.d/99-liip-developer.ini

You can use php_ini_loaded_file().
Taken from php.net:
$inipath = php_ini_loaded_file();
if ($inipath) {
echo 'Loaded php.ini: ' . $inipath;
} else {
echo 'A php.ini file is not loaded';
}
You may also want to check php_ini_scanned_files().
Also, you should note that if you run a PHP script from CLI, it's possible that a different php.ini file will be used than if a server (e.g., nginx or Apache) runs it.
Other options:
php -i|grep 'php.ini'
create info.php that contains <?php phpinfo(); in the webroot, and run it in your browser

Note that the configuration loaded for PHP when it's being used in the console is different from the configuration for the web process. Most PHP installations would come with a php.ini file for Apache and another for CLI.
To know which configuration file is used for the console commands, use
php -i | grep "Configuration File"
To know which configuration file is used for the web processes, follow these steps
Create an info file (preferably in the root folder)
The contents of this file should be <?php phpinfo(); ?>
Ctrl + F and search for "Configuration File"

You have to use the PHP method php_ini_loaded_file (only after PHP 5.2.4)
php_ini_loaded_file — Retrieve a path to the loaded php.ini file
PHP website example:
<?php
$inipath = php_ini_loaded_file();
if ($inipath) {
echo 'Loaded php.ini: ' . $inipath;
} else {
echo 'A php.ini file is not loaded';
}
?>
Source: PHP site

Just add a file like this:
<?php
phpinfo();
?>
Then look for
Loaded Configuration File
You'll see the full path for the php.ini file.

Create a simple page and it will be listed there!
<?php
phpinfo();
?>

As mentioned, "find / -name php.ini" will help get all the php.ini files. The one you may be editing may not be the one from which the server is drawing the command from! I found php.ini for three different versions of PHP on my server and I got the fix instantly then.

Related

Starting web server with `php -S` not reading php.ini file

I have a local project I am working on. I have at the root of my project and index.php php.ini and local_connector.php.
When I run php -S ... from inside my project. It says that the php.ini is not loaded.
This is the code I have in my index.php
$inipath = php_ini_loaded_file();
if ($inipath) {
echo 'Loaded php.ini: ' . $inipath;
} else {
echo 'A php.ini file is not loaded';
}
This is what I have in my php.ini
auto_prepend_file = "./local_connector.php"
The idea is I will have multiple pages that use the local_connector but I don't want to include it in every file. Is this possible with php's local server?
I would rather not set up an entire local apache server, so if someone knows a good way of getting this to work, or a work around. That would be very helpful.

How to find the Extensions used in PHP Project?

When publish PHP project to server,maybe this server not support some extensions but my project required, so I want to find all extionsions my project used.
Like...
"require": {
"php": ">=5.3.0",
"ext-gd": "*"
}
is there some Tools or Commands support?
###For Example
//filename is exp.php
class exp{
private $array = ['a'=>'b'];
private $conn = mysql_connect("....");
}
//tool or command result
require >=PHP5.4,ext-mysql,
//filename is exp.php
namespace com\core\exp
class exp{
private $array = array('a'=>'b');
private $conn = new mysqli("....");
}
//tool or command result
require >=PHP5.3,ext-mysqli
The most common way to load a PHP extension is to include it in your php.ini configuration file. Please note that many extensions are already present in your php.ini and that you only need to remove the semicolon to activate them.
;extension=php_extname.dll
change like this
extension=php_extname.dll
However, some web servers are confusing because they do not use the php.ini located alongside your PHP executable. To find out where your actual php.ini resides, look for its path in phpinfo():
Configuration File (php.ini) Path C:\WINDOWS
Loaded Configuration File C:\Program Files\PHP\5.2\php.ini
After activating an extension, save php.ini, restart the web server and check phpinfo() again. The new extension should now have its own section.
for example:
<?php
phpinfo();
?>
php -m : will give all the modules list
php -i : will give more detailed information about current configuration.

sys_get_temp_dir() - returns C:\Windows on windows8

On windows8 I got this with php 5.3:
echo sys_get_temp_dir();
output:
C:\Windows
Am I not understand something or it is a bug?
UPD
trying $_ENV:
<?php
var_export($_ENV);
output:
array ( )
Checking upload_tmp_dir:
<?php
echo ini_get('upload_tmp_dir');
output:
C:\Windows\Temp
Looking at the PHP source, it will call GetTempPath to determine the temp directory. According to the documentation, the windows directory C:\Windows is the last fallthrough option. You should check under which user profile PHP or its host process is running, maybe the environment needs some fixing.
Related to this PHP Bug (only CGI context?).
I have the same problem and the solution is to change the apache configuration to expose the TEMP system environment variable to PHP with this directive in apache configuration file (httpd.conf) :
PassEnv TEMP
Don't forget to activate the env_module, generally uncomment the line "LoadModule env_module modules/mod_env.so".
This solution fixes the result of these PHP functions: sys_get_temp_dir(), tempnam().

How can I know which 'php.ini' file is used?

I search the path where the php.ini file is located in our Linux Ubuntu server, and I found many php.ini files when executing the command find / -name php.ini. So how can I know exactly from a PHP script web page where the php.ini is located?
php --ini
For the webserver-SAPIs use phpinfo()
Here's some sample output:
bash-3.2# php --ini
Configuration File (php.ini) Path: /usr/local/php5/lib
Loaded Configuration File: /usr/local/php5/lib/php.ini
Scan for additional .ini files in: /usr/local/php5/php.d
Additional .ini files parsed: /usr/local/php5/php.d/10-extension_dir.ini,
/usr/local/php5/php.d/20-extension-opcache.ini,
/usr/local/php5/php.d/40-openssl.ini,
/usr/local/php5/php.d/50-extension-apcu.ini,
/usr/local/php5/php.d/50-extension-curl.ini,
/usr/local/php5/php.d/50-extension-gmp.ini,
/usr/local/php5/php.d/50-extension-imap.ini,
/usr/local/php5/php.d/50-extension-intl.ini,
/usr/local/php5/php.d/50-extension-mcrypt.ini,
/usr/local/php5/php.d/50-extension-mssql.ini,
/usr/local/php5/php.d/50-extension-pdo_pgsql.ini,
/usr/local/php5/php.d/50-extension-pgsql.ini,
/usr/local/php5/php.d/50-extension-propro.ini,
/usr/local/php5/php.d/50-extension-raphf.ini,
/usr/local/php5/php.d/50-extension-readline.ini,
/usr/local/php5/php.d/50-extension-xdebug.ini,
/usr/local/php5/php.d/50-extension-xsl.ini,
/usr/local/php5/php.d/60-extension-pecl_http.ini,
/usr/local/php5/php.d/99-liip-developer.ini
You can use php_ini_loaded_file().
Taken from php.net:
$inipath = php_ini_loaded_file();
if ($inipath) {
echo 'Loaded php.ini: ' . $inipath;
} else {
echo 'A php.ini file is not loaded';
}
You may also want to check php_ini_scanned_files().
Also, you should note that if you run a PHP script from CLI, it's possible that a different php.ini file will be used than if a server (e.g., nginx or Apache) runs it.
Other options:
php -i|grep 'php.ini'
create info.php that contains <?php phpinfo(); in the webroot, and run it in your browser
Note that the configuration loaded for PHP when it's being used in the console is different from the configuration for the web process. Most PHP installations would come with a php.ini file for Apache and another for CLI.
To know which configuration file is used for the console commands, use
php -i | grep "Configuration File"
To know which configuration file is used for the web processes, follow these steps
Create an info file (preferably in the root folder)
The contents of this file should be <?php phpinfo(); ?>
Ctrl + F and search for "Configuration File"
You have to use the PHP method php_ini_loaded_file (only after PHP 5.2.4)
php_ini_loaded_file — Retrieve a path to the loaded php.ini file
PHP website example:
<?php
$inipath = php_ini_loaded_file();
if ($inipath) {
echo 'Loaded php.ini: ' . $inipath;
} else {
echo 'A php.ini file is not loaded';
}
?>
Source: PHP site
Just add a file like this:
<?php
phpinfo();
?>
Then look for
Loaded Configuration File
You'll see the full path for the php.ini file.
Create a simple page and it will be listed there!
<?php
phpinfo();
?>
As mentioned, "find / -name php.ini" will help get all the php.ini files. The one you may be editing may not be the one from which the server is drawing the command from! I found php.ini for three different versions of PHP on my server and I got the fix instantly then.

How can I check whether the server is able to handle SOAP requests

How can I check whether the server is able to handle SOAP requests at run time ?
I need to verify it before my script is executing.
You can use:
if (extension_loaded('soap')) {
// Do things
}
http://php.net/manual/en/function.extension-loaded.php
From SSH you can run:
php -i | grep Soap
that will return something like:
Soap Client => enabled
Soap Server => enabled
In PHP to check whether SOAP enabled or not use built in function class_exists():
var_dump(class_exists("SOAPClient"));
It also could be user to check any of modules classes.
in the command line type the following:
>> php -r 'echo (extension_loaded("soap")?"LOADED\n":"not loaded\n");'
Hmm... I'm new and I'm bad :
I tried this in a "test.php" file.
<?php
if (extension_loaded('soap'))
{
echo phpinfo();
}
else //will redirect to sth else so you know it doesn't work
{
header("Location: http://localhost/index.html");
die();
}
?>
And I saw myself looking at a "phpinfo()" page with a paragraph called : "soap".
Sorry for the misinterpretation.
To install SOAP :
Check your "php.ini" file, look for "extension".
You should find a line :
extension=php_soap.dll or ;extension=php_soap.dll
";" means it's commented.
Uncomment it.
If you didn't find the line, then put it there.
extension=php_soap.dll
Make sure the dll file actually is in the default folder php/ext.
If it isn't, check on phpinfo() is your version is VC6, VC9 of VC11, go to the php download page : http://windows.php.net/download#php-5.6 and get the correspondant version of php zip file.
Steal their "php_soap.dll" from their /ext folder and put it in yours.
You're all set!
Restart your servers, then go to your phpinfo() test page to check if it works.
Good luck.
Note :
phpinfo() simple test.php file :
<php
echo phpinfo();
?>
in a php file :
<?php
echo phpinfo();
?>
and then look for SOAP and you will see if SOAP is installed and enabled
EDIT : be careful with other solutions using php CLI (Command Line Interface), because you don't have the same php.ini used for the CLI and for your web server (for example apache). Thus it may differ.
Then if you use apache and you want to see if soap is enabled, it's better to indicate the apache php.ini file in the command line, for instance :
php -c /etc/php/apache2/php.ini -i | grep Soap
PEAR packages are not listed in phpinfo(), so if "soap" doesn't appear on your "test.php" page, it's normal !
You can use the phpinfo script to see is SOAP is installed.
http://[your-domain.com]/phpinfo.php

Categories