07 - PHP

Zuletzt aktualisiert am 2. Februar 2024 2 Minuten

PHP komplett deinstallieren

Schauen was ist installiert: brew list | grep php. Uralte php Versionen entfernen / altes Homebrew Schema:

brew untap exolnet/deprecated
brew uninstall --force php56 php56-apcu php56-opcache php56-xdebug php56-yaml
brew uninstall --force php70 php70-apcu php70-opcache php70-xdebug php70-yaml
brew uninstall --force php71 php71-apcu php71-opcache php71-xdebug php71-yaml
brew uninstall --force php72 php72-apcu php72-opcache php72-xdebug php72-yaml
brew uninstall --force php73 php73-apcu php73-opcache php73-xdebug php73-yaml
brew uninstall --force php74 php74-apcu php74-opcache php74-xdebug php74-yaml

Weitere zu entfernende Versionen waren bei mir:

brew uninstall --force php@7.3
uninstall --force phpmyadmin
rm -Rf /usr/local/etc/php/\*

Jetzt ist das System wieder sauber, und alles kann neu installiert werden:

PHP Versionen installieren

welche php Versionen sind installiert?

brew search php

Im Terminal

brew tap shivammathur/php
brew install shivammathur/php/php@7.4
brew install shivammathur/php/php@8.0

Ich habe 7.4 und 8.0 installiert. Auch wenn mehrere Versionen installiert sind, ist immer nur eine PHP Version aktiv.

wenn PHP zuerst im PATH sein soll:

echo 'export PATH="/usr/local/opt/php@7.1/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/usr/local/opt/php@7.1/sbin:$PATH"' >> ~/.zshrc

Ausserdem:

pecl install memcached

php.ini bearbeiten

codium /usr/local/etc/php/7.4/php.ini
codium /usr/local/etc/php/8.0/php.ini
date.timezone = Europe/Berlin

Das Terminal schließen, und ein neues Terminal öffnen.

Prüfe die Version

php -v
which php

which php Liefert den Pfad zum executable: /usr/local/bin/php

Apache Module

codium /usr/local/etc/httpd/httpd.conf

INFO: Das bleibt neuerdings alles auskommentiert. Keine Ahnung wieso.

#LoadModule php5_module /usr/local/opt/php@5.6/lib/httpd/modules/libphp5.so
#LoadModule php7_module /usr/local/opt/php@7.0/lib/httpd/modules/libphp7.so
#LoadModule php7_module /usr/local/opt/php@7.1/lib/httpd/modules/libphp7.so
#LoadModule php7_module /usr/local/opt/php@7.2/lib/httpd/modules/libphp7.so
LoadModule php7_module /usr/local/opt/php@7.4/lib/httpd/modules/libphp7.so

und

DirectoryIndex index.php index.html
SetHandler application/x-httpd-php

Dann den Server neu starten.

sudo apachectl -k stop
sudo apachectl start

PHP Versionen umschalten

Dazu gibt es das kompfortables Skript sphp das du zunächst installieren musst:

curl -L https://gist.githubusercontent.com/rhukster/f4c04f1bf59e0b74e335ee5d186a98e2/raw > /usr/local/bin/sphp
chmod +x /usr/local/bin/sphp

Pfad prüfen

echo $PATH

Der sollte so aussehen: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

Umschalten von einer der aktiven PHP Version zB. auf 7.4 oder auf 8.0 - falls die installiert sind:

sphp 7.4
php -v
sphp 8.0
php -v

Eine etwas “komplizierte Art” der Umschaltung ohne sphp Skript, im Terminal:

brew unlink php && brew link --overwrite --force php@7.4
brew unlink php && brew link --overwrite --force php@8.0

PHP Version aktualisieren

Es ist immer nur eine PHP Version aktiv. Um alle installierten PHP Version zu aktuallisieren muss du jeweils zur Version wechseln und dann das Update dafür ausführen.

php als Dienst starten

brew services start php

oder php-fpm wenn du keinen Dienst benötigst.