How to change php CLI configuration in laradock? - php

Im using latest laradock with basic configuration.
I created my.ini file with some settings and edit php-fpm/Dockerfile as follow:
COPY ./my.ini /usr/local/etc/php/conf.d/
When i run phpinfo() in browser I see the following:
So, my.ini file successfully loaded. But when I run php -i in workspace bash:
Configuration File (php.ini) Path => /etc/php/8.0/cli
Loaded Configuration File => /etc/php/8.0/cli/php.ini
Scan this dir for additional .ini files => /etc/php/8.0/cli/conf.d
Additional .ini files parsed => /etc/php/8.0/cli/conf.d/10-mysqlnd.ini,
/etc/php/8.0/cli/conf.d/10-opcache.ini,
/etc/php/8.0/cli/conf.d/10-pdo.ini,
/etc/php/8.0/cli/conf.d/15-xml.ini,
/etc/php/8.0/cli/conf.d/20-ast.ini,
/etc/php/8.0/cli/conf.d/20-bcmath.ini,
/etc/php/8.0/cli/conf.d/20-calendar.ini,
/etc/php/8.0/cli/conf.d/20-ctype.ini,
/etc/php/8.0/cli/conf.d/20-curl.ini,
/etc/php/8.0/cli/conf.d/20-dom.ini,
/etc/php/8.0/cli/conf.d/20-exif.ini,
/etc/php/8.0/cli/conf.d/20-ffi.ini,
/etc/php/8.0/cli/conf.d/20-fileinfo.ini,
/etc/php/8.0/cli/conf.d/20-ftp.ini,
/etc/php/8.0/cli/conf.d/20-gd.ini,
/etc/php/8.0/cli/conf.d/20-gettext.ini,
/etc/php/8.0/cli/conf.d/20-iconv.ini,
/etc/php/8.0/cli/conf.d/20-igbinary.ini,
/etc/php/8.0/cli/conf.d/20-intl.ini,
/etc/php/8.0/cli/conf.d/20-mbstring.ini,
/etc/php/8.0/cli/conf.d/20-msgpack.ini,
/etc/php/8.0/cli/conf.d/20-mysqli.ini,
/etc/php/8.0/cli/conf.d/20-pdo_mysql.ini,
/etc/php/8.0/cli/conf.d/20-pdo_pgsql.ini,
/etc/php/8.0/cli/conf.d/20-pdo_sqlite.ini,
/etc/php/8.0/cli/conf.d/20-pgsql.ini,
/etc/php/8.0/cli/conf.d/20-phar.ini,
/etc/php/8.0/cli/conf.d/20-posix.ini,
/etc/php/8.0/cli/conf.d/20-readline.ini,
/etc/php/8.0/cli/conf.d/20-redis.ini,
/etc/php/8.0/cli/conf.d/20-shmop.ini,
/etc/php/8.0/cli/conf.d/20-simplexml.ini,
/etc/php/8.0/cli/conf.d/20-sockets.ini,
/etc/php/8.0/cli/conf.d/20-sqlite3.ini,
/etc/php/8.0/cli/conf.d/20-sysvmsg.ini,
/etc/php/8.0/cli/conf.d/20-sysvsem.ini,
/etc/php/8.0/cli/conf.d/20-sysvshm.ini,
/etc/php/8.0/cli/conf.d/20-tokenizer.ini,
/etc/php/8.0/cli/conf.d/20-xmlreader.ini,
/etc/php/8.0/cli/conf.d/20-xmlwriter.ini,
/etc/php/8.0/cli/conf.d/20-xsl.ini,
/etc/php/8.0/cli/conf.d/20-zip.ini,
/etc/php/8.0/cli/conf.d/25-memcached.ini,
/etc/php/8.0/cli/conf.d/xdebug.ini
How can I add my ini file when I running CLI commands?

When you using laradock, it's simple to change php version, everything config are set by .env.
So, open your .env, find PHP_VERSION change version to what you want and that's it.
Run docker-compose build workspace rebuild image, and your php-cli should be change to specific version.
Document: https://laradock.io/#change-the-php-cli-version

Related

PHP command line loading ioncube_loader?

Does anyone know why this happens? I cannot figure it out.
I run a command line PHP script (eg. prompt$ myscript.cgi) with this at the start:
#!/usr/local/bin/php81 -q
It runs fine using the PHP.ini at:
Configuration File (php.ini) Path: /opt/cpanel/ea-php81/root/etc Loaded Configuration File: /opt/cpanel/ea-php81/root/etc/php.ini Scan for additional .ini files in: /opt/cpanel/ea-php81/root/etc/php.d Additional .ini files parsed: /opt/cpanel/ea-php81/root/etc/php.d/01-ioncube.ini,
Now when I run the exact same script via a PHP 7.2 web page with shell_exec('/path/myscript.cgi') it will switch to PHP 7.2's ini.
Configuration File (php.ini) Path => /opt/cpanel/ea-php81/root/etc Loaded Configuration File => /opt/cpanel/ea-php81/root/etc/php.ini Scan this dir for additional .ini files => /opt/cpanel/ea-php72/root/etc:/opt/cpanel/ea-php72/root/etc/php.d:. Additional .ini files parsed => /opt/cpanel/ea-php72/root/etc/php.ini,
Why?

My computer has two php folders so I either can't connect to SQL Server or install Laravel

I spent two days setting up my PHP connection to SQL Server.
I downloaded the drivers, added them to the C:\Program Files\php\ext folder (as indicated by phpinfo()). Then I modified the php.ini file to add those extensions. Then I went to services and restarted "SQL Server EXPRESS". Nothing worked until I found that PHP is also installed in another folder on my PC: C:\Program Files\iis express\PHP\v8.0. So I added the drivers there too and changed the php.ini file and restarted the SQL Server EXPRESS service (is that what they mean with restarting your web server?). The phpinfo() page said:
Configuration File (php.ini) Path: no value
Loaded Configuration File: C:\Program Files\iis express\PHP\v8.0\php.ini
and there was no section "sqlsserver". I gave up and the next day it magically worked. The phpinfo had a "sqlserver" section and the connection to my database no longer said "Call to undefined function sqlsrv_connect()".
Now, I had to download Laravel for my course, and install Composer. When doing so, it was unable to install when I had C:\Program Files\iis express\PHP\ as my PATH and it asked me if I wanted to make C:\Program Files\php\ my PATH instead. So I clicked yes, and the installation was successful.
Laravel works, however now my database connections with SQL Server don't work anymore! I get the same old "Call to undefined function sqlsrv_connect()" error, and my phpinfo() now says
Configuration File (php.ini) Path:
Loaded Configuration File: C:\Program Files\php\php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)
and there is no longer a "sqlsserver" section on the page.
I have tried everything in StackOverflow articles, such as removing the semicolon in the php.ini extension, including the full address in the extensions in the php.ini file, including the extensions of the other php folder into this php.ini file, restarting SQL Server service, etc. But nothing works. I also don't know how to reset the old PHP folder back into the PATH variable.
My connection code is:
$con = sqlsrv_connect( 'localhost' ,
[ 'Database' => 'sample_db' ,
'UID' => 'sample_user' ,
'PWD' => 'sample_password' ]
);
//Print error message if the database doesn't connect
if ($con === false ){
echo 'Failed to connect to db: ' . sqlsrv_errors()[ 0 ][ 'message' ];
exit ();
}
How can I have these two php folder on my computer both work, the one for my PHP SQL Server database connection, and the other for my Laravel programme to run? Has anyone else had this issue and I so, what worked for you?
I managed to resolve this by changing the PATH back to the php folder instead of the iis/php folder. I was worried that would break my Laravel now, but it didn't.

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

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 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.

Failed loading php_xdebug message

When I run php from the command line (on Windows), I receive the following message
Failed loading C:\Users\Nickey K\Documents\AMD APP\bin\x86_64;C:\Users\Nickey K\
Documents\AMD APP\bin\x86;C:\Program Files (x86)\AMD APP\bin\x86_64;C:\Program F
iles (x86)\AMD APP\bin\x86;C:\Program Files\Common Files\Microsoft Shared\Window
s Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Prog
ram Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C
:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program F
iles (x86)\Calibre2\;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files
(x86)\Windows Live\Shared;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-
Static;C:\Program Files (x86)\EasyPHP-12.0\php\php544x120715104042;\php\php544x1
20715104042\php_xdebug-2.2.0-5.4-vc9.dll
x_debug seems to be installed properly based on phpinfo, and I have the following line in php.ini
zend_extension = "C:\Program Files (x86)\EasyPHP-12.0\php\php544x120715104042\php_xdebug-2.2.0-5.4-vc9.dll"
I've put the dll file in both the above the the ...\ext directory and tried a few variants of the above line, but I'm unable to get rid of this error message.
Any ideas?
The regular command line PHP from EasyPHP did not work as is. The problem is EasyPHP replaces the PATH variable with its own. That is just dumb that it doesn't use a different variable.
But, the following worked for me after some experimentations. I created a batch file php5.bat and placed it in C:\Windows\Sytem32 for easier access, with the following code (where C:\Program Files (x86)\EasyPHP-12.1\php\php548x121030011600 is the location my easyPHP php.exe was).
#echo off
REM Set the path for easy PHP and then start PHP.
set OLD_PATH=%PATH%
set PATH=C:\Program Files (x86)\EasyPHP-12.1
set PHP_DIR=C:\Program Files (x86)\EasyPHP-12.1\php\php548x121030011600
call "%PHP_DIR%\php.exe" -c "%PHP_DIR%\php.ini" %*
set PATH=%OLD_PATH%
#echo on
And then calling the batch file php5 -v will give you the php version. You might need to copy some DLLs from the Apache folder into the PHP folder as it will complain the DLLs are not found.
lets try to use zend_extension_tc instead of zend_extension if you're using window.

Categories