I am trying to compile less file using php, and I am trying to use lessc which I installed as nodejs module on my windows 7
I am trying to do :
$command = lessc %s -compress %s
via
exec($command, $output);
and if I do this via cmd it works fine but I can't execute it using above command in php :(.
the path which works are relative to my drive (E:/wamp/my-project/less/hello.less)
Any body knows what I am doing wrong?
Note: I know how I can use lessphp compiler, and I am already using it but I would like to use lessc module installed via nodejs.
Are you able to get the output of the command when it fails? It's possible that lessc isn't directly available in your path. If you installed it via npm install -g then it will likely be in %appdata%, which is a user path'd directory. It really depends upon how the php process gets initiated, but my guess is that this path won't work.
If I need to use an npm module like this, I usually npm install it locally, and invoke the path to lessc.cmd from a relative path to my program.
Hope this helps. Happy coding!
Related
I tried to update my PHP version on my mac but I am facing some issues
When i use cURL it freezes and it will never complete the download on the terminal:
This is the cURL command that I am running is: curl -s https://php-osx.liip.ch/install.sh | bash -s 7.2
I tried to download a package manually but I can't extract it or even know how to install it.
You can use home-brew for installation / https://medium.com/#romaninsh/install-php-7-2-on-macos-high-sierra-with-homebrew-bdc4d1b04ea6 , I find it quite better then managing with Mac OS build in PHP
I don't have enough details so I will go in blind guess here.
First judging by screenshot it is stuck on downloading. For how long it was frozen? Maybe you didn't wait enough.
When you downloading the source what you need to do is:
Assuming you downloaded package with name php-7.2.6.tar.gz from PHP Official website.
Execute command tar xzf php-7.2.6.tar.gz from command line. (assuming you are in the same directory as file). It will unpack it in directory called php-7.2.6.
Enter the directory with command cd php-7.2.6.
Enter in terminal ./configure. It will take a while, so make sure to get some coffee.
After ./configure finished, execute command make. This will take a while as well, so you might get a sandwich.
Once command finished executing the last step will be executing command make install. It will be quicker than others, don't worry. After that you will be able to execute php command.
Optional Run make test to make sure everything is fine.
PHP has been installed, HOORAY!
Hope that helped, have a nice day. And if I answered your question, please mark it 'Answered`.
I have setup the bash feature on my Windows 10, it works well but I can't figure how to use it with PHP, despite a lot of research.
I would like to use a popen like this :
$fp = popen("tail ".$file, "r");
But the error.log says that tail is not recognized as an internal or external command. PHP don't recognize any bash commands but they are working in a shell.
I have try to edit the environnment variables, the PATH but nothing...
I would really appreciate some help, thanks !
You are running PHP from windows. Just because you have Linux Bash installed doesn't mean all the applications that are installed in it are available inside of windows. They are two completely different entities.
If you install php inside of Linux Bash and run the script from Linux it should work.
Another alternative is to install Git for Windows or Cmder or something else like this. They have a windows version of tail, you will just need to make sure it is added to your PATH in windows.
For normal Git for Windows installation you will find it at:
C:\Program Files\Git\usr\bin\tail.exe
I am trying to create a cron job that will back up my MySQL database. However it doesn't seem to ever call it.
I then tried to check if I could even run it from the terminal and I can't do that either. What is the problem?
I don't understand what the PATH variable means, I guess it must be something to do with that?
I'm just running php /var/www/html/backup.php
If php installed , go to the specified file location (cd to the file location in terminal) and enter below
php exampleFile.php
You need to install php if it's not there.
Try apt-get install php for debian http://php.net/manual/en/install.unix.debian.php
I've you've got it installed, try to use the full path to executable:
/usr/local/bin/php /var/www/html/backup.php
(Replacing /user/local/bin with the actual path to the php executable)
I'll explain what I'm trying to do, because someone might have a much better and completely different approach to this.
I'm trying to install FFMPEG, but not just install it, I'm making an automated installer that installs some PHP scripts and also FFMPEG if it's not already installed.
I can't find any automated PHP scripts that can install FFMPEG, so I'm guessing this is more difficuilt than I thought.
I had 3 options to do this:
Build from source on the server using the exec function, this
requires root permissions.
Find a pre-compiled binary of FFMPEG, easily done, and I did it, but
then I realised it didn't have the correct codecs so wasn't working.
Use YUM or APT-GET to install FFMPEG, this would be great but it
requires root permissions.
So, how can I either:
Use YUM/APT-GET from PHP and set sudo
OR
Install codecs for FFMPEG after it has been compiled. Using the pre-compiled binaries that I found, if it were possible then I could just install the missing codecs (lame mp3 I think. Maybe others too). Or do the codecs need to be built into the binary.
I think the prefered option is to use YUM/APT-GET as my targets are mostly Centos 5 and maybe Ubuntu aswell.
sudo in php is a lot easier if you use SSH. Among other things you can make use of "expect" to wait for the appropriate prompts. If there's a way to do that with the built in exec() or system() I'm not aware of it.
If you end up compiling from source or installing from a repo you can handle the install processs through this project that allows PHP to obtain and interact with a real Bash shell. Get it here: https://github.com/merlinthemagic/MTS
After downloading you would simply use the following code:
$shell = \MTS\Factories::getDevices()->getLocalHost()->getShell('bash', true);
$return1 = $shell->exeCmd('yum -y install FFMPEG');
//the return will be a string containing the return of the command
echo $return1;
You will need to deal with the edge cases when i.e. there is a GPG key that need to be accepted or dependencies are conflicting. But the project lets you script all Bash interaction.
My system has two PHP interpreters. One came bundled with the OS and the other I installed via the XAMPP package. All of my PHP extensions are applied to the XAMPP installation but PHPUnit seems to only run the version of PHP that came with my machine.
Does anybody know of a way I can configure or rebuild PHPUnit so that it uses my XAMPP PHP interpreter exclusively?
For Mac/Linux, the first line of the phpunit script with starts with
#!/usr/bin/php
change that to
#!/Applications/XAMPP/xamppfiles/bin/php
or whatever other php interpret you want to use.
Find the folder you installed PHPUnit in. There should be a file called phpunit.bat. It should have a line that reads something like
set PHPBIN="C:\php\php.exe"
%PHPBIN% "C:\php\phpunit" %*
Change it to read
set PHPBIN="C:\xampp\php\php.exe"
%PHPBIN% "C:\xampp\php\phpunit" %*
Or whatever the path to your PHP executable is
Since modifying phpunit file did not work for me because of phar signature errors, I was running phpunit with different php version by calling interpreter explicitly (on Linux):
php7.1 /usr/local/bin/phpunit
php5.6 /usr/local/bin/phpunit
Following the example with XAMPP, full path to php interpreter could be provided:
/Applications/XAMPP/xamppfiles/bin/php /usr/local/bin/phpunit
In agreement with Thomas' statement, additionally there's a line further below
if (strpos('/Applications/MAMP/bin/php5.3/bin/php', '#php_bin') === 0) {
set_include_path(dirname(__FILE__) . PATH_SEPARATOR . get_include_path());
}
That I've been told you're also supposed to change to reflect the PHP you're interested in using
(I've set mine to MAMP obviously)
I've switched back and forth from 5.2 and 5.3 a lot recently :)
This applies to phpunit installed using Homebrew on Mac OS 10.9. I’ve editing the file located at /usr/local/Cellar/phpunit/4.2.6/bin as seen below. CAVEAT: I don’t know how Homebrew will handle this on a PhpUnit update, but for now it’s working to be able to select the php version that PhpUnit is using for it's testing.
#!/usr/bin/env bash
php=/Applications/MAMP/bin/php/php5.3.14/bin/php
#php=/Applications/MAMP/bin/php/php5.4.4/bin/php
/usr/bin/env $php -d allow_url_fopen=On -d detect_unicode=Off /usr/local/Cellar/phpunit/4.2.6/libexec/phpunit-4.2.6.phar $*
On Windows, this may be achieved using a similar approach to the ones mentioned in other replies.
In your /path/to/composer/phpunit directory, open the phpunit file in an editor. The first line should look like this:
#!/usr/bin/env php
Simply download your desired version of PHP for Windows, place the contents of the ZIP file somewhere to your liking, and reference the fully quantified path to the php.exe file, instead of just php. Like so:
#!/usr/bin/env /c/misc/php-5.5.9-nts-Win32-VC11-x86/php.exe
In my case, I put it in /c/misc/php-5.5.9-nts-Win32-VC11-x86/, which corresponds to C:\misc\php-5.5.9-nts-Win32-VC11-x86\ using Windows path syntax.
Remember to verify that the correct php.ini file is being used (php --ini or in a script file php_ini_loaded_file()).