How to check php version in MacOS sierra? - php

I have mac os sierra machine. When I start a php project in vs code, I get the following warning
language server needs php 7, and the version found is 5.6.27.
So I used homebrew to upgrade to version 7 and confirmed it from the terminal. I am also running mamp which show version 7.
But in the terminal of vs code the php version is still 5.6.27. So I am bit confused?
I changed the value of php.validate.executablepath in settings.json in vs code from usr/bin/php to usr/local/bin/php, but still vs code terminal showing the older version (viz. 5.6.27)

This is because VM Code still checking /usr/bin/php directory which is php5
You have to configure the path to the PHP executable in the user settings file.
Follow the following steps to change it
Go to File > Preferences > User Settings > Settings.json
Change the value of php.validate.executablePath according to the installed
directory of php7.
"php.validate.executablePath":
"/Applications/MAMP/bin/php/php7.0.14/bin/php"
Relaunch VM Code
If the problem remains same, then add the path to PHP7 to your environment variables, run where php and php --version to verify. To add path in your macos sierra do the following:
Within the Terminal, run vim ~/.bash_profile
Type i and then paste the following at the top of the file:
export PATH=/user/local/bin:$PATH
Hit ESC, Type :wq, and hit Enter.
In Terminal run source ~/.bash_profile
In Terminal, type in which php again and look for the updated string.
If everything went successful, it should output the new path to MAMP PHP install.
In case it doesn't output the correct path, try closing the terminal window (exit fully) and open again, it should apply the changes (Restart in short)

To find out what version you're using, upload a php file to your server containing the following code...
<?php
phpinfo();
?>
It will tell you at the top of the page.

Related

How to debug PHP using VSCode IDE in Ubuntu

I need to debug PHP code using VS Code IDE. We can debug PHP using Xdebug. So I tried a lots to setup Xdebug for debugging but I failed to use Xdebug using VS Code IDE.
PHP is 8.1
Ubuntu 22.04.1 LTS
Please help me how can I debug.
Step 1:- Install PHP Debug Extension in VS Code IDE.
Step 2:- Copy Full output of Phpinfo(). run below Command in CLI for get output of phpinfo().
php -r "phpinfo();"
Step 3:- open Xdebug wizard Page & paste copied full output of phpinfo() in the form field. after the submitting form you will get step by step Instructions related to setup Xdebug in your System.
In my system currently I used Php 8.1. see below Snapshot of Xdebug Wizard Instructions.
Follow above Instruction which one you will getting from Xdebug Wizard
Note that, above Wizard Instructions is as per my server configuration. In your case it may differ than my above snapshot. So, you must need to follow Step 2 & 3.
Step 4:- add below Configuration in your php.ini file.
[xdebug]
xdebug.mode = debug
xdebug.start_with_request = yes
;Note:- Below Xdebug Path is depends on your OS & your PHP Server.
;So you need to write path of xdebug.so (in Linux)
;OR path of xdebug.dll (in windows)
zend_extension=/usr/lib/php/20210902/xdebug.so
for find Extension Directory for your server (Xampp, Lampp etc. all) then, simply Run php -r "phpinfo();" command then find out extension_dir as like below snapshot
OR write <?php phpinfo() ?> in your php file then run that php file & found out extension_dir in your output page of phpinfo.
Step 5:- Restart your Server (Apache).
Step 6:- Install Browser Extension Initiation. then start debugger in your Vs Code IDE see below snapshot.
Now, All Done.
for referece I share other source urls
refer Xdebug Docs
refer for Windows
refer this for Linux
But, before starts debugging your code, if you need to check Xdebug is working proply or not then Follow below Steps. otherwise you can ignore below steps.
In Xdebug 3+. there is xdebug_info() method exits which return info of xdebug extension.
write <?php xdebug_info(); ?> in your php file & then run this php file.you will get output as like below snapshot
& for check Xdebug works properly for CLI run php -r "xdebug_info();" in cli.

How to use MAMP PHP on macOS big Sur

I updated the to MacOS Big Sur and then switched to MAMP Pro 6.3 from MAMP 4.x.
which php commands results the
usr/php/bin/
I updated the path using following.
vim ~/.bash_profile
export PATH=/Applications/MAMP/bin/php/php7.4.12/bin:$PATH export
PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
Press esc and then
:wq
source ~/.bash_profile
Now when I do which php it shows MAMP's php7.4.12 but if close and re-open the terminal, it again says
usr/php/bin
Btw, PHP 7.4.12 is set as Default version in MAMP Pro from PHP settings in MAMP Pro.
Versoins
macOS Big Sur version 11.1
MAMAP 6.3
Since you're using MAMP PRO 6.x you can enable Activate command line shortcuts for the selected PHP version, pear & pecl within the MAMP PHP settings. This will add aliases to your .profile file. If this does not work right away find the .zshrc file if you have it and add source ~/.profile; within it.
Open a terminal.
edit this file:
nano .zshrc
add these two lines:
export MAMP_PHP=/Applications/MAMP/bin/php/php7.4.12/bin
export PATH="$MAMP_PHP:$PATH"
NOTE: if you want another version, replace php7.4.12 for the version you want.
Save the changes o file and then close the terminal and reopen it.
Now run "which php" and you will see the desire version of Php.

How do you update php version to 7 on siteground server?

I have a system build with Laravel 5.5 and it needs PHP version 7.
I have deployed the project to site ground server, updated PHP version using PHP version but when I ran php -v command via putty it is showing me PHP version 5. I don't know what going on.
I shall be thankful if someone tell me that what is the proper way of updating PHP version?
I have also tried AddHandler application/x-httpd-php70s .php in my .htaccess files but got nothing fruitful
You can change the PHP CLI version through SSH. After connecting through SSH type cd ~ and then find .bash_profile file. Open the .bash_profile file with nano or vi which you would like to use and enter this line:
alias php=/usr/local/php72/bin/php-cli
and save the file. After that run command:
source .bash_profile
And your PHP CLI version has been changed. To confirm the PHP version type php -v and it will show you the version which you just changed.
P.S: In my case, I want to change the PHP CLI version to PHP 7.2 so I use php72 in alias php=/usr/local/php72/bin/php-cli. You can change it to any other version which you need.
So there's no problem if you see PHP5 using command line and PHP7 using php file with phpinfo();. Your hosting provider allows you to choose from several PHP version. You can select PHP7 e.g. using .htaccess but it doesn't have to change PHP CLI version. So when you set PHP7 in .htaccess file it serves your website using PHP7, but CLI is still v5.
By the way, this type of question should be asked on superuser I think.

linux xammp Visual Studio Code configuration

I want to config Visual Studio Code (VSC) to work with php on linux (Ubuntu).
I installed xammp for this purpose and I don't know where to point this parameter on VSC php.validate.executablePath
On windows the config path has to be like this: "php.validate.executablePath": "c:/php/php.exe"
Could you give me the full path to configure it properly ON LINUX?
Regards
This answer may change based on what flavor of Linux/Unix you are using, but if you are using Ubuntu like me, this is how I did it.
First and foremost, I know you're using XAMPP, but do exactly what the error message says and install PHP7. You can do so by running sudo apt-get install php.
I know that goes against intuition. At first I thought "I have XAMPP installed, which installed PHP. Why do I need to install PHP?" XAMPP only includes the PHP runtime executables. In order to do development with PHP, you need to install the full environment. XAMPP will continue to use its built-in version.
Once the install is completed, follow these steps:
Execute whereis php. Example output below:
php: /usr/bin/php7.0 /usr/bin/php /usr/lib/php /etc/php /usr/share/php7.0-json /usr/share/php7.0-opcache /usr/share/php /usr/share/php7.0-readline /usr/share/php7.0-common /opt/lampp/bin/php /usr/share/man/man1/php.1.gz
In Visual Studio Code, click the cog in the bottom left corner and select Settings. On the right-hand pane, insert the following code. The version-agnostic path is used here:
"php.validate.executablePath": "/usr/bin/php"
Press Control+S or click File -> Save
The final settings file should look like this:
// Place your settings in this file to overwrite the default settings
{
// Snip... other configurations overrides
// Points to the PHP executable.
// Use the version-agnostic value from the "whereis php" command above.
"php.validate.executablePath": "/usr/bin/php"
}
For me is "/opt/lampp/bin/php" (I have xampp on Linux Mint; to find out write in terminal: "whereis php")

Installing Xdebug for PHP on Ubuntu with XAMPP

I'm running XAMPP 1.7.3a on Ubuntu 9.10. With Netbeans 6.7.1 as my editor, I want to be able to debug my PHP sites.
To do this, I looked up Xdebug and started following the installation instructions, found here: http://xdebug.org/docs/install.
Trying to compile the .tgz file, run in to a problem.
Step 3) I can execute that, but what use does it have? I don't get the output or what I should do with it.
Step 4) I execute the following command:
./configure --enable-xdebug --with-php-config=/opt/lampp/etc/
At the bottom of the output, it says: configure:
error: Cannot find php-config. Please
use --with-php-config=PATH
I've checked the location I entered, the php.ini file is there and so are all other config files.
So, I'm not sure what to do now. Should I ignore and just do the 'make' command, or does something else yet need to be done?
you have to pass the path to the php config binary - should be something like
/opt/lampp/bin/php-config
All the binaries in XAMPP are located in
/opt/lampp/bin
That's why if you work with XAMPP's PHP version you ought to proceed all operations using binaries from there.
For example, after installation of XAMPP it's possible to set path to it's PHP bin file.

Categories