Installing PHP_codesniffer with Pear and MAMP Pro on OSX - macos

I've tried all kinds of fixes to get php_codesniffer working with OSX and Pear and am having no luck. The installation works, the scripts are there, but when I run, for example, phpcs -h, nothing happens.
I am doing the following to install and try to run:
chris#DEATHSTAR:~$ pear clear-cache
reading directory /var/folders/r5/3s2lsmc10zj07nw56xbx1k1m0000gn/T//pear/cache
14 cache entries cleared
chris#DEATHSTAR:~$ pear install php_codesniffer
Unknown remote channel: pear.phpunit.de
Did not download optional dependencies: channel://pear.phpunit.de/PHP_Timer, use --alldeps to download automatically
pear/PHP_CodeSniffer can optionally use package "channel://pear.phpunit.de/PHP_Timer"
downloading PHP_CodeSniffer-1.4.6.tgz ...
Starting to download PHP_CodeSniffer-1.4.6.tgz (402,882 bytes)
.................................................................................done: 402,882 bytes
install ok: channel://pear.php.net/PHP_CodeSniffer-1.4.6
chris#DEATHSTAR:~$ which phpcs
/Applications/MAMP/bin/php/php5.4.10/bin/phpcs
chris#DEATHSTAR:~$ phpcs -h
chris#DEATHSTAR:~$
The PHP directory is correct in Pear config:
chris#DEATHSTAR:~/.vim$ pear config-show | grep php_bin
PHP CLI/CGI binary php_bin /Applications/MAMP/bin/php/php5.4.10/bin/php
Not sure what else I can do to troubleshoot?
Possible related note: PHP Mass Detector does essentially the same thing...it installs correctly, but running it seemingly does nothing as well!

I think the phpcs binary file is not inside your $PATH. Use the follow steps to figure out if this is true:
Call the codesniffer on your command line with entering the full path:
$ /Applications/MAMP/bin/php/php5.4.10/bin/phpcs -h
If you get the help output then proceed with step 2. If not something else is broken in your setup.
Export this path to $PATH:
$ export PATH=$PATH:/Applications/MAMP/bin/php/php5.4.10/bin/phpcs
Call the CodeSniffer like you try before:
$ phpcs -h
To make this change permanent you need to insert the command from 2. into you .profile/.bashrc/.zshrc or whatever you use as a shell

Related

Installation of Xdebug on MacOS Catalina 10.15

I tried to install Xdebug on OS X 10.15 and run into following problem:
/private/tmp/pear/install/xdebug/xdebug.c:25:10: fatal error: 'php.h' file not found
I tried to fix the problem like described here: Installing xdebug on MacOs Mojave - 'php.h' file not found
Unfortunately the header files cannot be found in this directory: /Library/Developer/CommandLineTools/Packages
Any ideas where I can get the current header files for OS X 10.15?
Update
For anyone that just want xdebug support on MacOS, most of the instructions in this answer are not necessary when using the built-in version of PHP. Before doing anything, you should check if xdebug.so already exists in /usr/lib/php/extensions/no-debug-non-zts-20180731/, which should be there by default. If so, you can skip to the Enabled support in PHP portion of this answer.
Using Homebrew is also an acceptable solution for you (and can also prevent other issues).
For anyone else looking to actually build binaries on MacOS and get the header error, the full answer is for you. It also answer OP question directly. Note building xdebug from source code and actually trying to use that version of xdebug.so with the build-in PHP should end up in a "code signature" error. As described here and here, the only real solution would be to compile and use you own instance of PHP instead of the built-in one. In any situation, using Homebrew would be easier.
tl;dr
Apple decided to remove headers file in /usr/include and the macOS_SDK_headers_for_macOS_10.14.pkg package. To install Xdebug, you'll have to manually compile Xdebug with the correct reference in both phpize and make.
For more details, I wrote a blog article about the issue and the solution
Original Answer:
Long story short, Apple decided to nuke /usr/include in MacOS Catalina, which has been the default location for C header file for ever in UNIX systems. Trying to install through PEAR / PECL will return an error as the compiler will look for necessary headers file in /usr/include. So the solution is to compile Xdebug manually, manually specifying the actual location of the header files, which are still provided by Xcode, just at a different location.
First, make sure Xcode is installed, including the command line tools. The following command will display the location of the default SDK :
$ xcrun --show-sdk-path
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
The header you'll want (php.h) will then be in /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/php/main.
Getting source
Let's compile 2.7.2, getting the source code from git. Alternatively, you can download the source from Xdebug site.
git clone https://github.com/xdebug/xdebug.git
cd xdebug
git checkout tags/2.7.2
phpize
Next we need to make a copy phpize so we can edit the include path :
cp /usr/bin/phpize .
nano ./phpize
Find this line :
includedir="`eval echo ${prefix}/include`/php"
...and replace it with this line :
includedir="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/php"
Run phpize:
./phpize
You should now see something like this :
Configuring for:
PHP Api Version: 20180731
Zend Module Api No: 20180731
Zend Extension Api No: 320180731
Configure & build
We can now configure :
./configure --enable-xdebug
...and run make using our custom SDK location defined as compiler flags :
make CPPFLAGS='-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/php -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/php/main -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/php/TSRM -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/php/Zend -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/php/ext -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/php/ext/date/lib'
Might see some warning, just ignore it for now. Finally, we'll need to run :
make install
Again, this command will fail because it can't move the extension to the right place. SIP will prevent it. But no worries, we'll take care of that manually at the next step. make install is still required as it will sign the *.so file.
Enabled support in PHP
Next, we move the executable somewhere safe. I use /usr/local/php/extensions.
sudo mkdir -p /usr/local/php/extensions
sudo cp /usr/lib/php/extensions/no-debug-non-zts-20180731/xdebug.so /usr/local/php/extensions
Then we edit the PHP configuration to enable Xdebug. Simply edit php.ini:
sudo nano /etc/php.ini
And we add the following at the bottom :
[xdebug]
zend_extension=/usr/local/php/extensions/xdebug.so
xdebug.remote_enable=on
xdebug.remote_log="/var/log/xdebug.log"
xdebug.remote_host=localhost
xdebug.remote_handler=dbgp
xdebug.remote_port=9000
Restart built in server to be sure :
sudo apachectl restart
And finally test everything went fine :
php -i | grep "xdebug support"
If the above command returns nothing, then Xdebug is not available on your install. Go back the steps to find out what's missing.
Note:
A more complete fix would be to edit the result of php-config --include-dir, which returns /usr/include/php. That would make any installation find the necessary header files without having to manually edit files or compiler flags.
If you are using brew, I solve this by reinstalling php and re-linking:
brew reinstall php#7.3
brew link --overwrite php
I got an error when I tried to install xdebug in MacOS Catalina 10.15:
pecl install xdebug-3.0.1
Error:
/private/tmp/pear/install/xdebug/xdebug.c:25:10: fatal error: 'php.h' file not found
This is due to Apple decided to remove headers file in /usr/include, like you can see in other answer.
Then I added config to .bash_profile, executing these lines in console:
echo 'export PATH="/usr/local/opt/php#7.3/bin:$PATH"' >> ~/.bash_profile
echo 'export PATH="/usr/local/opt/php#7.3/sbin:$PATH"' >> ~/.bash_profile
export LDFLAGS="-L/usr/local/opt/php#7.3/lib"
export CPPFLAGS="-I/usr/local/opt/php#7.3/include"
source ~/.bash_profile
After that you can try to install xdebug again with pecl:
pecl install xdebug-3.0.1
Notes: Previously I have installed PHP 7.3 with "brew". You should adjust the php and xdebug version, in the above lines, adding the versions that you prefer.
I would recommend you use "brew" to install PHP, and then use the "pecl" tool that comes with the installed version of brew's PHP to install Xdebug.
you can find detailed instructions with ready to use patches on this site: https://profilingviewer.com/installing-xdebug-on-catalina.html

El Capitan pear command not found

I am new to mac and am trying to get pear to run from the terminal.
All the scripts are added to the MAMP folder and if I run:
$ sudo /Applications/MAMP/bin/php/php5.6.10/bin/pear
everything is fine.
However, if I run $sudo pear or pear I get a message: "pear command not found"
My $PATH variable looks like this:
/Applications/MAMP/bin/php/php5.6.10/bin/pear:/usr/bin:/bin:/usr/sbin:/sbin:
When I look for pear with $ locate bin/pear I get the same location as in the path:
/Applications/MAMP/bin/php/php5.6.10/bin/pear
Any idea what can be wrong?
Copied -- in essence -- from a comment:
Th $PATH environment variable should contain a list of directories to be searched for a command. Having the executable itself as part of the path doesn't help with resolving its location.

guard-laravel reports "phpunit is not installed on your machine"

I'm using Jeffrey Way's wonderful Laravel-Guard on a Laravel 4 project I'm building, and for the most part, it seems to be working as intended, except for when I try to get the phpunit part working.
Upon running guard, and editing a file, I get this in the console:
19:49:53 - ERROR - phpunit is not installed on your machine.
I've tried two things to make this work, first I tried installing phpunit via composer, then I tried installing it via PEAR - neither worked.
I'm running Debian 7.
Can anyone help? Thank you.
What error message do you get?
See this question on installing php-unit via composer. Notice the path to phpunit. You may want to alias that to phpunit command works anywhere.
Alternatively, you may need/want to install it globally. I've had luck installing it via a package manager. edit: You may have already tried this method :/
$ sudo apt-get install php-pear # The same on Debian ??
$ sudo pear upgrade PEAR
$ sudo pear config-set auto_discover 1
$ sudo pear install pear.phpunit.de/PHPUnit
Note: May need PEAR dependencies, see here: http://www.giocc.com/installing-phpunit-on-ubuntu-11-04-natty-narwhal.html
I don't know about Laravel-Guard specifically, but I found the easiest way to install phpunit without needing to do anything with PEAR was to do a stand-alone composer-based install.
I created a directory /opt/phpunit (because I couldn't think of anywhere better to put it), and then created the file /opt/phpunit/composer.json:
{
"require": {
"phpunit/phpunit": "3.7.*"
},
"config": {
"bin-dir": "/usr/local/bin/"
}
}
You may need to adjust the bin-dir setting to match somewhere on your path. This is critical - otherwise anything looking for phpunit will not be able to find it.
Then you can just run composer install - it will download phpunit for you and put a symlink to the launch script in /usr/local/bin,
dev1:~$ which phpunit
/usr/local/bin/phpunit
Where (on my machine) /usr/local/bin/phpunit becomes a symlink to /opt/phpunit/vendor/phpunit/phpunit/composer/bin/phpunit
... and it just works. Of course, you will need to manually update occasionally using composer update to get the latest phpunit code.
I got these instructions from here: Chapter 3. Installing PHPUnit

PHPUnit installed but simply doing nothing

I am following along with the tutorials in 'Easy PHP Websites with Zend Framework' and wanted to install PHPUnit.
System: Mac OS x Lion, PHP running locally (Not MAMP)
Pear was installed and working fine, I upgraded it to the latest.
Installed PHPUnit using
sudo pear install phpunit/PHPUnit
terminal did some work and installed it without errors
The in my terminal I did
phpunit --version
this returns/does nothing as follows (Username removed)
Machine:~ Username$ phpunit --version
Machine:~ Username$ sudo phpunit --version
Machine:~ Username$
Was worried it some how did not install so I check for the PHPUnit files and they do exist under /usr/lib/php/phpunit
Also checked that the phpunit exe exists which it does under /usr/bin
edited .profile as well as .bash_profile to include the /usr/bin path to have
export PATH=/usr/bin:$PATH
then restarted terminal
running
echo $PATH
shows
/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/git/bin:/Users/xxxxx/development/frameworks/ZendFramework-1.11.11/bin
php.ini includes is
include_path = ".:/usr/lib/php/pear:/Library/Server/Web/Data/Sites/ZendFramework-1.11.11/library"
Where xxxxx is my username on the Mac
even going into /usr/bin in terminal and using phpunit --version returns nothing
in case its relevant my PEAR config shows
Configuration (channel pear.php.net):
=====================================
...
...
PEAR executables directory bin_dir /usr/bin
PEAR documentation directory doc_dir /usr/lib/php/doc
PHP extension directory ext_dir /usr/lib/php/extensions/.....
PEAR directory php_dir /usr/lib/php
PEAR data directory data_dir /usr/lib/php/data
PHP CLI/CGI binary php_bin /usr/bin/php
php.ini location php_ini <not set>
....
....
PEAR Installer temp directory temp_dir /private/tmp/pear/temp
PEAR test directory test_dir /usr/lib/php/test
PEAR www files directory www_dir /usr/lib/php/htdocs
....
Also added the pear and phpunit directory to my php.ini includes path list.
Am at a loss as to why this does not want to work. Am sure its me and I have done something incorrectly....Any help appreciated.
Ok, solved this, finally after much reading and fiddling. Issue was with PEAR, not PHPUnit itself.
Found the issue by following the set up for PEAR onhttp://pear.php.net/manual/en/installation.checking.php
php.ini change from
.:/usr/lib/php/pear:/Library/Server/Web/Data/Sites/ZendFramework-1.11.11/library:/usr/lib/php/PHPUnit
to
.:/usr/lib/php/pear:/Library/Server/Web/Data/Sites/ZendFramework-1.11.11/library:/usr/lib/php
solved this issue immediately.
phpunit --version now works

How to use Pear with xampp?

How do i include Pear's QuickForm into a php file if Pear is already installed in xampp?
I ran go-pear.bat from the command line, and it ran a setup program to configure my system for PEAR.
When it was finished I was left with some new folders and a pear.bat file. I tested it with "pear install -f Text_CAPTCHA" and everything seemed to work.

Resources