Configuring php-cs-fixer and PATH variable - php

A while ago, I successfully configured Atom to beautify my PHP using php-cs-fixer, but now I need to go through the same process on another Mac and can't remember exactly how I did it.
As a front-end dev, I'm not a PHP expert, but I understand that the Atom plugin is merely the middleman facilitating the actual fixing using php-cs-fixer, which, by default, it doesn't have access to. Once I installed the fixer, I had to add its location to my PATH variable. The confusing part is that I don't have the fixer installed via Atom (checked ~/.atom/packages) nor Homebrew (confirmed with brew list), however, the file is present in /usr/local/bin. If I move it, Atom returns the original error, so it's definitely using this file:
See https://github.com/FriendsOfPHP/PHP-CS-Fixer for program installation instructions.
Your program is properly installed if running 'which php-cs-fixer' in your Terminal returns an absolute path to the executable. If this does not work then you have not installed the program correctly and so Atom Beautify will not find the program. Atom Beautify requires that the program be found in your PATH environment variable.
Note that this is not an Atom Beautify issue if beautification does not work and the above command also does not work: this is expected behaviour, since you have not properly installed your program. Please properly setup the program and search through existing Atom Beautify issues before creating a new issue. See https://github.com/Glavin001/atom-beautify/search?q=php-cs-fixer&type=Issues for related Issues and https://github.com/Glavin001/atom-beautify/tree/master/docs for documentation. If you are still unable to resolve this issue on your own then please create a new issue and ask for help.
Hide Stack Trace
Error: Could not find 'php-cs-fixer'. The program may not be installed.
at PHPCSFixer.module.exports.Beautifier.commandNotFoundError (/Users/ourcore/.atom/packages/atom-beautify/src/beautifiers/beautifier.coffee:204:14)
at /Users/ourcore/.atom/packages/atom-beautify/src/beautifiers/beautifier.coffee:304:22
at tryCatcher (/Users/ourcore/.atom/packages/atom-beautify/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/Users/ourcore/.atom/packages/atom-beautify/node_modules/bluebird/js/release/promise.js:510:31)
at Promise._settlePromise (/Users/ourcore/.atom/packages/atom-beautify/node_modules/bluebird/js/release/promise.js:567:18)
at Promise._settlePromise0 (/Users/ourcore/.atom/packages/atom-beautify/node_modules/bluebird/js/release/promise.js:612:10)
at Promise._settlePromises (/Users/ourcore/.atom/packages/atom-beautify/node_modules/bluebird/js/release/promise.js:687:18)
at Async._drainQueue (/Users/ourcore/.atom/packages/atom-beautify/node_modules/bluebird/js/release/async.js:138:16)
at Async._drainQueues (/Users/ourcore/.atom/packages/atom-beautify/node_modules/bluebird/js/release/async.js:148:10)
at Async.drainQueues (/Users/ourcore/.atom/packages/atom-beautify/node_modules/bluebird/js/release/async.js:17:14)
at process._tickCallback (internal/process/next_tick.js:103:7)
which php-cs-fixer returns /usr/local/bin/php-cs-fixer and my PATH variable currently contains /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/ourcore/.atom/packages/php-cs-fixer.
I guess my questions are, how is the fixer working if the PATH variable seems to be pointing to it in a different location, and how did it end up where it is? Does the location in my PATH matter at all, or does the Atom plugin know to look in /usr/local/bin? I just want to fully understand the entire process before repeating it.
EDIT: On further testing, I removed the Atom directory from my PATH and it didn't affect the plugin, so then I copied the file into the same directory onto the second Mac and it ran without issue, without needing to edit the PATH. Does the fixer file someone inform the OS?

Well first test "which php-cs-fixer" or "where php-cs-fixer" (depending on what os you're running) and if nothing is returned in the terminal then there actually is something wrong on the installation and the best thing to do is to manually install it.
Head to https://github.com/FriendsOfPHP/PHP-CS-Fixer and download it from there and follow the installation steps, after that it should all be good

Related

"Cannot find script file" error but file is actually there

Disclaimer: am beginner.
I'm trying to build this certain PHP extension on Visual Studio Code 2017 in the Integrated Terminal, and I tried using the phpize command (there is an environment variable for the directory). It keeps outputting
C:\xampp\php\ext\php-geos
$ C:\xampp\php\php-src-php-7.2.6\win32\build\phpize
Input Error: Can not find script file "C:\xampp\php\php-src-php-7.2.6\win32\build\phpize.js".
Error generating configure script, configure script was not copied
even though it's right there. The file path is right. I checked the folder.
How can I fix this?
Found the problem: the .js file was actually a .js.in file. I solved the problem by changing the extension, but I guess another solution is to edit phpize and put .in where it is applicable.

.php files doesn't work in Visual Studio Code

I think I broke mi VS Code trying to join php and html syntax when I have a php file with html and php code.
The problem is that VS Code doesn't recognize .php files. The Select Language Mode shows as a 'Plain Text' and when I try to configure file association for '.php' doesn't appear.
I try a solution found "php.validate.excecutablePath" and I did not have results.
Finally I tried installing again VS Code after uninstall and delete all but doesn't work.
I don't know what to do.
I know it's very late lmao, but here's what I found; In order to make the setting re-appear, uninstall any extra php related extensions and restart vscode (you might also want to disable and re-enable php through searching "#builtin php" in extensions). That should bring the option back; then go and set up the path in the settings.json, and if you are a windows user add it to your environmental variables (specifically path).

which is the environment variables route for cakephp 3?

I recently installed a cakephp with composer to learn about framework use, and trying the bookmarks tutorial, but I get stucked in the checking your installation where you have to open the command line AKA cmd, and writing bin\cake.
It replies back: the system cannot find the path specified.
I've seen some information about how to set up the path variables but I'm guessing it's for version 2+ because apparently the cakephp 3 doesn't have a LIB folder like such:
YOUR_CAKE_DIR/lib/Cake/Console/
Any ideas on how to fix this?
Thanks
best regards!
***************UPDATE**********************
well, I've finally fixed the problem, the path I used for the cakePHP 3 instalation was:
c:\xampp\htdocs\caketest\bin
so I assume that If you aren't using xampp, it should point at the end to: cakeinstallation\bin...
my problem was that I always typed bin\cake but actually all I had to do was type only:
cake
you can read more information in here
bin\cake shouldn't require any special path settings other than being in the correct directory. However, you should make sure that php-cli is on your system's PATH. Depending on how you install PHP it could be in any number of places, but if php -v doesn't output the version of PHP you installed, you'll need to find where your installer put PHP and then setup the PATH environment variable.
With your example, AFAI remember the working directory they were executing cake binary was the parent of "bin" folder, in your case "caketest". I am talking without trying it (I dont have an environment close) you should use:
c:\xampp\htdocs\caketest> "bin/cake"
Watch the quotes. I think they are the main reason of that "the system cannot find the path specified."
I am supossing you are under windows (I saw xampp written in your post) and probably the xampp installation has already added the php folder in the PATH environment variable.

Symfony2 permission issue in OSX local environment

I wanted to try out the local apache environment that comes with OSX Mountain Lion.
I did the basic setup and placed a project in the root directory
/Library/WebServer/Documents/
Jumped over too localhost in my browser and everything was working as expected.
However I then decided to follow this guide in order to use the Sites folder in my home directory, for simplicity sake.
http://osxdaily.com/2012/09/02/start-apache-web-server-mac-os-x/
I then reset apache and added this to my browser
http://127.0.0.1/~bengibson/PracTest/
The browser shows a list of a few of the files and directories in the project folder but not all of them :S.
I tried to navigate to one of the missing folders
http://127.0.0.1/~bengibson/PracTest/web/app_dev.php
But I get a forbidden message :(
Anyone know what this needs?
Just for reference here is the project folder
Heres the detailed view in of the folder in terminal
And here is what shown in the browser
I ran into this problem before on OS X when I downloaded the archive file for the Symfony 2 Standard Edition directly in the browser.
The # symbol at the end of the permissions table indicates that the file has additional attributes.
You can see these additional attributes by typing the following command in Terminal as an example, explained here.
$ xattr -l ~/Sites/PracTest/web/app_dev.php
The result returned is com.apple.quarantine.
This is the way OS X protects potentially malicious files downloaded from the internet from being readily available, which is why in Finder you get the warning box alerting you about opening a file downloaded from the internet.
In your case, to remove these extended attributes, run
$ xattr -rd com.apple.quarantine ~/Sites/PracTest
IF you wanted to know what this command does:
The -d flag removes the extended attribute specified after it, followed by the path.
The -r flag acts recursively, on all subfolders and files.
You should now be able to access both app.php and app_dev.php in the browser.
I'd also like to take the opportunity to recommend creating a new Symfony2 project with Composer rather than downloading it directly. It's hard to look back.
For anyone else who may happen on this blog, I had a similar issue and after a bit of looking around I found that I had forgotten the 'FollowSymLinks' Option in the username.conf file
sounds like permissions.
right click folder, get info, unlock with admin password bottom right and make all users able to read and write. then click the gear looking menu below it and tell it to apply to all contents within as well.

PHPUnit not responding - is this a PHPUnit.bat error

Can someone with a working Zend/PHPUnit installation tell me how PHPUnit.bat should read?
I have installed PEAR and PHPUnit, but PHPUnit.bat appears to have an error in its code.
Having worked through a few issues, I no longer get 'PHPUnit is not a recognised command' error. But if I now call "PHPUnit" in the command line nothing at all happens except the command prompt reappears. Indicating some code may have run.
I did some reading and PEAR should be calling a .bat file in 'c:\zend\zendServer\bin'. I opened this and there is a very short block of code.
if "%PHPBIN%" == "" set PHPBIN=c:\zend\zendserver\bin\php.exe
if not exist "%PHPBIN%" if "%PHP_PEAR_PHP_BIN%" neq "" goto USE_PEAR_PATH
GOTO RUN
:USE_PEAR_PATH
set PHPBIN=%PHP_PEAR_PHP_BIN%
:RUN
"%PHPBIN%" "C:\Zend\zendServer\bin\\phpunit" %*
The final line looks incorrect, notably the double slash. I have tried various derivations such as 'bin\pear\phpunit etc', but are not sure where this should be pointing.
Can anyone with a working ZendServer/PHPUnit installation tell me how this line should read.
Also, I should also ask, is calling 'PHPunit' in the cmd line the best way to test if the package has installed correctly. Ideas appreciated. The PEAR install call suggested the install should be working fine.
UPDATE
I just created a new project through the zend framework CLI tool and got a note that PHPUnit was not found in my include_path. I have both PEAR and PHP on my include path do I need something else?
UPDATE
I found this post on a potential test Getting PHPUnit Working - Include Path not set correctly?, which provides a way to test phpUnit. I saved the suggested PHP script in my htdocs folder and tried to call it with PHPUnit. Once again no response, which seems to suggest that there is a n error in my PHPUnit.bat file.
Okay this has been a nightmare, but I think I have a solution for anyone facing the same issues.
Question One: how do I test if PHPUNit is working.
Answer: typing PHPUnit into the cmd line will give you a list of all the commands and so acts as a good test as to whether the install has worked.
Question Two: What should PHPUnit.bat look like.
The text above is correct and the extra slash in PHP.bat does not affect the output as ta.speot.is notes.
Solution to get install working:
The issue in this case related to an anomaly with Zend Server. A change to the php config file PHP.ini does not seem to get picked up by the server. It appears that Zend stores the path variables somewhere else. I noted that the changes to the include_path had not been picked up and changed it through the GUI server interface provided with the install.
PHPUnit is now working correctly.
For those struggling with an install I would add two lessons to add to the huge range of posts on the topic.
1) if you have ever had Zend on your computer. Beware an uninstall leaves trace files that can complicate later installs.
2) There is PHPUnit.ini file that gets saved in the c:\windows directory be sure to delete this before starting the install.
3) The following link is an excellent set of instructions http://www.zendexperts.com/2011/06/21/how-to-install-zend-server-ce-pear-phpunit/.
The only change I would make is when using go-pear.php to install PEAR, do not activate errors as suggested in the post, otherwise the interface does not seem to work and issues a large number of errors in the PEAR php.
Hope this helps someone save a couple of days.

Categories