Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MAMP exec command in php cannot find mysql in apache env (works in CLI)

Tags:

php

macos

I am using MAMP pro latest version Mac OS X 10.10

FROM cli I can run the following and it works:

exec("mysql --host=$db_host --user=$db_user --password=$db_password $db_name < $sql_file"); 

FROM apache/php it doesn't work and cannot find the executable.

It DOES work from apache/php if I do the following:

exec("/Applications/MAMP/Library/bin/mysql --host=$db_host --user=$db_user --password=$db_password $db_name < $sql_file"); 

What do I need to change to get this to work? It seems for some reason the environment variables aren't available when running from apache/php.

like image 402
Chris Muench Avatar asked Jul 23 '26 11:07

Chris Muench


1 Answers

I solved this by finding out the the environment path was /usr/bin:/bin:/usr/sbin:/sbin

I find this via phpinfo. I then symlinked mysql and mysqldump into /usr/bin and that solved my problem. I was I knew how to add paths to php; but this was good enough for what I needed.

like image 169
Chris Muench Avatar answered Jul 25 '26 02:07

Chris Muench