514 lines
8.7 KiB
Markdown
514 lines
8.7 KiB
Markdown
# Installer PHP (homebrew)
|
|
|
|
### Installation:
|
|
|
|
Ajouter le tap:
|
|
|
|
```bash
|
|
$ brew tap shivammathur/php
|
|
$ brew update
|
|
```
|
|
|
|
Installer différentes versions de PHP:
|
|
|
|
```bash
|
|
$ brew install shivammathur/php/php@7.4
|
|
$ brew link --overwrite --force php@7.4
|
|
```
|
|
|
|
```bash
|
|
$ brew install shivammathur/php/php@8.0
|
|
$ brew link --overwrite --force php@8.0
|
|
```
|
|
|
|
|
|
|
|
### Configurer PHP:
|
|
|
|
Mac intel:
|
|
|
|
```bash
|
|
$ nano /usr/local/etc/php/7.4/php.ini
|
|
$ nano /usr/local/etc/php/8.0/php.ini
|
|
```
|
|
|
|
Mac M1:
|
|
|
|
```bash
|
|
$ nano /opt/homebrew/etc/php/7.4/php.ini
|
|
$ nano /opt/homebrew/etc/php/8.0/php.ini
|
|
```
|
|
|
|
|
|
|
|
```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:
|
|
|
|
```bash
|
|
$ nano /usr/local/etc/httpd/httpd.conf
|
|
```
|
|
|
|
Mac M1:
|
|
|
|
```bash
|
|
$ nano /opt/homebrew/etc/httpd/httpd.conf
|
|
```
|
|
|
|
Dans *httpd.conf*, ajouter les lignes:
|
|
|
|
Mac intel:
|
|
|
|
```http
|
|
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:
|
|
|
|
```http
|
|
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:
|
|
|
|
```http
|
|
<IfModule dir_module>
|
|
DirectoryIndex index.html
|
|
</IfModule>
|
|
```
|
|
|
|
par
|
|
|
|
```http
|
|
<IfModule dir_module>
|
|
DirectoryIndex index.php index.html
|
|
</IfModule>
|
|
|
|
<FilesMatch \.php$>
|
|
SetHandler application/x-httpd-php
|
|
</FilesMatch>
|
|
```
|
|
|
|
Redémarrer le serveur web:
|
|
|
|
- pour Apache (httpd): `brew services restart httpd`
|
|
- pour Nginx: `brew services restart nginx`
|
|
|
|
Valider PHP:
|
|
|
|
```bash
|
|
echo "<?php phpinfo();" > ~/Sites/info.php
|
|
```
|
|
|
|
et aller sur http://localhost/info.php
|
|
|
|
Si PHP n'est pas interprété, redémarrer le mac.
|
|
|
|
|
|
|
|
### Changer de version:
|
|
|
|
#### Méthode 1:
|
|
|
|
```bash
|
|
$ brew unlink php && brew link --overwrite --force php@7.4
|
|
```
|
|
|
|
#### Méthode 2:
|
|
|
|
*PHP switcher script*
|
|
|
|
Installation Mac intel:
|
|
|
|
```bash
|
|
$ 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:
|
|
|
|
```bash
|
|
$ curl -L https://raw.githubusercontent.com/vadimbk/sphp/main/sphp > /opt/homebrew/bin/sphp
|
|
$ chmod +x /opt/homebrew/bin/sphp
|
|
```
|
|
|
|
Utilisation:
|
|
|
|
```bash
|
|
$ sphp 7.4
|
|
```
|
|
|
|
|
|
|
|
#### Version de PHP:
|
|
|
|
```bash
|
|
$ php -v
|
|
PHP 7.4.22 (cli) (built: Jul 27 2021 15:38:56) ( NTS )
|
|
Copyright (c) The PHP Group
|
|
Zend Engine v3.4.0, Copyright (c) Zend Technologies
|
|
with Zend OPcache v7.4.22, Copyright (c), by Zend Technologies
|
|
with Xdebug v3.0.4, Copyright (c) 2002-2021, by Derick Rethans
|
|
```
|
|
|
|
#### PHP Info:
|
|
|
|
```bash
|
|
$ php -i
|
|
```
|
|
|
|
|
|
|
|
#### Logs:
|
|
|
|
```bash
|
|
/opt/homebrew/var/log/php-fpm.log
|
|
```
|
|
|
|
|
|
|
|
### Extensions:
|
|
|
|
#### Installer une extension (depuis Homebrew):
|
|
|
|
Ajouter le tap:
|
|
|
|
```bash
|
|
$ brew tap shivammathur/php
|
|
$ brew update
|
|
```
|
|
|
|
Installer les [différentes extensions](https://github.com/shivammathur/homebrew-extensions):
|
|
|
|
```bash
|
|
$ brew install xdebug@8.0
|
|
|
|
# Fichier config
|
|
/opt/homebrew/etc/php/8.0/conf.d/xdebug.ini # M1
|
|
/usr/local/etc/php/8.0/conf.d/xdebug.ini # intel
|
|
```
|
|
|
|
```bash
|
|
$ nano /opt/homebrew/etc/php/8.0/conf.d/xdebug.ini
|
|
```
|
|
|
|
```php
|
|
[xdebug]
|
|
zend_extension="/opt/homebrew/opt/xdebug@8.0/xdebug.so"
|
|
xdebug.mode=debug
|
|
```
|
|
|
|
|
|
|
|
```bash
|
|
$ brew install apcu@8.0
|
|
|
|
# Fichier config
|
|
/opt/homebrew/etc/php/8.0/conf.d/apcu.ini
|
|
```
|
|
|
|
```bash
|
|
$ nano /opt/homebrew/etc/php/8.0/conf.d/apcu.ini
|
|
```
|
|
|
|
```php
|
|
[apcu]
|
|
extension="/opt/homebrew/opt/apcu@8.0/apcu.so"
|
|
apc.enabled=1
|
|
apc.shm_size=64M
|
|
apc.ttl=7200
|
|
apc.enable_cli=1
|
|
```
|
|
|
|
|
|
|
|
```bash
|
|
$ brew install imagick@8.0
|
|
|
|
# Fichier config
|
|
/opt/homebrew/etc/php/8.0/conf.d/imagick.ini
|
|
```
|
|
|
|
```bash
|
|
$ nano /opt/homebrew/etc/php/8.0/conf.d/imagick.ini
|
|
```
|
|
|
|
```php
|
|
[imagick]
|
|
extension="/opt/homebrew/opt/imagick@8.0/imagick.so"
|
|
```
|
|
|
|
|
|
|
|
```bash
|
|
$ brew install memcached@8.0
|
|
|
|
# Fichier config
|
|
/opt/homebrew/etc/php/7.4/conf.d/memcached.ini
|
|
```
|
|
|
|
```bash
|
|
$ nano /opt/homebrew/etc/php/7.4/conf.d/memcached.ini
|
|
```
|
|
|
|
```php
|
|
[memcached]
|
|
extension="/opt/homebrew/opt/memcached@7.4/memcached.so"
|
|
```
|
|
|
|
|
|
|
|
#### Installer une extension (PECL)
|
|
|
|
On peut également installer des extensions avec [PECL](https://pecl.php.net):
|
|
|
|
```bash
|
|
$ pecl channel-update pecl.php.net
|
|
```
|
|
|
|
<u>mcrypt:</u>
|
|
|
|
```bash
|
|
$ brew install mcrypt
|
|
|
|
$ pecl install mcrypt
|
|
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
|
|
```
|
|
|
|
```bash
|
|
$ pecl install mcrypt
|
|
|
|
libmcrypt prefix? [autodetect] : /opt/homebrew
|
|
|
|
Build process completed successfully
|
|
Installing '/opt/homebrew/Cellar/php/8.0.8_2/pecl/20200930/mcrypt.so'
|
|
install ok: channel://pecl.php.net/mcrypt-1.0.4
|
|
Extension mcrypt enabled in php.ini
|
|
```
|
|
|
|
<u>Yaml:</u>
|
|
|
|
```bash
|
|
$ brew install libyaml
|
|
|
|
$ pecl install yaml
|
|
configure: error: Please install libyaml
|
|
```
|
|
|
|
```bash
|
|
$ pecl install yaml
|
|
|
|
Please provide the prefix of libyaml installation [autodetect] : /opt/homebrew
|
|
|
|
Build process completed successfully
|
|
Installing '/opt/homebrew/Cellar/php/8.0.8_2/pecl/20200930/yaml.so'
|
|
install ok: channel://pecl.php.net/yaml-2.2.1
|
|
Extension yaml enabled in php.ini
|
|
```
|
|
|
|
PECL a un souci avec l'installation homebrew des macs M1:
|
|
|
|
https://stackoverflow.com/a/68138560/12431632
|
|
|
|
Chaque version de PHP a son propre répertoire d'extensions:
|
|
|
|
Mac intel:
|
|
|
|
```bash
|
|
/usr/local/lib/php/pecl/20160303 ← 7.1
|
|
/usr/local/lib/php/pecl/20170718 ← 7.2
|
|
/usr/local/lib/php/pecl/20180731 ← 7.3
|
|
/usr/local/lib/php/pecl/20190902 ← 7.4
|
|
/usr/local/lib/php/pecl/20200930 ← 8.0
|
|
```
|
|
|
|
Mac M1:
|
|
|
|
```bash
|
|
/opt/homebrew/lib/php/pecl/20160303 ← 7.1
|
|
/opt/homebrew/lib/php/pecl/20170718 ← 7.2
|
|
/opt/homebrew/lib/php/pecl/20180731 ← 7.3
|
|
/opt/homebrew/lib/php/pecl/20190902 ← 7.4
|
|
/opt/homebrew/lib/php/pecl/20200930 ← 8.0
|
|
```
|
|
|
|
Désinstaller une extension:
|
|
|
|
```bash
|
|
$ pecl uninstall mcrypt
|
|
Extension mcrypt disabled in php.ini
|
|
uninstall ok: channel://pecl.php.net/mcrypt-1.0.4
|
|
```
|
|
|
|
|
|
|
|
#### Installer une extension (depuis les sources):
|
|
|
|
<u>ssh2:</u>
|
|
|
|
```bash
|
|
# Installation de ssh2:
|
|
# https://pecl.php.net/package/ssh2
|
|
|
|
$ brew install libssh2
|
|
|
|
$ cd ~/Downloads
|
|
$ wget https://pecl.php.net/get/ssh2-1.3.1.tgz
|
|
$ tar zxvf ssh2-1.3.1.tgz
|
|
$ cd ssh2-1.3.1
|
|
$ phpize
|
|
$ ./configure
|
|
|
|
checking for ssh2 files in default path... not found
|
|
configure: error: The required libssh2 library was not found. You can obtain that package from http://sourceforge.net/projects/libssh2/
|
|
|
|
# libssh2 est dans /opt/homebrew mais attendue dans /usr/local
|
|
|
|
$ ./configure --with-ssh2=$(brew --prefix libssh2)
|
|
|
|
$ make
|
|
...
|
|
Libraries have been installed in:
|
|
/Users/bruno/Downloads/ssh2-1.3.1/modules
|
|
|
|
$ make install
|
|
Installing shared extensions: /opt/homebrew/Cellar/php@7.4/7.4.22/pecl/20190902/
|
|
```
|
|
|
|
```bash
|
|
$ nano /opt/homebrew/etc/php/7.4/conf.d/ssh2.ini
|
|
```
|
|
|
|
```php
|
|
[ssh2]
|
|
extension="/opt/homebrew/Cellar/php@7.4/7.4.22/pecl/20190902/ssh2.so"
|
|
```
|
|
|
|
|
|
|
|
<u>Yaml:</u>
|
|
|
|
```bash
|
|
# Installation de yaml:
|
|
# https://pecl.php.net/package/yaml
|
|
|
|
$ brew install libyaml
|
|
|
|
$ cd ~/Downloads
|
|
$ wget https://pecl.php.net/get/yaml-2.2.1.tgz
|
|
$ tar zxvf yaml-2.2.1.tgz
|
|
$ cd yaml-2.2.1/
|
|
$ phpize
|
|
$ ./configure
|
|
|
|
checking for yaml headers... not found
|
|
configure: error: Please install libyaml
|
|
|
|
# libyaml est dans /opt/homebrew mais attendue dans /usr/local
|
|
|
|
$ ./configure --with-yaml=$(brew --prefix libyaml)
|
|
|
|
$ make
|
|
...
|
|
Libraries have been installed in:
|
|
/Users/bruno/Downloads/yaml-2.2.1/modules
|
|
|
|
$ make install
|
|
Installing shared extensions: /opt/homebrew/Cellar/php@7.4/7.4.22/pecl/20190902/
|
|
```
|
|
|
|
```bash
|
|
$ nano /opt/homebrew/etc/php/7.4/conf.d/yaml.ini
|
|
```
|
|
|
|
```php
|
|
[yaml]
|
|
extension="/opt/homebrew/Cellar/php@7.4/7.4.22/pecl/20190902/yaml.so"
|
|
```
|
|
|
|
|
|
|
|
<u>mcrypt</u>:
|
|
|
|
```bash
|
|
# Installation de mcrypt:
|
|
# https://pecl.php.net/package/mcrypt
|
|
|
|
$ brew install libmcrypt
|
|
|
|
$ cd ~/Downloads
|
|
$ wget https://pecl.php.net/get/mcrypt-1.0.4.tgz
|
|
$ tar zxvf mcrypt-1.0.4.tgz
|
|
$ cd mcrypt-1.0.4/
|
|
$ phpize
|
|
$ ./configure
|
|
|
|
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
|
|
|
|
# libmcrypt est dans /opt/homebrew mais attendue dans /usr/local
|
|
|
|
./configure --with-mcrypt=$(brew --prefix libmcrypt)
|
|
|
|
$ make
|
|
...
|
|
Libraries have been installed in:
|
|
/Users/bruno/Downloads/mcrypt-1.0.4/modules
|
|
|
|
$ make install
|
|
Installing shared extensions: /opt/homebrew/Cellar/php@7.4/7.4.22/pecl/20190902/
|
|
```
|
|
|
|
```bash
|
|
$ nano /opt/homebrew/etc/php/7.4/conf.d/mcrypt.ini
|
|
```
|
|
|
|
```php
|
|
[mcrypt]
|
|
extension="/opt/homebrew/Cellar/php@7.4/7.4.22/pecl/20190902/mcrypt.so"
|
|
```
|
|
|
|
|
|
|
|
Chaque version de PHP a son propre répertoire d'extensions:
|
|
|
|
Mac intel:
|
|
|
|
```bash
|
|
/usr/local/Cellar/php@7.4/7.4.22/pecl/20190902/
|
|
```
|
|
|
|
Mac M1:
|
|
|
|
```bash
|
|
/opt/homebrew/Cellar/php@7.4/7.4.22/pecl/20190902/
|
|
```
|
|
|