Reputation: 4817
Brief introduction to the problem:
I need to load pdo_mysql to run command php app/console doctrine:database:create
and other commands for Symfony 2.
I found a way to do this by running php -c "path/to/my/php.ini" app/console doctrine:database:create
Problem:
Since I don't want to add the path to my php.ini every time I run commands in PHP CLI, where/how can I set up Windows, so that every time I type php somecommand
in console it will load my desired php.ini file?
Upvotes: 2
Views: 8818
Reputation: 520
What if you add path/to/your/php.ini
to the path environment variable and then just run php -c "php.ini" app/console doctrine:database:create
Could you try that?
Upvotes: 1
Reputation: 2915
Create a .CMD file which automatically runs PHP with the required options:
path/to/php.exe -c "path/to/php.ini" %1 %2 %3 % %5 %6 %7 %8 %9
and call it something like phpcli.cmd
. Make sure it's on your search path and off you go. The only change you need to make is to run phpcli rather than php.
Upvotes: 3
Reputation: 2496
There are several ways to do it, but if you don't want to mess with an alias or making multiple copies of file php.ini, you can also set the PHPRC environment variable. I would think this is the recommended method to set it more "permanently".
More information in the PHP documentation: The configuration file
In Windows, an easy way to do this is to go to the "System Properties" dialog; either right-click on "My Computer" and click "Properties", or use the "System" item in Control Panel, then go to "Advanced" settings, click "Environment Variables", and click "Add" for either the system or your user, call it "PHPRC" and copy the path to your .ini file in there ... for example, mine was in C:\MAMP\conf\php5.6.28
.
(This was on Windows 7, and they changed some of the UI in different versions, but it's basically the same.)
You can verify it's working by doing php --ini
from the command line. The output should be something like:
Configuration File (php.ini) Path: C:\Windows
Loaded Configuration File: C:\MAMP\conf\php5.6.28\php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)
You can also do echo %PHPRC%
from the Windows command prompt, or echo $PHPRC
from Cygwin/Bash/MinGW, etc. You will have to restart any existing terminal sessions for this to take effect, but in my experience it works for all three, since the bash environments also inherit the Windows environment variables.
Upvotes: 2