Files
mkdocs/docs/macos/webserver/mod-php.md
2025-03-25 15:52:48 +01:00

4.5 KiB

Configurer PHP (mod-php)(Apache 2.2-)

php.ini

Mac intel:

$ nano /usr/local/etc/php/7.4/php.ini
$ nano /usr/local/etc/php/8.0/php.ini

Mac M1:

$ nano /opt/homebrew/etc/php/7.4/php.ini
$ nano /opt/homebrew/etc/php/8.0/php.ini
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = Europe/Paris


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Error handling and logging ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

error_log = php_errors.log


;;;;;;;;;;;;;;;;;;;
; Resource Limits ;
;;;;;;;;;;;;;;;;;;;

memory_limit = 512M

Modifier le httpd.conf:

Mac intel:

$ nano /usr/local/etc/httpd/httpd.conf

Mac M1:

$ nano /opt/homebrew/etc/httpd/httpd.conf

Dans httpd.conf, ajouter les lignes:

Mac intel:

LoadModule php7_module /usr/localopt/php@7.4/lib/httpd/modules/libphp7.so
#LoadModule php_module /usr/local/opt/php@8.0/lib/httpd/modules/libphp.so

Mac M1:

LoadModule php7_module /opt/homebrew/opt/php@7.4/lib/httpd/modules/libphp7.so
#LoadModule php_module /opt/homebrew/opt/php@8.0/lib/httpd/modules/libphp.so

intel / M1:

Remplacer:

<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>

par

<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>

<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>

Changer de version:

Méthode 1:

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

Méthode 2:

PHP switcher script

Installation Mac intel:

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

Installation Mac M1:

$ curl -L https://raw.githubusercontent.com/vadimbk/sphp/main/sphp > /opt/homebrew/bin/sphp
$ chmod +x /opt/homebrew/bin/sphp

Utilisation:

$ sphp 7.4

Xdebug

Installation:
$ sphp 8.2
$ pecl uninstall -r xdebug
$ pecl install xdebug
$ sphp 8.3
$ pecl uninstall -r xdebug
$ pecl install xdebug-3.3.0alpha3
Configuration:
$ bbedit /opt/homebrew/etc/php/8.2/conf.d/ext-xdebug.ini
$ bbedit /opt/homebrew/etc/php/8.3/conf.d/ext-xdebug.ini
[xdebug]
zend_extension="xdebug.so"
xdebug.mode=debug

Xdebug Switcher:

Installation:
$ curl -L https://gist.githubusercontent.com/rhukster/073a2c1270ccb2c6868e7aced92001cf/raw/c1629293bcf628cd6ded20c201c4ef0a2fa79144/xdebug > /opt/homebrew/bin/xdebug
$ chmod +x /opt/homebrew/bin/xdebug
$ xdebug

Usage: xdebug <on | off> [--no-server-restart]

You are running PHP v8.2 with Xdebug enabled

PHP 8.2.14 (cli) (built: Dec 20 2023 06:28:06) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.14, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.14, Copyright (c), by Zend Technologies
    with Xdebug v3.3.1, Copyright (c) 2002-2023, by Derick Rethans

APCu

Installation:
$ pecl install apcu
# fatal error: 'pcre2.h' file not found

$ ln -s /opt/homebrew/Cellar/pcre2/10.42/include/pcre2.h /opt/homebrew/Cellar/php/
$ ln -s /opt/homebrew/opt/pcre2/include/pcre2.h /opt/homebrew/opt/php@8.4/include/php/ext/pcre/

ln -s /opt/homebrew/Cellar/pcre2/10.42/include/pcre2.h /opt/homebrew/Cellar/php/8.3.1/include/php/ext/pcre/pcre2.h

ln -s /opt/homebrew/Cellar/pcre2/10.42/include/pcre2.h /opt/homebrew/Cellar/php@8.2/8.2.14/include/php/ext/pcre/pcre2.h
$ sphp 8.2
$ pecl install apcu
$ sphp 8.3
$ pecl uninstall -r apcu
$ pecl install apcu
Configuration:
$ bbedit /opt/homebrew/etc/php/8.2/conf.d/ext-apcu.ini
$ bbedit /opt/homebrew/etc/php/8.3/conf.d/ext-apcu.ini
[apcu]
extension="apcu.so"
apc.enabled=1
apc.shm_size=64M
apc.ttl=7200
apc.enable_cli=1

YAML

Installation:

$ brew install libyaml
$ sphp 8.2
$ pecl install yaml

# Au prompt "Please provide the prefix of libyaml installation [autodetect]", entrer:
# /opt/homebrew/Cellar/libyaml/0.2.5
$ sphp 8.3
$ pecl uninstall -r yaml
$ pecl install yaml

# Au prompt "Please provide the prefix of libyaml installation [autodetect]", entrer:
# /opt/homebrew/Cellar/libyaml/0.2.5
Configuration:
$ bbedit /opt/homebrew/etc/php/8.2/conf.d/ext-yaml.ini
$ bbedit /opt/homebrew/etc/php/8.3/conf.d/ext-yaml.ini
[yaml]
extension="yaml.so"