06-08-20121

This commit is contained in:
2021-08-06 13:32:29 +02:00
parent 53aa196ac1
commit 7d89fb0224
14 changed files with 2297 additions and 46 deletions

View File

@@ -1,4 +1,4 @@
# nvm
# nvm

View File

@@ -113,10 +113,10 @@ lrwxr-xr-x 1 bruno staff 6 15 mar 07:29 python3 -> python
Mettre-à-jour `pip` et `setuptools`:
Mettre-à-jour `pip`, `setuptools` et installer `wheel`:
```bash
(tuto-virtuel-env) bruno@SilverBook:~/venv/tuto-virtuel-env/bin$ pip3 install -U pip setuptools
(tuto-virtuel-env) bruno@SilverBook:~/venv/tuto-virtuel-env/bin$ pip3 install -U pip setuptools wheel
```
@@ -150,6 +150,27 @@ Le module installé dans l'environnement virtuel est disponible UNIQUEMENT dans
#### Virtual environnment courant:
```python
python
Python 3.9.6 (default, Jun 28 2021, 19:24:41)
[Clang 12.0.5 (clang-1205.0.22.9)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print(sys.prefix)
/Users/bruno/Documents/venv/soco-cli
>>> print(sys.executable)
/Users/bruno/Documents/venv/soco-cli/bin/python
>>>
```
```bash
which -a python
/Users/bruno/Documents/venv/soco-cli/bin/python
/usr/bin/python
```
### pyvenv

View File

@@ -0,0 +1,691 @@
# Apache
### Installer Apache (homebrew)
#### Désactiver le serveur Apache d'origine:
```bash
$ sudo apachectl stop
$ sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist 2>/dev/null
```
#### Installation:
```bash
$ brew install httpd
$ sudo brew services start httpd
```
Voir si Apache tourne:
```bash
$ ps -aef | grep httpd
501 28356 1 0 10:56 ?? 0:00.29 /opt/homebrew/opt/httpd/bin/httpd -D FOREGROUND
501 12984 781 0 9:09 ttys001 0:00.01 tail -f /opt/homebrew/var/log/httpd/error_log
501 29101 786 0 1:19 ttys002 0:00.00 grep httpd
```
Faire les m-à-j directement depuis Homebrew.
### Arrêter / redémarrer Apache
Apache est controllé par les *services brew*:
```bash
$ brew services stop httpd
$ brew services start httpd
$ brew services restart httpd
```
ou par *apachectl*:
```bash
$ sudo apachectl start
$ sudo apachectl stop
$ sudo apachectl -k restart
$ sudo apachectl -k restart -e Debug -E /dev/stdout
```
### Log:
```bash
# Mac intel
$ tail -f /usr/local/var/log/httpd/error_log
$ tail -f /usr/local/var/log/httpd/access_log
# Mac M1
$ tail -f /opt/homebrew/var/log/httpd/error_log
$ tail -f /opt/homebrew/var/log/httpd/access_log
```
```bash
$ multitail -s 2 /usr/local/var/log/httpd/error_log /usr/local/var/log/httpd/access_log
```
```bash
$ tail -f /opt/homebrew/var/log/httpd/error_log -f /opt/homebrew/var/log/httpd/access_log
==> /opt/homebrew/var/log/httpd/error_log <==
[Fri Jul 30 06:58:08.250315 2021] [mpm_prefork:notice] [pid 59484] AH00169: caught SIGTERM, shutting down
PHP Warning: PHP Startup: Unable to load dynamic library 'mcrypt.so' (tried: /opt/homebrew/lib/php/pecl/20200930/mcrypt.so (dlopen(/opt/homebrew/lib/php/pecl/20200930/mcrypt.so, 9): image not found), /opt/homebrew/lib/php/pecl/20200930/mcrypt.so.so (dlopen(/opt/homebrew/lib/php/pecl/20200930/mcrypt.so.so, 9): image not found)) in Unknown on line 0
==> /opt/homebrew/var/log/httpd/access_log <==
::1 - - [29/Jul/2021:17:39:55 +0200] "GET /info.php HTTP/1.1" 200 120227
::1 - - [29/Jul/2021:18:04:09 +0200] "GET /info.php HTTP/1.1" 200 120660
```
### Version:
```bash
$ httpd -v
Server version: Apache/2.4.48 (Unix)
Server built: Jul 6 2021 20:11:03
```
### Modules activés:
```bash
$ httpd -M
Loaded Modules:
core_module (static)
so_module (static)
http_module (static)
mpm_prefork_module (shared)
authn_file_module (shared)
$ apachectl -M
```
### Configuration:
Ouvrir le fichier *httpd.conf*:
```bash
# Mac intel
$ nano /usr/local/etc/httpd/httpd.conf
# Mac M1
$ nano /opt/homebrew/etc/httpd/httpd.conf
```
Remplacer les lignes et blocs:
| Original | Modifié |
| ----------------------------------------------- | ------------------------------------------------------------ |
| `Listen 8080` | `Listen 80` |
| `DocumentRoot "/usr/local/var/www"` | `DocumentRoot "/Users/bruno/Sites"` |
| `<Directory "/usr/local/var/www">` | `<Directory "/Users/bruno/Sites">`<br /><br />*Dans le même bloc Directory:*<br/>`AllowOverride All` |
| #User & Group:<br/>`User http`<br/>`Group http` | #User & Group:<br/>`User bruno`<br/>`Group staff` |
| `#ServerName www.example.com:8080`<br/> | `ServerName airbook.local`<br />#ServerName localhost |
Activer certains modules:
```http
LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so
```
Créer une page d'accueil:
```bash
echo "<h1>My User Web Root</h1>" > ~/Sites/index.html
```
#### Tester la configuration:
```bash
$ httpd -t
Syntax OK
$ apachectl configtest
```
#### Redémarrer Apache:
```bash
$ brew services restart httpd
```
Créer un alias dans .zshrc
```bash
alias bra='brew services restart httpd'
```
### [=> Installer PHP](php_M1.md)
### Virtual Hosts:
Les activer dans *httpd.conf* (décocher les lignes):
```http
LoadModule vhost_alias_module lib/httpd/modules/mod_vhost_alias.so
```
Mac M1
```http
# Virtual hosts
Include /opt/homebrew/etc/httpd/extra/httpd-vhosts.conf
```
Mac intel
```http
# Virtual hosts
Include /usr/local/etc/httpd/extra/httpd-vhosts.conf
```
#### Redirection:
Editer le fichier *hosts*:
```bash
$ sudo nano /etc/hosts
127.0.0.1 airbook.local
127.0.0.1 wordpress.airbook.local
127.0.0.1 dev.airbook.local
127.0.0.1 zenphoto.airbook.local
127.0.0.1 phpmyadmin.airbook.local
```
Editer le fichier *httpd-vhosts.conf*:
```bash
# Mac intel
$ nano /usr/local/etc/httpd/extra/httpd-vhosts.conf
# Mac M1
$ nano /opt/homebrew/etc/httpd/extra/httpd-vhosts.conf
```
```http
<VirtualHost *:80>
DocumentRoot /Users/bruno/Sites/wordpress
ServerName wordpress.air.local
CustomLog /usr/local/var/log/httpd/wordpress-access.log combined
ErrorLog /usr/local/var/log/httpd/wordpress-error.log
</VirtualHost>
```
#### Redirection de port:
wiki.js tourne sur localhost:3000
Pour le rendre disponible sur wiki.silverbook.local:
Editer le fichier *httpd.conf* et activer les modules `mod_proxy` et `mod_proxy_http`:
```http
LoadModule proxy_module lib/httpd/modules/mod_proxy.so
LoadModule proxy_http_module lib/httpd/modules/mod_proxy_http.so
```
Editer le fichier *hosts*:
```bash
$ sudo nano /etc/hosts
127.0.0.1 airbook.local
127.0.0.1 wiki.airbook.local
```
Editer le fichier *httpd-vhosts.conf*:
```http
<VirtualHost *:80>
ServerName wiki.airbook.local
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
ProxyPreserveHost On
</VirtualHost>
```
### SSL:
Activer SSL dans *httpd.conf* (décocher les lignes):
```http
LoadModule socache_shmcb_module lib/httpd/modules/mod_socache_shmcb.so
...
LoadModule ssl_module lib/httpd/modules/mod_ssl.so
```
Mac M1
```http
# Secure (SSL/TLS) connections
Include /opt/homebrew/etc/httpd/extra/httpd-ssl.conf
```
Mac intel
```http
# Secure (SSL/TLS) connections
Include /usr/local/etc/httpd/extra/httpd-ssl.conf
```
Ouvrir le fichier *httpd-ssl.conf*:
```bash
# Mac intel
$ nano /usr/local/etc/httpd/extra/httpd-ssl.conf
# Mac M1
$ nano /opt/homebrew/etc/httpd/extra/httpd-ssl.conf
```
Remplacer les lignes:
| Original | Modifié |
| -------------------------------------- | ----------------------------------- |
| `Listen 8443` | `Listen 443` |
et le bloc:
```http
<VirtualHost _default_:8443>
# General setup for the virtual host
DocumentRoot "/opt/homebrew/var/www"
ServerName www.example.com:8443
ServerAdmin you@example.com
ErrorLog "/opt/homebrew/var/log/httpd/error_log"
TransferLog "/opt/homebrew/var/log/httpd/access_log"
```
par
```http
<VirtualHost _default_:443>
# General setup for the virtual host
DocumentRoot "/Users/bruno/Sites"
ServerName airbook.local:443
ServerAdmin bruno@clicclac.info
ErrorLog "/opt/homebrew/var/log/httpd/error_log"
TransferLog "/opt/homebrew/var/log/httpd/access_log"
```
Ouvrir le fichier *httpd-vhosts.conf*:
Rajouter ce bloc pour chaque Virtual Host.
```http
<VirtualHost *:443>
DocumentRoot "/Users/bruno/Sites"
ServerName airbook.local
SSLEngine on
SSLCertificateFile "/usr/local/etc/httpd/server.crt"
SSLCertificateKeyFile "/usr/local/etc/httpd/server.key"
</VirtualHost>
```
### Générer un certificat auto-signé:
#### Méthode 1:
Générer la <u>clé</u> et le <u>certificat</u> (*Common Name* doit correspondre à *ServerName* du *https-vhosts.conf*)
```bash
$ cd /usr/local/etc/httpd
$ openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout server.key -out server.crt
```
Vérifier la configuration Apache et relancer le serveur:
```bash
$ sudo apachectl configtest
$ sudo apachectl -k restart
```
#### Méthode 2:
Installer 2 programmes:
- mkcert: Simple tool to make locally trusted development certificates
- nss: Libraries for security-enabled client and server applications (for Firefox)
```bash
$ brew install mkcert nss
```
Installer le serveur de certificat:
```bash
$ mkcert -install
Created a new local CA 💥
Sudo password:
The local CA is now installed in the system trust store! ⚡️
The local CA is now installed in the Firefox trust store (requires browser restart)! 🦊
```
Créer les dossiers pour les certificats:
```bash
$ cd /opt/homebrew/etc/httpd
$ mkdir certs && cd certs
```
Générer les certificats:
```bash
$ mkcert airbook.local
Created a new certificate valid for the following names 📜
- "airbook.local"
The certificate is at "./airbook.local.pem" and the key at "./airbook.local-key.pem"
It will expire on 29 October 2023 🗓
```
Un certificat et une clé sont créer pour chaque domaine:
```http
/opt/homebrew/etc/httpd/certs/airbook.local.pem
/opt/homebrew/etc/httpd/certs/airbook.local-key.pem
```
Editer le fichier *httpd-ssl.conf* et remplacer les 2 lignes:
```http
SSLCertificateFile "/opt/homebrew/etc/httpd/certs/airbook.local.pem"
SSLCertificateKeyFile "/opt/homebrew/etc/httpd/certs/airbook.local-key.pem"
```
Tester la configuration:
```bash
$ httpd -t
Syntax OK
$ apachectl configtest
```
Redémarrer Apache:
```bash
$ brew services restart httpd
```
#### SSL dans Virtual Host
Editer le fichier *httpd-vhosts.conf*:
Rajouter le bloc suivant
```http
<VirtualHost *:443>
DocumentRoot "/Users/bruno/Sites"
ServerName airbook.local
SSLEngine on
SSLCertificateFile "/opt/homebrew/etc/httpd/certs/airbook.local.pem"
SSLCertificateKeyFile "/opt/homebrew/etc/httpd/certs/airbook.local-key.pem"
</VirtualHost>
```
après le bloc
```http
<VirtualHost *:80>
ServerAdmin bruno@clicclac.info
DocumentRoot "/Users/bruno/Sites"
ServerName airbook.local
#ServerAlias www.dummy-host.example.com
#ErrorLog "/opt/homebrew/var/log/httpd/dummy-host.example.com-error_log"
#CustomLog "/opt/homebrew/var/log/httpd/dummy-host.example.com-access_log" common
</VirtualHost>
```
### Warning: getimagesize(): SSL operation failed with code 1.
Erreur dans Worpdress:
```
Warning: getimagesize(): SSL operation failed with code 1.
OpenSSL Error messages: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed in
/Users/bruno/Sites/wordpress/wp-content/themes/CreatorThemeRes-child/functions.php on line 1611
```
Il faut rajouter les lignes suivantes au PHP.ini
```ini
[openssl]
openssl.cafile="/usr/local/etc/httpd/server.crt"
# D'après SSLCertificateFile "/usr/local/etc/httpd/server.crt" du httpd-ssl.conf
```
https://stackoverflow.com/questions/51532963/tcpdf-getimagesize-ssl-operation-failed-with-code-1-error1416f086ssl-routi
Mais ça donne une erreur pour les MàJ PECL: `Connection to ssl://pecl.php.net:443' failed: `
### Messages d'erreur personnalisés:
Dans un fichier .htaccess, ajouter:
```html
ErrorDocument 404 /custom_404.html
ErrorDocument 500 /custom_50x.html
```
### Messages d'erreur personnalisés multilingues:
Ouvrir le fichier *httpd-ssl.conf* et dé-commenter les lignes suivantes:
```http
LoadModule include_module lib/httpd/modules/mod_include.so
LoadModule negotiation_module lib/httpd/modules/mod_negotiation.so
Include /usr/local/etc/httpd/extra/httpd-multilang-errordoc.conf
```
### Installer phpmyadmin (Homebrew):
```bash
$ brew install homebrew/php/phpmyadmin
```
Le fichier de configuration se trouve là:`/usr/local/etc/phpmyadmin.config.inc.php`
Ajouter le bloc qui suit dans le **httpd.conf**
```http
Alias /phpmyadmin /usr/local/share/phpmyadmin
<Directory /usr/local/share/phpmyadmin/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
<IfModule mod_authz_core.c>
Require all granted
</IfModule>
<IfModule !mod_authz_core.c>
Order allow,deny
Allow from all
</IfModule>
</Directory>
```
### Message derreur personnalisé:
[:fa-link: https://httpd.apache.org/docs/2.4/fr/custom-error.html](https://httpd.apache.org/docs/2.4/fr/custom-error.html)
### Différence installation macOS - homebrew:
***MacOS:***
```bash
/usr/sbin/httpd-wrapper
/System/Library/LaunchDaemons/org.apache.httpd.plist
/Library/WebServer/Documents/index.html
/private/etc/apache2/httpd.conf
/private/etc/apache2/extra/httpd-vhosts.conf
```
***Homebrew:***
Mac intel:
```bash
/usr/local/opt/httpd/bin/httpd
/Users/bruno/Library/LaunchAgents/homebrew.mxcl.httpd.plist
/Users/bruno/Library/LaunchAgents/homebrew.mxcl.php.plist
/Users/bruno/Library/LaunchAgents/homebrew.mxcl.mariadb.plist
/usr/local/var/www/index.html -> /Users/bruno/Sites
/usr/local/etc/httpd/httpd.conf
/usr/local/etc/httpd/extra/httpd-vhosts.conf
```
Mac M1:
```bash
/opt/homebrew/opt/httpd/bin/httpd
/Users/bruno/Library/LaunchAgents/homebrew.mxcl.httpd.plist
/Users/bruno/Library/LaunchAgents/homebrew.mxcl.php.plist
/Users/bruno/Library/LaunchAgents/homebrew.mxcl.mariadb.plist
/opt/homebrew/var/www/index.html -> /Users/bruno/Sites
/opt/homebrew/etc/httpd/httpd.conf
/opt/homebrew/etc/httpd/extra/httpd-vhosts.conf
```
### Arrêt brutal de macOS:
Il se peut qu'au redémarrage, Apache ne fonctionne plus.
Regarder *error_log*:
<!--Tue Jan 30 13:24:14.790214 2018] [core:warn][pid 2103] AH00098: pid file /usr/lo 218-->
<!--cal/var/run/httpd/httpd.pid overwritten -- Unclean shutdown of previous Apache run 127.0.0.1 - - [30/Jan/2018:09:57:30 +0100] "GET /favicon.ico HTTP/1.1" 404 209-->
<!--?-->
Puis arrêter et redémarrer Apache:
```bash
$ sudo apachectl stop
$ sudo apachectl start
```
### Nouvelle version de Python:
<u>Apache ne fonctionne plus</u>. Regarder *error_log*:
```http
Fatal Python error: Py_Initialize: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'
```
Dans *httpd.conf* commencer par vérifier la version de Python dans la ligne suivante. Si elle est correcte, commenter la ligne:
`WSGIPythonHome "/usr/local/Cellar/python/3.6.4_4/Frameworks/Python.framework/Versions/3.6"`
Arrêter et redémarrer Apache.
Si cela refonctionne, désinstaller et réinstaller <u>mod_wsgi</u> avec <u>pip</u>.
```bash
$ pip3 list --format=columns
Package Version
------
...
mod-wsgi 4.6.4
...
$ pip uninstall mod-wsgi
Uninstalling mod-wsgi-4.6.4:
Would remove:
/usr/local/bin/mod_wsgi-express
/usr/local/lib/python3.6/site-packages/mod_wsgi-4.6.4.dist-info/*
/usr/local/lib/python3.6/site-packages/mod_wsgi/*
Proceed (y/n)? y
Successfully uninstalled mod-wsgi-4.6.4
$ pip install mod-wsgi
Collecting mod-wsgi
Downloading https://files.pythonhosted.org/packages/9e/37/dd336068ece37c43957aa337f25c59a9a6afa98086e5507908a2d21ab807/mod_wsgi-4.6.4.tar.gz (2.6MB)
100% |████████████████████████████████| 2.6MB 1.6MB/s
Building wheels for collected packages: mod-wsgi
Running setup.py bdist_wheel for mod-wsgi ... done
Stored in directory: /Users/bruno/Library/Caches/pip/wheels/2d/73/68/9dcbbd0147b3fde4686263a31324ea2372e42f7cefa2f7d181
Successfully built mod-wsgi
Installing collected packages: mod-wsgi
Successfully installed mod-wsgi-4.6.4
$ sudo apachectl stop
$ sudo apachectl start
```
Pour connaître la configuration dans *httpd.conf*, lancez `mod_wsgi-express module-config`
```bash
$ mod_wsgi-express module-config
LoadModule wsgi_module "/usr/local/lib/python3.8/site-packages/mod_wsgi/server/mod_wsgi-py38.cpython-38-darwin.so"
WSGIPythonHome "/usr/local/Cellar/python@3.8/3.8.3_2/Frameworks/Python.framework/Versions/3.8"
```
### Liens:
[:fa-link: https://getgrav.org/blog/macos-bigsur-apache-multiple-php-versions](https://getgrav.org/blog/macos-bigsur-apache-multiple-php-versions)
[:fa-link: https://lukearmstrong.github.io/2016/12/setup-apache-mysql-php-homebrew-macos-sierra/](https://lukearmstrong.github.io/2016/12/setup-apache-mysql-php-homebrew-macos-sierra/)

View File

@@ -1,93 +1,513 @@
# ls -Installer PHP (homebrew)
# Installer PHP (homebrew)
### Installation:
Ajouter le tap:
```bash
$ brew tap homebrew/php
$ brew tap shivammathur/php
$ brew update
$ brew install php71 --with-httpd
```
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
$ bbedit /usr/local/etc/php/7.1/php.ini
$ 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:
```http
httpd.conf:
#LoadModule php7_module /usr/local/Cellar/php71/7.1.11_22/libexec/apache2/libphp7.so
LoadModule php7_module /usr/local/opt/php71/libexec/apache2/libphp7.so
```
### Version de PHP:
Mac intel:
```bash
$ php -v
$ 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 php54 && brew link php53
$ brew unlink php && brew link --overwrite --force php@7.4
```
Erreur: Failed loading /usr/local/opt/php71-opcache/opcache.so: dlopen(/usr/local/opt/php71-opcache/opcache.so, 9): Symbol not found: *compiler*globals ⇒
#### Méthode 2:
*PHP switcher script*
Installation Mac intel:
```bash
$ brew reinstall php71-opcache --build-from-source
$ brew reinstall php71-apcu --build-from-source
$ brew reinstall php71-xdebug --build-from-source
$ brew reinstall php71-yaml --build-from-source
$ 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
```
## Extensions:
### Liste des extensions (Homebrew):
#### Version de PHP:
```bash
$ brew search php71
$ 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
```
### Installer l'extension Tideways:
[:fa-link: https://tideways.io/profiler/docs/setup/installation#macos-homebrew](https://tideways.io/profiler/docs/setup/installation#macos-homebrew)
#### Logs:
```bash
$ brew tap tideways/homebrew-profiler
$ brew install tideways-daemon-tideways
/opt/homebrew/var/log/php-fpm.log
```
Puis ajouter dans le php.ini
### Extensions:
`extension=/usr/local/opt/php71/lib/php/extensions/no-debug-non-zts-20160303/tideways.so`
#### Installer une extension (depuis Homebrew):
Idem pour mongodb
Ajouter le tap:
`extension=/usr/local/opt/php71/lib/php/extensions/no-debug-non-zts-20160303/mongodb.so`
```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
```
### Liens:
```bash
$ brew install apcu@8.0
[:fa-link: PHP (osx)](https://php-osx.liip.ch/) (package PHP)
# Fichier config
/opt/homebrew/etc/php/8.0/conf.d/apcu.ini
```
[Installer Xhprof pour PHP7](Xhprof.md)
```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/
```
[Installer mongodb](mongodb.md)

View File

@@ -0,0 +1,93 @@
# Installer PHP (homebrew)
### Installation:
```bash
$ brew tap homebrew/php
$ brew update
$ brew install php71 --with-httpd
```
### Configurer PHP:
```bash
$ bbedit /usr/local/etc/php/7.1/php.ini
```
### Modifier le httpd.conf:
```http
httpd.conf:
#LoadModule php7_module /usr/local/Cellar/php71/7.1.11_22/libexec/apache2/libphp7.so
LoadModule php7_module /usr/local/opt/php71/libexec/apache2/libphp7.so
```
### Version de PHP:
```bash
$ php -v
```
### Changer de version:
```bash
$ brew unlink php54 && brew link php53
```
Erreur: Failed loading /usr/local/opt/php71-opcache/opcache.so: dlopen(/usr/local/opt/php71-opcache/opcache.so, 9): Symbol not found: *compiler*globals ⇒
```bash
$ brew reinstall php71-opcache --build-from-source
$ brew reinstall php71-apcu --build-from-source
$ brew reinstall php71-xdebug --build-from-source
$ brew reinstall php71-yaml --build-from-source
```
## Extensions:
### Liste des extensions (Homebrew):
```bash
$ brew search php71
```
### Installer l'extension Tideways:
[:fa-link: https://tideways.io/profiler/docs/setup/installation#macos-homebrew](https://tideways.io/profiler/docs/setup/installation#macos-homebrew)
```bash
$ brew tap tideways/homebrew-profiler
$ brew install tideways-daemon-tideways
```
Puis ajouter dans le php.ini
`extension=/usr/local/opt/php71/lib/php/extensions/no-debug-non-zts-20160303/tideways.so`
Idem pour mongodb
`extension=/usr/local/opt/php71/lib/php/extensions/no-debug-non-zts-20160303/mongodb.so`
### Liens:
[:fa-link: PHP (osx)](https://php-osx.liip.ch/) (package PHP)
[Installer Xhprof pour PHP7](Xhprof.md)
[Installer mongodb](mongodb.md)