I am creating a Wordpress plugin that utilizes PDFTK. I followed the documentation for php-pdftk and my PHP looks like this:
$pdf = new Pdf('/pdf-templates/testpdf.pdf', ['command' => 'C:\Program Files (x86)\PDFtk\bin\pdftk.exe',
'useExec' => true]);
$pdf->fillForm($data)
->flatten()
->saveAs('/generated-pdfs/' . $filename);
I installed php-pdftk using composer and the commands follow through fine. I installed pdftk using
sudo apt-get install pdftk and it runs correctly in my Ubuntu terminal. I am developing on a local version of Wordpress hosted in a Docker container with a WSL2 backend.
I have tried installing pdftk locally to my windows machine and passing the path directly as well as using the Ubuntu installation, but neither command passes and both fail. I used the methods from this question to check whether the command was executing and it isn't, which leaves me to believe that my path is the issue, but even passing the absolute path through did not help. I believe it may be something to do with using Docker. This needs to be usable on a live server as well, so I want to avoid using the local windows install but I needed to test if that would work either. I am totally stumped, and any help would be greatly appreciated
I should also mention that even after installing the local version of pdftk, Powershell, CMD and Git Bash did not register it as a command, but I assumed that since I was passing the hard path to the application it didnt matter if my windows PATH was wrong
Related
I'm trying to install phpunit manually on my windows machine. I don't use composer, so I have to install it manually with a .phar file. I'm following the instructions from the official documentation:
https://phpunit.readthedocs.io/en/latest/installation.html#windows
I've done every step, but it won't work. phpunit --version will throw me the message 'phpunit' is not recognized as an internal or external command, operable program or batch file. Can someone Help me?
I'm using Windows 7 64-bit with XAMPP 3.2.2 and PHP 7.1.1.
EDIT:
My phpunit.cmd file location is C:\xampp\php\phar\phpunit.cmd.
The file contains the code #php "%~dp0phpunit.phar" %*. I've added ;C:xampp\php\phar to my PATH variable.
In order to make Windows recognize any command, you must put the binary's path in the relevant environment variable (PATH). Before that you need to create some kind of file Windows can run natively (i.e. not a .phar – can be a command line / batch file or executable). Here are instructions:
https://phpunit.de/manual/current/en/installation.html#installation.phar.windows
Edit: If following the above instructions, it's also important to make sure that php itself is part of the PATH environment variable, so that it's possible to execute commands like php phpunit.phar.
I want to use another php version on my machine than the one already installed using WAMP (2 PHP version installed).
The composer installed uses PHP 5.6
A new project requires PHP7.0.
Whenever I choose PHP 7 from the control panel of WAMP and then run php -v it still printing PHP5.6 (CLI)... instead of PHP7.
How can I use PHP7 without reinstalling the composer again?
You can change php version of composer without uninstalling it, follow these steps :
Search for system environment variables in cortana.
Click on the button "Environment variables".
Under "System variables" select path and click on edit, you will see one entry like this "C:\wamp\bin\php\php5.6.13".
Just change this to the folder name of the php located at your wamp/bin/php7.1.9, here php7.1.9 is folder name.
Replace php5.6.13 with bin7.1.9, it will look like these "C:\wamp\bin\php\php7.1.9", just click ok on all the boxes.
You are done.
To verify, first close all the cmd windows, than open cmd and type php -v, press enter and you should see php7.1.9.
If you don't see change in php version than just restart your pc and run php -v again in cmd , it will work.
I'm assuming Windows if you're using WAMP. Composer likely is just using the PHP set in your path: How to access PHP with the Command Line on Windows?
You should be able to change the path to PHP using the same instructions.
Otherwise, composer is just a PHAR file, you can download the PHAR and execute it using any PHP:
C:\full\path\to\php.exe C:\full\path\to\composer.phar install
If anyone is still having trouble, remember you can run composer with any php version that you have installed e.g. $ php7.3 -f /usr/local/bin/composer update
Use which composer command to help locate the composer executable.
I found a very easy way to switch php versions:
Search for system environment variable
Click on "Environment variables"
Under "System variables" select path and click on edit
Move the PHP version folder you want to use before the other one.
So for example: php 7.0 will now be used:
Close all windows by clicking "OK"
Close all the cmd windows, than open cmd and type php -v
You will see the correct php version loaded now:
Another possibility to make composer think you're using the correct version of PHP is to add to the config section of a composer.json file a platform option, like this:
"config": {
"platform": {
"php": "<ver>"
}
},
Where <ver> is the PHP version of your choice.
Snippet from the docs:
Lets you fake platform packages (PHP and extensions) so that you can emulate a production env or define your target platform in the config. Example: {"php": "7.0.3", "ext-something": "4.0.3"}.
This is what happens in my case. I hope this may help to someone have same situation. I'm using macOS Monterey with MAMP.
I linked the php 7.4 using ~/.profile file. So the terminal it says I'm using php 7.4. However, still my composer giving an error saying i'm using php 7.3.
So I check the php path using
which php
This gives me the /usr/local/bin/php as my php cli location. So I remove the file and made a symlink to my php7.4 and now working perfectly.
sudo rm -rf /usr/local/bin/php
sudo ln -s /Applications/MAMP/bin/php/php7.4.21/bin/php /usr/local/bin/php
I found out that composer runs with the php-version /usr/bin/env finds first in $PATH, which is 7.1.33 in my case on MacOs.
So shifting mamp's php to the beginning helped me here.
PHPVER=$(/usr/libexec/PlistBuddy -c "print phpVersion" ~/Library/Preferences/de.appsolute.mamppro.plist)
export PATH=/Applications/MAMP/bin/php/php${PHPVER}/bin:$PATH
Old question I know, but just to add some additional information:
WAMP is used only on Microsoft Windows Operating Systems.
Changing the version of PHP used through the left-click -> PHP -> Version menu changes the version used by Apache to server your site.
Changing the version of PHP used through the right-click -> Tools -> Change PHP CLI Version menu changes the version used by WAMP's PHP CLI.
Note: It is important to understand that the "PHP CLI Version" is used by WAMP's own internal PHP scripts. This "PHP CLI Version" has nothing to do with the version you wish to use for your scripts, Composer or anything else.
For your scripts to work with the version you require, you need to add it's path to the Users Environmental Path. You could add it to the Systems environmental Path but the Users Path is the recommended option.
From WAMP v3.1.2, it would display an error when it detect reference to a PHP path in the System or User Environmental Path. This was to stop confusion such as you were experiencing. Since v3.1.7 the display of this error can now be optionally displayed through a selection in the WampSettings menu.
As indicated in previous answers, adding an installed PHP path (such as "C:\wamp64\bin\php\php7.2.30") to the Users Environmental Path is the correct approach. PS: As the value of the Users Environmental Path is a string, all paths added must be separated with a semi-colon (;)
After experiencing the exact same problem (IE: Choosing which version of PHP I wanted Composer to use), I created a script which could easily and rapidly switch between PHP CLI Versions depending on what project I was working on.
The Windows batch script "WampServer-PHP-CLI-Version-Changer" can be found at https://github.com/custom-dev-tools/WampServer-PHP-CLI-Version-Changer
I hope this helps others.
Good luck.
After a long search on the internet and finding many unrelated answers / ones that did not work for me, Here is what worked for me.
Those who are in shared hosting know that bin directory is write-protected and running sudo commands or any system-wide command is not allowed.
There's two ways of solving this:
Run the command directly on your project folder selecting the appropriate PHP version you need.
ea-php80 /opt/cpanel/composer/bin/composer update
To get available PHP on your server type ea-php and hit TAB to see a list.
make an alias to composer
Run this command to edit/make this file nano ~/.bashrc
Inside that file, put alias composer="ea-php80 /opt/cpanel/composer/bin/composer"
This gives you the flexibility to run composer commands as usual without those long trailing strings
If you are using Windows, all you have to do is change the path to php.exe in the composer.bat file located in: "C:\ProgramData\ComposerSetup\bin".
In my case I include paths to all php versions, whenever I need to run a project on a specific php version, I just move the required path to the top (using these buttons in the right) and then close all the terminals and restart my wampp server.
The path with listing in the will be selected as your php version by windows
This is the simplest solution I think.
If you still facing the problem after changing Environment variables in windows, try to delete directory or just rename directory of your old php.
I've done it and it's work.
I will assume that you need this because a requirement to have multiple php versions installed to handle multiple projects.
If this is the case a prefer to run directly the php desired bin pointing to the executable script of composer, for example, in my case I have php 8.1 and 7.4, my main php version configured for CLI is 8.1, but I want to run composer with 7.4 in some projects, so I run this command:
php7.4 -f /usr/local/bin/composer install
Where php7.4 is the bin installed and my global composer script is in /usr/local/bin/composer
From there, you can make an alias like this to facilitate things: alias composer7.4='php7.4 -f /usr/local/bin/composer ' so next time you need to run composer with php#7.4 you only need to run: composer7.4 install
Came here by the title, but the question specifies WAMP; which this may not easily apply to. So, in my case - using a Mac.. so more like a MAMP - if you have brew and the below versions installed, this could help - and composer picks it up.
brew link --overwrite --force php#8.1
php -v
#PHP 8.1...
brew link --overwrite --force php#7.4
php -v
#PHP 7.4...
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'm using linux and installed xampp that already provided php in its package. Then, I add "export PATH=/opt/lampp/bin:$PATH" to my "~/.bashrc" so that I can use every commands that is provided in xampp directly from my terminal (without needed to pointing to "/opt/lampp/bin"). Everything works fine.
My problem is I'm using netbeans and when I tried to execute my program, it said "/usr/bin/env: php: No such file" I know it happened because there's no php in my "/usr/bin" since I have it via xampp, but I do have it in my "/opt/lampp/bin". How to configure PHP in netbeans so that it's pointing to "/opt/lampp/bin", instead of "/usr/bin"?
I've googled it and they said that I need to install php-cli, which I think is not a good choice since it makes me have two php in my system. IS there any way for me to use netbeans and php from xampp without needed to install php-cli?
I've also tried to Tools->Options->PHP-General and provide PHP interpreter poiting to "/opt/lampp/bin/php" but it didn't work.
Have you e.g. restarted OS after editing .bashrc file? Or run in command line
. ~/.bashrc
to apply changes in bashrc and then start NetBeans and give it another try. Another option could be to use symbolic link
sudo ln -s /opt/lampp/bin/php /usr/bin/php
If you run "which php" does it point to the lampp directory?
While following the "Practical Symfony" course, I have run in a strange error.
I have installed a Debian Squeeze in a VMWare 6.5.5 machine. It comes with PHP 5.3.3 and I am using Symfony 1.4. The source files are on the host, I am accessing them using the shared folder feature (vmhgfs mount).
Now, when I try the following commands, I get an error:
php symfony doctrine:build --model
php symfony doctrine:build --sql
Error:
PHP Parse error: syntax error, unexpected ')' in /var/www/appli/lib/model/doctrine/base/BaseJobeetJob.class.php on line 144
What is funny is that when I :
- do the same thing without the shared folders (e.g. on a ext3 partition), it works,
- convert the VM to VirtualBox and do the same thing on a shared folder, it works,
- downgrade the PHP to 5.2.6 (from lenny), it works.
I remember having the same kind of issue some time ago with the PHP code generated by Smarty. As it was automatically generated PHP and could be regenerated at will, I had it generated in a local direcorty. But I do not think this is applicable to Doctrine generated files.
Does anyone have any clue of what is happening and how I could fix it ?
EDIT: here is the code around line 144:
public function setUp()
{
parent::setUp();
$this->hasOne('JobeetCategory', array(
'local' => 'category_id',
'foreign' => 'id',
'onDelete' => 'CASCADE'));
$timestampable0 = new Doctrine_Template_Timestampable();
$this->actAs($timestampable0);
}
} // Line 144 here.
It is actually the end of the file...
EDIT #2: to make it clear I have tested the following combinations in order to narrow down the issue:
VM software : VMWare Workstation
6.5.5 / VirtualBox 4.0.8
PHP version: 5.3.3 / 5.2.6,
Mount type : vmhgfs (or vboxsf with VirtualBox) / ext4 (local)
/ cifs (aka Windows share).
In every case I am using the very same source files (but for ext4 because I had no other choice than to copy them). I have a failure when combining the bold items. If I change any one of them, everything goes fine. I also tried to use the open-vm-modules in place of the provided vmware tools and to build a Debian installation from scratch instead of using my own automated script but neither has changed anything.
This seems to be a bug in vmhgfs - I have the same issue working with Drupal PHP code. It also seems to only happen when the files are added to the host from the guest, for example using git to clone a repository in the Linux VM.
There are three workarounds:
Copy the files into their desired location, then disable shared folders in VMWare settings for the virtual machine, refresh the web page so you get 'Not found', then re-enable shared folders.
On the host machine, run the following command which updates the file access / modified timestamps for every file, thus causing the VMWare driver to reload the file, fixing the issue:
find . -exec touch {} \;
Open the affected file from the host machine, modify it, and save it back. This may be useful if you're on a Windows machine.
The errors range from PHP Parse errors to others, normally flagging the last line of the file.
I have the same problem on OpenSUSE 11.4 with PHP 5.3.5 using vmhgfs (on a Mac). I am also using doctrine, however I am using it without the full symfony project.
Initially vmhgfs didn't work at all, so I downloaded the open-vm-tools and compiled/installed that. That solved my problem for a few weeks, but it came back today.
The issue appears to be php reading past the end of the file. If I read the file with cat, less, or tail, then the end of the file looks fine.
But if I do php -s bad_file.php > bad_file.php.html and look at the html output, I can see at the end of the file there is some extra garbage that I don't see with with cat, less, or vim.
You can see that php sees "array (" at the end of the file, while other tools do not see that.
The only solution I've found is to manually add a new, blank line at the end of each problematic file. For some reason it only affects 1-2 files out of about 40.
Same problem here. I confirm that it is a vmhgfs problem.
A workaround is to use a NFS share instead of vmware shared folders:
Linux env
apt-get install portmap nfs-common nfs-kernel-server
mkdir /nfs-share1
echo "/nfs-share1 192.168.2.1(rw,sync)" >> /etc/exports
/etc/init.d/portmap start
/etc/init.d/nfs-kernel-server start
/etc/init.d/nfs-common start
usermod -u 501 paolo
find / -user paolo -exec chown paolo {} \;
OS X env
showmount -e 192.168.2.129
mkdir /Users/paolo/netshare1
mount -t nfs -o resvport,soft,intr,rsize=8192,wsize=8192,timeo=900,retrans=3,proto=tcp 192.168.2.129:/nfs-share1 /Users/paolo/netshare1/
Ugh! Finally I figured it out. I'm using VMware Fusion (4.0.2) on Mac OS X Lion (10.7.2) and I've been pulling my hair out trying to figure this out.
Upgrade your VMware Tools!
So far, so good: Haven't encountered the problem again. The latest release at this time is VMware Tools 8.0.0.
Well, this might be off topic, but I hope it helps:
I am working on the same book, and I have done this (I think you'd better do something like me):
Installed Ubuntu Server inside VirtualBox
Installed LAMP Server on Ubuntu
Installed vsftpd, for ftp access on Ubuntu
Installed SSH server on Ubuntu.
Now, if I am on Linux host, I use Aptana Studio with ftp access for editing files and SSH to run commands, and if I am on Windows, I use Aptana Studio and Putty for SSH access.
If you do something similar, you will probably have no trouble.
Hope it helps.
I am also experiencing this problem in regards to Wordpress and Laravel. To fix the problem, I have to remount the mounted folder from the guest.
For instance, all my source files are located on the host (OSX) and shared to Ubuntu (guest) with vmhgfs. The mount point is /mnt/hgfs/www. To remount:
sudo mount /mnt/hgfs/www