Mac php and xampp php.ini file

Hello,

I am having trouble with the php versions on my mac. When I am in terminal i get the php mac version.

I tried to install Yii2 advanced, and could not run yii migrate. I also could not get a virtual host to work.

Lots of information, but I cannot figure it out.

I believe I need to set the path to the xampp php, so terminal looks at that first. How do I accomplish that?

Thanks, Dan

I am on the latest El Capitan, and as your probably aware, your Mac comes with php installed. This can be confusing. The CLI (running PHP from terminal) actually will use your Mac’s included PHP and not the one from XAMPP. So far I haven’t ran into any issues with this. It could pose a problem if the script your running in CLI requires a specific PHP module to be installed. It could be installed for XAMPP but not for your included PHP. Say Zend, you add it to XAMPP but run the script from terminal and boom, errors. As for Yii, I haven’t had any issues from command line.

Before giving you the answer, I am going to tell you how to find out which php.ini both are using.

Open Terminal and navigate to your htdocs:


cd /Applications/XAMPP/xamppfiles/htdocs

Create a phpinfo.php file:


touch phpinfo.php

Edit the file and enter in the command to make php spit out it’s guts:


nano phpinfo.php

the content:


<?php

phpinfo();



To save and exit:




cmd + o

cmd + x



Open the file in your browser:


http://localhost/phpinfo.php

Run the file in Terminal CLI:


php phpinfo.php

You can compare the differences. The one in terminal is what came with your Mac. I had version 5.5 where XAMP had 5.6. The included php version on mine has no php.ini loaded, error_reporting had no value. It does say that it looks in "/etc" for the ini file. Remember, that is for the PHP which came with your Mac and only applies to anything PHP that you run from terminal itself. What you are interested in, is the PHP Info you ran in your browser, as that is what XAMPP is using.

In your browser’s phpinfo that you opened, look for the line for “Loaded Configuration File”. Mine shows this:


Loaded Configuration File:          /Applications/XAMPP/xamppfiles/etc/php.ini

So there you go. XAMPP’s PHP.ini on a Mac is located at: /Applications/XAMPP/xamppfiles/etc/php.ini

I wanted to point out the differences for you to keep in mind in the future, in case you ever have issues from Terminal (the CLI = Command Line Interface). So you know you actually have 2 versions of PHP.


On a Mac, you have to do this:


./yii migrate

In the root of the Yii app is an executable file named "yii". In order to execute files on a Mac, you put "./" in front of it.

While this question is old, I wanted to answer it just in case it helps someone else in the future.

1 Like