Installing Missing Dependencies For Laravel on MacOS - php

If I open Terminal on my MacOS and view my php version the result is:
Jacks-MBP:Projects jackrobson$ php -v
PHP 7.2.12 (cli) (built: Nov 29 2018 01:59:12) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.12, Copyright (c) 1999-2018, by Zend Technologies
I'm also running httpd as my Apache server:
Jacks-MBP:Projects jackrobson$ httpd -v
Server version: Apache/2.4.37 (Unix)
Server built: Nov 8 2018 08:13:24
However, upon trying to configure Laravel of which I did by running this command without any errors:
composer create-project laravel/laravel demowebsite
And configure my vhost, I see this error when I view demowebsite.test:
Parse error: syntax error, unexpected '=' in /Users/jackrobson/Projects/demowebsite/vendor/laravel/framework/src/Illuminate/Support/Arr.php on line 384
I think maybe this because I don't have the dependencies needed?
Is that true or would the composer install of laravel failed?
I'm trying to figure out if the dependencies are missing.
Weirdly, upon looking at phpinfo from the base of the laravel demosite it says:
PHP Version 7.0.32
Not sure why it's not using version 7.2 as is visible in my Terminal.
Maybe that is issue.
I will investigate further and update but anyone with more wisdom who understands this, I'd appreciate a point in the right direction.
Many thanks
Edit:
Following user Caddy DZ's suggestion "Try configuring httpd to use php 7.2 instead or remove version 7.0 completely"
I was able to switch php versions using a script I initially configured php, apache, etc. last year
$ curl -L https://gist.githubusercontent.com/rhukster/f4c04f1bf59e0b74e335ee5d186a98e2/raw > /usr/local/bin/sphp
$ chmod +x /usr/local/bin/sphp
$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
If that doesn't work for any observers, try this additional command:
export PATH=/usr/local/bin:/usr/local/sbin:$PATH
This script made it easy for me to change httpd php version with the command:
Jacks-MBP:Projects jackrobson$ sphp 7.2
Sorry, but php#7.2 is not installed via brew. Install by running: brew install php#7.2
Jacks-MBP:Projects jackrobson$ brew install php#7.2
Which ran without errors and now httpd is using 7.2 and the Laravel install no longer shows the syntax error. Huzzah!
Thank you for your assistance Caddy DZ. :)
I hope these notes prove helpful to anyone who encounters a similar issue.

Try configuring httpd to use php 7.2 as the default fpm instead or uninstall version php 7.0 completely if you don't need it.
Hope this helped

Related

POPOS: How to revert PHP to 8.0

I use PopOs for work. PopOs has released version 22.4 but it comes with PHP 8.1 and our development project (Laravel) uses php_cs_fixer and it currently only supports PHP 8.0. I was tasked to test if we should upgrade to PopOs 22.4 yesterday. I tested phpbrew and homebrew. Neither of them worked well. phpbrew doesn't work once I upgrade to PHP 8.1 (it has a single deprecated function in it, everywhere). Homebrew didn't seem to work and recommended editing the apache2 httpd.conf file, but our project isn't using Apache. I currently have PHP 8.0 installed (found at /usr/bin/php8.0) but the cli still says I'm using PHP 8.1.7. I used update-alternatives --set php /usr/bin/php8.0 to try and change the version the cli is using but that doesn't seem to work although when I when I execute update-alternatives --display php it reports that my link is pointing to /usr/bin/php8.0. Yet, php -v returns:
PHP 8.1.7 (cli) (built: Jun 7 2022 18:21:38) (NTS) Copyright (c) The PHP Group Zend Engine v4.1.7, Copyright (c) Zend Technologies with Zend OPcache v8.1.7, Copyright (c), by Zend Technologies
I'm desperate, this is my work computer and I need to get this working. How does one literally revert from PHP 8.1 back down to version 8.0?
You can uninstall the php 8.1 directly through the terminal.
sudo apt remove php8.1
sudo apt autoremove
Hope this help you.

MacOS Sierra PHP installation with Homebrew not able to use homebrew php

I recently got my hands on a new macbook and I'm loving the terminal!
I'm now configuring my enviroment to run completely on homebrew and on different php versions. To do this, I am following this guide: https://getgrav.org/blog/macos-sierra-apache-multiple-php-versions
Everything works up to the point of
brew unlink php#7.2 && brew link --force --overwrite php#5.6
When I do this I get no error message and everything is OK, however, the guide says that I have to check with php -v to see which version is running and it is NOT php 5.6...
PHP 7.1.16 (cli) (built: Apr 1 2018 13:14:42) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
Is the message I get back.
When I run which php:
/usr/local/bin/php
What I have tried
Restarting apache
removing everything regarding php from /usr/local/php-*
checking brew, both php 5.6 and apache are running
Could anyone help me? Thank you for your time!
EDIT (FIXED):
Restarted my Mac and then the brew PHP installation went trough ^^
You just need to open new shell tab / window. You don't have to restart macOS :)

Postgresql database with PHP server error on MacOS Bash

I ran a PHP server with postgresql on my college computers which works fine, however on my local machine (which runs MacOS), I get the following error message:
Call to undefined function pg_Connect() in /Users/mac/Documents/<... the remaining path to php file>.php on line 2
Now, I thought it's an issue of missing the postgresql packages for php, so I used brew to install the php postgresql packages. I ran the following commands:
brew install postgresql
brew install php55 --with-postgresql
brew install php55-pdo-pgsql
However, even after running these commands I get the same error when running the php server, i.e.
Call to undefined function pg_Connect() in /Users/mac/Documents/<... the remaining path to php file>.php on line 2
The php version I have is 5.5.30:
mac$ php -v
PHP 5.5.30 (cli) (built: Oct 23 2015 17:21:45)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
Please could you suggest what I am doing wrong to install the packages. I read on stack overflow that the packages can be installed with an apt-get command on linux, however I'm not sure as to what the solution is with the Mac operating system.
Thanks in advance.
The solution was edit the php.ini on your server then find this below line and uncomment that line.
extension="pgsql.so"
then restart the server apache and test it out again.
Also, check this link for the steps regarding installation of the postgress to mac OS.

Class Memcached Not Found Lumen 5.4

When trying to run artisan commands I get the following error
[Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'Memcached' not found
I had recently been been working on another project that used Lumen 5.3 and had no problem running artisan commands. Both projects are on the same virtual box and apart from the Lumen versions there is no differences in server setup.
I've checked that Memcached is running and there is no problems.
I've tried composer dump-autoload, deleting the vendor folder and re-installing but none of these have made a difference.
I'd prefer not to have to go back to 5.3 if possible.
Is there a way to solve this issue?
Had the same problem.
Check if you have the memcached extension installed for the php version that you're using, and check also if it is correctly configured in the php.ini file (it could be looking in the wrong directory).
looks like your memcahed is not installed or not properly configured.
for quick solution ,
use file cache driver instead of memcached
CACHE_DRIVER=file
Ubuntu 16.04 LTS, try this:
sudo apt-get install php-memcached
Just to add to the os specific responses. Here is the one using OS/X and homebrew.
First you have to determine which version of PHP you're using locally.
$ php -v
PHP 7.0.19 (cli) (built: May 21 2017 11:56:11) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
$ brew search memcached
homebrew/php/php53-memcached homebrew/php/php70-memcached
homebrew/php/php54-memcached homebrew/php/php71-memcached
homebrew/php/php55-memcached libmemcached ✔
homebrew/php/php56-memcached memcached ✔
Since I'm running PHP 7.0 I chose to install homebrew/php/php70-memcached
$ brew install homebrew/php/php70-memcached
If you don't have homebrew installed go to https://brew.sh/ and install it to use these instructions. This was the command last time I used it.
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Once I was done with all that then I tested by clearing the cache.
$ php artisan cache:clear
Cache cleared successfully.
$
Cheers, this fixed it for me for local development.
If you are on Mac OSX, you will need to install Memcached and its PHP dependencies via Homebrew.
brew update
brew doctor
brew install memcached
Then check your PHP version and install your relevant PHP hooks for Memcached.
php -v
in my case...
PHP 7.1.4 (cli) (built: Apr 14 2017 15:02:16) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
So I used:
brew install php71-memcached
But you can lookup your required version using
brew search memcached
Once you have performed these steps you will probably get a new error
No Memcached servers added.
So fire it up with
brew services restart memcached
Done!

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