Run lime build command from a PHP script


I’m running Ubuntu 14.04. I would like to run the lime command from a PHP script using the shell_exec function. The command is to build a swf:

/usr/bin/lime build project.xml flash

The command works if I run it in a terminal, everything is properly set up on my system. But when I run it from my PHP script, I get this output:

This is the first time you are runing haxelib. Please run `haxelib setup` first

I guess this is because the haxelib path is not set up for the user www-data who executes the PHP script so I tried to add these environment variables in my /etc/profile file:


But unfortunately, this still does not work, I got the same error output. Can someone help me on that?

It looks like haxelib is searching for the following:


Perhaps you could set the “HOME” environment variable to trick it into working. This is likely occurring because the PHP script is being executed as a different user, another option would be to copy .haxelib from your user directory to the user directory of what PHP uses (if it exists). Long-term, though, this would be a great thing to be fixed in haxelib :confused:

Thanks for your reply.

You are right. Setting the HOME env variable makes it work:

PHP Script:


$output = shell_exec('/usr/bin/lime build Path/To/project.xml flash');

According to the PHP doc, the env variables set by putenv are restored to their initial state when the script is done. So I guess there is nothing else to worry about except if an other process makes use of the $HOME var at the same moment.

It’s not clean but that should do the work for me.
Thanks again!

A better way to do that in my opinion is to copy the .haxelib file to the /var/www directory the PHP script uses as home directory as you also suggested. This works as well and no need to change anything in the environment variables!
Thank you :smile:

haha, awesome, glad this is working! :smile: