PHP version different to CLI version using Homebrew MacOS Monterey - php

I have installed PHP with homebrew, switch to PHP 8.0 but the browser phpinfo() is showing 7.4. I am on the latest version of Monterey.
brew services stop httpd is stopping the apache service.
% php -v
PHP 8.0.19 (cli) (built: May 12 2022 02:25:19) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.19, Copyright (c) Zend Technologies
with Zend OPcache v8.0.19, Copyright (c), by Zend Technologies
% which php
/opt/homebrew/bin/php
How would I get PHP 8.0 to work in the browser?

in your httpd config, you must hardwire the shipped php version (7.4), with apache, would look like this :
LoadModule php7_module /usr/local/opt/php#7.4/lib/httpd/modules/libphp7.so
Just change the httpd config to load the appropriate lib, and restart your httpd server. Also, php has multiple configs (cli, fpm) : make certain that you tailor the appropriate one in your configs , typically found in /usr/local/etc/php/8.N (monterey, brewed-in php)

Related

lumen 5.6 version not working on ubuntu 16.04

I have installed fresh copy of lumen 5.6 on my ubuntu machine. I also upgrade my php version from php 5.6.* to 7.2.5. Now php 7.2.5 version is enabled on my system. But when I run the project I receive frollowing exceptoion
Parse error: syntax error, unexpected '?'
/home/example/apis/lumen/vendor/symfony/http-foundation/Response.php
Below is my php version
PHP 7.2.5-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: May 5 2018 04:59:13) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.5-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies
Guide to solve this problem or suggest any usefull link
If you create an info.php file inside your lumen public/ folder and open it on your server
<?php // info.php filename
phpinfo();
there is a good chance it is still referencing php 5.6?
You do not mention if you are serving the project via php -S, apache or nginx.
I am going to presume you are using apache as it mostly the default on Ubuntu. Disable the php 5.6 module for apache and enable the php 7.2 module. Something like the following will work.
Disable php 5
sudo a2dismod php5
Enable php 7.2
sudo a2enmod php7.2
Restart apache
sudo service apache2 restart

Drupal 8 installation setup shows older PHP version than what the server is running

When installing Drupal 8, just before database setup, I get a few errors and warnings, but I also see the following:
PHP
7.1.14-1+ubuntu16.04.1+deb.sury.org+1
However, doing php -v I get:
PHP 7.2.2-3+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Feb 6 2018 16:11:23) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.2-3+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies
Clearly, my web server is running 7.2 but Drupal thinks it's 7.1. This is causing a problem where I have gd installed on PHP 7.2, but Drupal doesn't see gd installed on PHP 7.1 (because it isn't, at least its php.ini file doesn't have the gd extension enabled). Same with a few of the other errors and warnings.
How can I get Drupal 8 to recognize the correct PHP version?
So I figured it out:
Runing sudo a2dismod php7.1 then sudo a2enmod php7.2 seems to work perfectly (after a restart of Apache).
Try To install using composer
This method creates a project in web folder and other files outside web folder
composer create-project drupal-composer/drupal-project:8.x-dev d8_test_project --stability dev --no-interaction
Or
This method creates a project in a normal folder structure
composer create-project drupal/drupal my_site_name 8.*#dev --no-dev
I don't think it's about "recognizing" version, but you most likely have 2 different versions, one for console and other for web server. Run phpinfo() and see what PHP version is used by web server.

Where do I tell Apache to use 5.6.23 instead of 5.5.9?

I am having a problem AFTER installing a newer version of PHP with the Apache web server seeing the new version 5.6.23...it is still using 5.5.9. Where do I tell Apache to use 5.6.23 instead of 5.5.9?
I am running a local web server on Linux Mint 17.1
As reported by phpinfo (both BEFORE installing php 5.6.23 and AFTER)
Apache Version: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.17
Apache API Version: 20120211
PHP Version: 5.5.9-1ubuntu4.17
Configuration File (php.ini) Path: /etc/php5/apache2
Loaded Configuration File: /etc/php5/apache2/php.ini
Scan this dir for additional .ini files: /etc/php5/apache2/conf.d
Noticing that newer versions of PHP are available (such as 5.6.23) but, evidentily not from the default repositories for Linux Mint 17.1, I decided to do the following:
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php5.6
After restarting the web server (end even rebooting linux), I executed the following:
php -v
PHP 5.6.23-2+deb.sury.org~trusty+1 (cli)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
I verified the following:
5.5.9 is located here: /etc/php
5.6.23 is located here: /etc/php/5.6
Somewhere setting "Configuration File (php.ini) Path" will do the trick, but I do not know where to do this?
Thanks
Mike

Multiple PHP versions using phpenv, php-build and php-version

I'm on Arch Linux, trying to configure multiple PHP versions for testing my scripts.
I'm basing myself on these three tools:
https://github.com/phpenv/phpenv
https://github.com/CHH/php-build/
http://wilmoore.com/php-version/
First I installed Apache and PHP (and their integration package) with pacman:
# pacman -S php apache php-apache
Next, I followed the instructions for installing the tools on the links, everything is working fine.
I manage to install two versions with phpenv-install from php-build tool. I got something like this:
-- ~
|---.phpenv
|---lib
|---versions
|---5.5.1
|---5.4.17
|--- (some more folders)
On CLI environment everything is working fine, I can easily switch between the two versions with php-version:
$ php-version 5.5.1
$ php --version
PHP 5.5.1 (cli) (built: Aug 5 2013 22:54:47)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
with Zend OPcache v7.0.2-dev, Copyright (c) 1999-2013, by Zend Technologies
with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans
$ php-version 5.4.17
$ php --version
PHP 5.4.17 (cli) (built: Aug 5 2013 23:19:44)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans
Now the problem: integrate this with apache.
As I said in the beginning of this post, I also had to install PHP from Arch repositories, which coincidentally is on version 5.4.17. This installation is working fine with Apache.
On php-env readme there are these instructions:
phpenv support dynamic switching for Apache apxs libraries and install
will build and install a libphp5.so shared library for Apache under
the versions libexec folder.
By calling phpenv global to show or change the global PHP version a
link is created under ~/.phpenv/lib/libphp5.so for the appropriate
release build. This link can be used for Apache's LoadModule
php5_module directive and requires Apache to restart when changed.
The problem is that there is no file or symlink named libphp5.so in lib directory neither in the whole .phpenv folder, because
$ find ~/.phpenv -name libphp5.so
returns nothing.
Maybe because english is not my first language, I'm having some problem to intepret the second paragraph of the quote above.
There is a package in the AUR for phpenv
https://aur.archlinux.org/packages/phpenv/
As well as packages for many different versions of PHP
https://aur.archlinux.org/packages/?O=0&C=0&SeB=nd&K=phpenv&outdated=&SB=n&SO=a&PP=50&do_Search=Go
First install phpenv:
yaourt phpenv
Then install the php versions you need, for example:
yaourt php53_29_env
Note: even with this though, you will likely have a problem. Checking the package build, it looks like it is missing the patch to disable PHP automatically being compiled with thread safe features when apache is running a thread safe mpm. Not quite sure since on my systems, I want PHP to enable thread safe code so it will work for me.

How to update the path of PHP to the new version I just installed on mac osx mountain lion?

first I am new to macs, I just installed PHP 5.4.6 on my machine after downloading the PHP package from http://www.php.net, I unzipped it and navigated to the directory through the terminal, then I ran the following commands:
./configure --with-config-file-path=~/php-5.4.6/php.ini
make
make test
sudo make install
I restarted the Apache with sudo apachectl graceful but and when I gone to the info.php it still said PHP 5.3.13 the default version that macs shipped with, I tried to run echo $PATH I got this result /usr/local/php5:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/mysql/bin:/usr/local/mysql/bin when I searched the internet they said something about changing the path because the default PHP is installed on /usr/local/php5 and the new one is installed on /usr/local/bin/, when I run /usr/local/bin/php -v I get
PHP 5.4.6 (cli) (built: Aug 18 2012 22:52:55)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
So I wanted to know how to update that path.
Thanks in advance and sorry for being long.
You will need to point your httpd.conf configuration to use your new mod_php library... assuming that you passed the proper --with-apxs2 flag during the build.
If using the built-in Apache server, see: /etc/apache2/httpd.conf
LoadModule php5_module <MY_NEW_PATH>/libphp5.so

Categories