I installed less.js on my machine, but the module still reports less.js as missing.

The existing documentation is a bit thin in this area.

When I check on my console, it looks like the lessc file can be found.

Imac kevin$ which lessc
/usr/local/bin//lessc

So probably what I'm is missing is "Thus is it required that you configure your PATH for the user that your PHP installation runs under to ensure that these programs can be run by name without the full path."

How could I check / achieve this?

Comments

asimag’s picture

To get less.js (lessc) working in OS X
Visit http://nodejs.org and click on Install

After installation, you need to create symbolic link or set path.
First make sure that lessc is working in your terminal.

which node
which less

Create a Symbolic link:

sudo ln -s /usr/local/bin/node /usr/bin/node
sudo ln -s /usr/local/bin/lessc /usr/bin/lessc

and you are ready to go.

corey.aufang’s picture

You need to make sure that this is available for the user that is running PHP, usually the user that your web server process runs under.

In Ubuntu, Apache runs under the user "www-data". So you would need to make sure that "lessc" can be run by that user without using the full path to the binary.

Creating a symbolic link to the binary might help, but you need to ensure that it works for the user account in question.

sylvaticus’s picture

Same here, on Ubuntu 14.04.
I just tested php with this script:

echo ("Testing PHP capability to find lessc");
$output=array();
exec ("lessc -v",$output);
foreach ($output as $test){
  echo ($test.' ENDL\n');
}

and it works only when I specify the full path of lessc, meaning that, differently than normal users, www-user don't have /usr/bin in path.
I believe that the fact that /usr/bin is NOT in www-data path is to increase security. So, is there a way to add only lessc in path ? I guess simlinking it to an other directory and putting the path of that directory for www-data.. is this the right approach? How to add path to www-data ?
I know that this question is not strictly related with the module itself, but I guess it would help lot of users..

corey.aufang’s picture

When you installed less.js did you use the '-g' command line switch?

The '-g' switch as documented here and specified for less.js here installs less.js with the 'lessc' command available globally. I believe it does this by adding 'lessc' to global PATH.

On Ubuntu I found that it was simpler to use 'su' and install as root. Attempting to install as a regular user, even with 'sudo', caused many issues beyond not having 'lessc' available to the www-data user. I found this issue with any node.js module installed with npm.

I want to make this clear: I had issues installing on my system, which is my dev system and not a real server. I most likely had permissions issues, but it was too convoluted for me to diagnose and fix. You use 'su' at your own risk.

So if you're on Ubuntu, you can try using 'su' and then following the command line install instructions linked above. Make sure you use the '-g' option so that all users have access to the command.

You might need to purge any previously installed versions of less.js before proceeding.

You might also be able to switch to the www-data user and install under that user, but I don't know how well that would work.

K3vin_nl’s picture

Probably has to with my MAMP configuration, but on the command line I get these results:

mymac:drupal7 kevin$ id -un
kevin
mymac:drupal7  kevin$ which less
/usr/bin/less
mymac:drupal7  kevin$ which lessc
/usr/local/bin//lessc

When I run the same lines from a php file inside my drupal directory

echo ('user: ' . shell_exec('id -un') . '<br/>');
echo('less: " ' . shell_exec('which less') . '<br/>');
echo('lessc: ' . shell_exec('which lessc') . '<br/>');
user: kevin 
less: " /usr/bin/less 
lessc: 

So it is correct that lessc can't be found. However it looks like MAMP is running onder my user name and should be able to find it.

corey.aufang’s picture

Yeah, that is odd.

I won't be able to provide any help with OS X, sorry.