How to change phpize to current version - php

I'm using Mojave OS X and I've been following these steps to install Xdebug through Pecl. I'm trying to set it up so I can use the debugger of PHPStorm.
http://www.devinbaldwin.com/2018/09/27/how-to-install-xdebug-on-a-new-mac-including-mojave/
This is my current setup:
Xdebug installed: no
Server API: Command Line Interface
Windows: no
Zend Server: no
PHP Version: 7.3.6
Zend API nr: 320180731
PHP API nr: 20180731
Debug Build: no
Thread Safe Build: no
OPcache Loaded: yes
Configuration File Path: /usr/local/etc/php/7.3
Configuration File: /usr/local/etc/php/7.3/php.ini
Extensions directory: /usr/local/lib/php/pecl/20180731
I've followed all the steps but got stuck at installing Xdebug because I didn't have phpize.
I've installed the newest version of Xcode to create phpize, this worked at first, but I was having trouble appending the php.ini through PHPStorm because the file was read-only and I've thought of following another guide which talks about downgrading PHP to version 7.2 and installing Xdebug through that version, which is how this problem started.
When I tried to install Xdebug through Pecl, I've got this error.
downloading xdebug-2.7.2.tgz ...
Starting to download xdebug-2.7.2.tgz (230,987 bytes)
.................................................done: 230,987 bytes
69 source files, building
running: phpize7.2
sh: phpize7.2: command not found
ERROR: 'phpize' failed
At the sh, it never showed phpize7.2 before, it used to show phpize without the numbers.
I've tried to uninstall and reinstall homebrew and remove all php versions and installed the current php version as posted above.
I just want to know how I can revert phpsize to the current version. I've tried using PHP 7.2 but I still got the same error.
I've tried this guide since I'm using the latest PHP version, which is 7.3.
https://sys.cuquejo.org/install-php-7-3-xdebug-on-macos-mojave-with-homebrew/
But I still get the same error.
In addition, when I typed phpsize I got this:
Cannot find config.m4.
Make sure that you run '/usr/local/bin/phpize' in the top level
source directory of the module
However, when I typed phpsize --help
Usage: /usr/local/bin/phpize [--clean|--help|--version|-v]
Typing phpize72 --help would only show this:
-bash: phpize7.2: command not found
I'm not sure why this happened but any explanations could help.

Related

having problem with installing PHP Debug extension in Virtual Studio Code on macOS

I'm trying to install the PHP Debug extension in Virtual Studio Code on macOS Ventura 13.1.
While following the instructions from https://xdebug.org/wizard, I am getting an error "Check for supported PHP versions...configure: error: not supported. Need a PHP version >= 7.2.0 and < 8.2.0 (found 8.2.0)" at step 6: Run ./configure
I have no problems installing PHP and Xdebug when I tried installing via homebrew outside of the VS Code app(followed instructions from https://xdebug.org/docs/install). When I typed php -v in terminal, it shows Xdebug version(3.2) and Zend OPcache v8.2.0.
I have tried copying xdebug.so module file from homebrew php app folder to AMPPS php app folder, configuring php.ini as the step 8 & 9 and reloading the AMPPS Apache web server. It still does not work, and I guess I need to run ./configure -> make to get proper xdebug.so file for AMPPS configuration settings.
UPDATE
I found the solution to use ./configure --with-php-config="path-to-AMPPS-php" but still having the problem of loading the Xdebug extension after reloading the web server.
Is there a way to use Xdebug with AMPPS and Virtual Studio Code together?

pecl fails installing mongodb driver on Apple Silicon (M1)

I have php 7.4 installed on my macbook pro m1
% php -v
PHP 7.4.15 (cli) (built: Feb 26 2021 09:28:23) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.15, Copyright (c), by Zend Technologies
I'm trying to install the mongodb driver running:
sudo pecl install mongodb
But fails after a while:
mp/pear/temp/mongodb/src/contrib/ -DHAVE_CONFIG_H -g -O2 -c /private/tmp/pear/temp/mongodb/php_phongo.c -fno-common -DPIC -o .libs/php_phongo.o
In file included from /private/tmp/pear/temp/mongodb/php_phongo.c:29:
In file included from /opt/homebrew/Cellar/php#7.4/7.4.15_1/include/php/ext/spl/spl_iterators.h:24:
/opt/homebrew/Cellar/php#7.4/7.4.15_1/include/php/ext/pcre/php_pcre.h:25:10: fatal error: 'pcre2.h' file not found
#include "pcre2.h"
^~~~~~~~~
1 error generated.
make: *** [php_phongo.lo] Error 1
ERROR: `make' failed
I tried with
arch -x86_64 sudo pecl install mongodb
but results in the same error.
Somebody knows how can I solve this please? Or if I can install the mongodb driver without using pecl. Thanks in advance.
I have finally solved my problem.
I followed these steps from https://github.com/mongodb/mongo-php-driver/issues/1159
After installing a newer PHP version where previously I used 7.3.24 and updated to 7.4.16.
Still had the same issue but diffrent file:
fatal error: 'pcre2.h' file not found #include "pcre2.h"
From this error I tried to check the files in the MacOs Big Sur File system and in the end I found where the pcre2.h is located, and oddly it was being called in the pcre folder, so I manually copied from the pcre2 folder to pcre
The solution that I used:
$cp /opt/homebrew/Cellar/pcre2/10.36/include/pcre2.h /opt/homebrew/Cellar/php\#7.4/7.4.16/include/php/ext/pcre/pcre2.h
Then, I installed mongodb using
$brew install mongodb
After that, I once again tried
$sudo pecl install mongodb
Finally, it worked. However, I'm not sure if this is a good way to solve the problem by manually adding a header file to the directory.
(Sorry I'm still new to the MacOs Environment, just bought a mac mini m1 last week for developing my programming skills)
If you were to install php multiple versions from homebrew make sure you are using the current version as you wanted to. You could check the version by using which php.
To switch from 7.4 to 5.6
$brew unlink php#7.4
$brew link php#5.6 --force
credits: https://www.markhesketh.com/switching-multiple-php-versions-on-macos/
New error
Success Installation:
There is a simpler way to fix the installation issue than symlinking the header file into PHP sources. When running pecl install, you can provide additional compile arguments via the CFLAGS environment variable. So, on the Apple Silicon platform, you can use the following command to get the extension to compile:
CFLAGS=-I/opt/homebrew/include pecl install mongodb
Note that this is only necessary on Apple Silicon, not on x64. It also works for other extensions that fail because of similar errors (e.g. apcu)
I had the same issue with PHP 7.3, I solved it just by running the following commands:
cp /opt/homebrew/Cellar/pcre2/10.38/include/pcre2.h /opt/homebrew/Cellar/php#7.3/7.3.31/include/php/ext/pcre/pcre2.h
Then installed it successfully:
sudo pecl install mongodb
I have finally solved my problem. I used PHP 8.1.7 - Mac Pro 2022 - Apple Silicon (M1)
My errors: fatal error: 'pcre2.h' file not found
The solution that I used:
1. brew install pcre2
2. ln -s /opt/homebrew/Cellar/pcre2/10.40/include/pcre2.h /opt/homebrew/Cellar/php/8.1.7/include/php/ext/pcre/pcre2.h
Please check your path again when use `ln -s`
3. sudo pecl install mongodb
See more: Install pecl pear on MacOs - Link
Success Installation:
Hope it help you :) Thanks
cp /Applications/MAMP/Library/include/pcre2.h /Applications/MAMP/bin/php/php8.0.8/include/php/ext/pcre/pcre2.h
then run
sudo pecl install mongodb
If you use MAMP,
Based on #Kelwin Tantono's answer follow instructions to install mongodb then,
Firstly, check for the location of pcre2.h file by
cd /opt/homebrew/Cellar/pcre2/
In this directory find the folder with ls command, in my case it was 10.40 .
Change 10.40 value in the below code with the result of ls command.
Then, check your php version with moving to php directory at MAMP by
cd /Applications/MAMP/bin/php/
Change php8.0.8 value in the below code with your desired php version.
cp /opt/homebrew/Cellar/pcre2/10.40/include/pcre2.h /Applications/MAMP/bin/php/php8.0.8/include/php/ext/pcre
Now you can install mongodb extension with below command after changing your working directory to
cd /Applications/MAMP/bin/php/php8.0.8/bin
sudo pecl install mongodb
Now, you should add extension=mongodb.so to php.ini file with
echo "extension=mongodb.so" > /Applications/MAMP/bin/php/php8.0.8/conf/php.ini
Do not forget to change php version.

Xdebug installation failed because "phpize" failed on macOS Big Sur with MAMP

I am trying to install Xdebug on my Mac, since I am using MAMP for local development.
I tried using pecl to install Xdebug by running the following command in my terminal:
sudo pecl install xdebug
But the following happens:
hello-world:~ lois$ sudo pecl install xdebug
WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update
downloading xdebug-2.9.8.tgz ...
Starting to download xdebug-2.9.8.tgz (245,293 bytes)
...................................................done: 245,293 bytes
91 source files, building
running: phpize
grep: /usr/include/php/main/php.h: No such file or directory
grep: /usr/include/php/Zend/zend_modules.h: No such file or directory
grep: /usr/include/php/Zend/zend_extensions.h: No such file or directory
Configuring for:
PHP Api Version:
Zend Module Api No:
Zend Extension Api No:
autom4te: need GNU m4 1.4 or later: /usr/bin/m4
ERROR: `phpize' failed
It looks like phpize is trying to locate some files which don't exist, and then fails.
There is no mention of those files in the xdebug installation page, so I am not sure what I did wrong.
Ok, so I finally found the solution to my problem.
First solution: if you are using MAMP
First, I am actually using MAMP for local development. If that is your case as well, you do not need to install Xdebug.
The reason is, Xdebug is already installed with MAMP.
There are only 2 things you need to do:
Modify the php.ini files in MAMP: https://dillieodigital.wordpress.com/2015/03/10/quick-tip-enabling-xdebug-in-mamp-for-osx/
Set up your IDE to use Xdebug. I am using VS Code, there are lots of tutorials on how to set up VS Code with Xdebug.
Second solution: you are not using MAMP, so you absolutely want to install Xdebug on your Mac
If you had the same problem I had with phpize, it is because newer versions of macOS have a different folder structure.
Xdebug expects a certain structure, which is not present anymore. In this case, take a look at this article: https://bbqsoftwares.com/blog/xdebug-catalina
Autoconf might be missing
run brew install autoconf and try again
on Apple M1 Silicon make sure to use arch -x86_64 sudo pecl install xdebug to install xdebug

Ran the xdebug wizard but still have php version confusion

When I run php -v I get
PHP 5.6.32-1+ubuntu16.04.1+deb.sury.org+1 (cli)
So then I go to xdebug wizard, paste in the output from php -i, follow the steps
When I run phpize I get
Cannot find build files at '/usr/local/lib/php/build'. Please check your PHP installation
So I did phpize5.6 and got
PHP Api Version: 20131106
Zend Module Api No: 20131226
Zend Extension Api No: 220131226
which matches the wizard. Now when I run ./configure, I get
checking Check for supported PHP versions... configure: error: not supported. Need a PHP version >= 5.5.0 and < 7.2.0 (found 5.3.10)
However, if I run it like ./configure --with-php-config=php-config5.6
I can get the end of the wizard. It says to
Run: cp modules/xdebug.so /usr/lib/php/20131226
Edit /etc/php/5.6/cli/php.ini and add the line
zend_extension = /usr/lib/php/20131226/xdebug.so
But now I get
Failed loading /usr/lib/php/20131226/xdebug.so: /usr/lib/php/20131226/xdebug.so: undefined symbol: zend_pass_function
So it looks like there is something wrong with the php installation. It seems to use 5.3, but php -i shows 5.6. Do you have any ideas on why that is and how I could best resolve it?
Ok, so I solved this by first searching /usr for 5.3.10
This led me to see that I had used phpbrew a while ago, although I was using the system-installed version of php rather than the phpbrew version.
Switching to the phpbrew version 5.6 (instead of the system 5.6) resolved the error.
In future I can remove phpbrew and go back to the regular php following advice here.

Laravel 4 - Error while running `composer install`

The problem:
I have installed Composer and followed the Quick start guide in the Laravel 4 documentation.
I get the following error when I run composer install or composer update:
Script php artisan optimize handling the post-install-cmd event
returned with an error...
I tried to run the following composer command:
composer create-project laravel/laravel myproject --prefer-dist
Or use their laravel.phar:
laravel new myproject
Or get the zip version from git: https://github.com/laravel/laravel?source=c
And I still fail to update via composer.
Additional information:
My PHP version on my Mac is:
PHP 5.4.17 (cli) (built: Aug 25 2013 02:03:38)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0,
Copyright (c) 1998-2013 Zend Technologies
PHP version on MAMP: 5.4.10
I found some solutions on Google / Stack Overflow but those did not work well in my case.
It says:
MCrypt PHP extension required
So it looks like you're missing the Mcrypt extension, which is required by Laravel (actually, I think it's used only by the Authentication class for password handling, not for the rest of the components of the framework).
I haven't got a Mac, but the command to install it should be something like this, using Homebrew
brew tap josegonzalez/php
brew install mcrypt php54-mcrypt
These links might help you:
http://www.jorble.com/2013/04/install-php-mcrypt-in-macosx/
http://coolestguidesontheplanet.com/install-mcrypt-php-mac-osx-10-9-mavericks-development-server/
Having the setting xdebug.scream = 1 in the configuration was the cause of the problem for me. I fixed it by doing the following:
Find XDebug configuration file.
$ sudo find / -name xdebug.ini
Edit file using any text editor.
$ sudo vi /your_path/xdebug.ini
Set xdebug.scream = 0
Reload the server (Apache/Nginx/whatever).
$ sudo service nginx reload
You might have Mcrypt installed already on your computer, if you are using MAMP or any other application. So, you don't need to install Mcrypt again. Add the following code to a php file and place it in your htdocs directory. See the info about the PHP you are running. You can see whether Mcrypt is already installed or not.
<?php
phpinfo();
If it shows Mcript, then do the following:
Check which PHP version you are using. You can see different directories for different PHP versions in this directory: /Applications/MAMP/bin/php/.
Move to the user's home directory. Use this command on terminal: cd ~.
Edit (or create a new one if not exists) .bash_profile file.
Add the following line:
where php5.5.10 is the directory of the PHP version you are using.
export PATH=/Applications/MAMP/bin/php/php5.5.10/bin:$PATH
Now restart your computer. And you can use php artisan command of Laravel.
Source of information: Laravel requires the Mcrypt PHP extension

Categories