I have installed XAMPP on a Windows XP Machine. PHP scripts are working fine through the browser.
Initially, PHP.exe (CLI) was failing with error - can't load php_pgsql.dll
I disabled extension=php_pgsql.dll in the php.ini file and PHP.exe stopped to fail.
However, even now I am not able to run a PHP script from the CLI even though the same script runs fine through the browser.
The script fails at mysqli_connect() with error - Can't connect to MySQL server on '127.0.0.1'
Has somebody else faced the same problem?
Kshitij
Did you start the MySQL service via the XAMPP Control panel and it kept beeing marked as "Running" in both test cases?
Did you test the webserver version by requesting something like http://localhost/... or http://127.0.0.1/... and did you run the php.exe -f something.php test on the same machine?
How many php.ini have you got? It's likely the CLI version has a different php.ini than the web version.
Is the path to your mysql DLLs in your command session's PATH environment variable? You probably need to add \pathtomysql\bin to your path. On my machine it is:
C:\Program Files\MySQL\MySQL Server 5.0\bin
Related
I downloaded the installer version of Xampp version 8.1.6-0 for Mac and went to the manager-osx widget to start the Apache and MySQL servers but neither would start.
I then tried using the command sudo apachectl start and then created an index.php file and put it in htdocs, and then tried to open it using http://localhost/index.php as well as http://localhost:8080/index.php and both times it said the server could not be reached.
I've actually downloaded Xamp in the past and was able to reach the server but wasn't able to get php scripts to run, but now for some reason I can't even get the server to run.
I made sure to download the installer and not the virtual machine version. I'm running Monterey version 12.4.
I tried the solutions here but they didn't seem to work. I checked my activity monitor and nothing is running on port 80.
I also installed MAMP from here and tried to start Apache but it displayed the error:
"Apache couldn't be started. Please check your MAMP installation and
configuration."
Any help would be appreciated as I just want to run PHP.
I run MAMP on my Mac at home, but on my work machine (Win7) I just started using MAMP for Windows so that I'm running the same (relatively speaking) software between the two machines. I was running some commands from the command line yesterday and noticed that the script was throwing errors because the mbstring extension wasn't loaded. I did some digging and am left scratching my head now...
In the browser, everything works fine. When I check the phpinfo, it's loading the configuration file just fine and mbstring is enabled. When I switch to the command line though, mbstring isn't in the list of modules (php -m). Also, when I do a php --ini, it tells me that no configuration file was loaded. I've added the correct PHP version to my PATH and running php -v gives me the version I expect, so I'm not really sure why PHP on the command line is acting differently from PHP in the browser.
Has anyone run into this before? How do I make PHP on the command line load the same configuration file that the browser is using?
Command line php (CLI) is a different executable to CGI PHP. It also uses typically a different php.ini file. You can however specify the location of the php.ini you would like to load when launching php cli:
php -c <path to your php.ini>
Have a look here.
This example assumes you use C:\MAMP\ as installation directory.
As you need configuration as used in Windows MAMP you will need to supply it as argument to php.
Open command prompt.
To execute test.php with script located in C:\MAMP\htdocs\ by using PHP5.6.0 from MAMP:
C:\MAMP\bin\php\php5.6.0\php.exe -c "C:\MAMP\conf\php5.6.0\php.ini" "C:\MAMP\htdocs\test.php"
As you can notice last argument is the script to be executed ("C:\MAMP\htdocs\test.php").
To execute phpinfo from command line:
C:\MAMP\bin\php\php5.6.0\php.exe -c "C:\MAMP\conf\php5.6.0\php.ini" -r phpinfo();
There should be line from phpinfo output which acknowledges that you're using configuration from C:\MAMP\conf\php5.6.0\php.ini.
Loaded Configuration File => C:\MAMP\conf\php5.6.0\php.ini
I am trying to run a PHP Script on my apache server installed with xampp under Linux but seem to have some user/file permissions issue. I have installed php cli and the path name is all correct.
My command is this and it does not do anything.
/usr/bin/php /home/eem/website/cron/cronjob_test.php
When I run it as wget or curl instead of php it executes correct. I know that curl+wget run with the apache user and php cli runs with the cron user.
So the fact that php does not execute should have something to do with the apache configuration in xampp or some user permissions but I really have no idea what the problem is.
Any help will be appreciated!
PHP 5.2.5
Microsoft IIS 6.0
Windows Server 2003 R2
I have just enabled php_printer.dll in my php.ini file, and it works correctly from the command line. However, running the same commands within a script running on IIS gives me a "call to undefined function printer_open() ...". My boss says we shouldn't have to restart IIS to get it to work, and is unwilling to try, because of the few mission-critical apps we have running on that server. Is restarting IIS necessary, or should the commands be accessible from a script as well as from the command line?
I suggest you ask on serverfault whether a IIS Process Recycling is advisable to reload php/isapi.
I have CakePHP (cake_1.2.2.8120) and EasyPHP (3.0) installed on Windows Vista Ultimate. I followed the "baking" tutorials online and successfully set the database connection with the "cake bake" command from the CLI.
I baked the controller for my "Users" table using the "php cake.php bake controller Users" command - worked fine. However, when I tried baking the view similarly, I got this message:
Fatal error: Call to undefined function mysql_connect() in C:\Web\EasyPHP
\www\cake\cake\libs\model\datasources\dbo\dbo_mysql.php on line 374'
Also, the MySQL module is enabled for PHP on the phpMyAdmin page (web), but I can't find it in the CLI (using "php -m" from the command line) even though I've uncommented the "extension=php_mysql.dll" line in the php.ini file.
How can I fix this?
Grab XAMPP which has Apache with the MySQL and PHP modules setup and working together, as well at the MySQL and command-line versions. It just unzips to any directory, so it won't mess up any other Apache installs you have. Just be careful of any port conflicts between the different installations.
Download XAMPP
The root cause of the problem is that in EasyPHP 5.3 there isn't any php.ini file in the php folder.
Copy php.ini from EasyPHP5.3\apache to EasyPHP5.3\php to solve this nasty issue.
Copy the apache/php.ini file to php/php.ini.
I don't know EasyPHP, but it seems to be Apache-based. Check if you're using a Apache-module for the MySQL connection, as this will not work in CLI.