# d # Installer Apache (homebrew) ### Installation: ```bash $ sudo apachectl stop $ sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist 2>/dev/null $ brew install httpd $ sudo brew services start httpd ``` ### Arrêter / redémarrer Apache ```bash $ sudo apachectl start $ sudo apachectl stop $ sudo apachectl -k restart $ sudo apachectl -k restart -e Debug -E /dev/stdout ``` ### Log: ```bash $ tail -f /usr/local/var/log/httpd/error_log ``` ```bash $ multitail -s 2 /usr/local/var/log/httpd/error_log /usr/local/var/log/httpd/access_log ``` ### Version: ```bash $ httpd -v ``` ### Configuration: Ouvrir le fichier *httpd.conf*: ```bash $ open -e /usr/local/etc/httpd/httpd.conf $ bbedit /usr/local/etc/httpd/extra/httpd-vhosts.conf ``` ### Virtual Hosts: #### Redirection: Editer le fichier *hosts*: ```bash $ sudo nano /etc/hosts 127.0.0.1 silverbook.local 127.0.0.1 wordpress.silverbook.local 127.0.0.1 dev.silverbook.local 127.0.0.1 zenphoto.silverbook.local 127.0.0.1 phpmyadmin.silverbook.local ``` Editer le fichier *httpd-vhosts.conf*: ```http DocumentRoot /Users/bruno/Sites/wordpress ServerName wordpress.silverbook.local CustomLog /usr/local/var/log/httpd/wordpress-access.log combined ErrorLog /usr/local/var/log/httpd/wordpress-error.log ``` #### 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`: ```bash 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 silverbook.local 127.0.0.1 wiki.silverbook.local ``` Editer le fichier *httpd-vhosts.conf*: ```http ServerName wiki.silverbook.local ProxyPass / http://localhost:3000/ ProxyPassReverse / http://localhost:3000/ ProxyPreserveHost On ``` ### SSL: Ouvrir le fichier *httpd.conf* et dé-commenter les lignes suivantes: ```http LoadModule socache_shmcb_module lib/httpd/modules/mod_socache_shmcb.so ... LoadModule ssl_module lib/httpd/modules/mod_ssl.so ... Include /usr/local/etc/httpd/extra/httpd-ssl.conf ``` Ouvrir le fichier *httpd-ssl.conf*: Remplacer le port 8443 par défaut par le port 443 et commenter 2 lignes. ```http Listen 443 ... \# General setup for the virtual host \# DocumentRoot "/usr/local/var/www" \# ServerName www.example.com:443 ``` Ouvrir le fichier *httpd-vhosts.conf*: Rajouter ce bloc pour chaque Virtual Host. ```http DocumentRoot "/Users/bruno/Sites" ServerName silverbook.local SSLEngine on SSLCertificateFile "/usr/local/etc/httpd/server.crt" SSLCertificateKeyFile "/usr/local/etc/httpd/server.key" ``` ### Générer un certificat auto-signé: Générer la clé et le certificat (*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 ``` ### 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 ``` ### Voir si Apache tourne: ```bash $ ps -aef | grep httpd 0 23417 1 0 2:48PM ?? 0:00.06 /usr/local/opt/httpd24/bin/httpd -D FOREGROUND ``` ### M-à-J: directement depuis Homebrew ### 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 Options Indexes FollowSymLinks MultiViews AllowOverride All Require all granted Order allow,deny Allow from all ``` ### Message d’erreur 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:*** ``` /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:*** ``` /usr/local/opt/httpd/bin/httpd /Library/LaunchDaemons/homebrew.mxcl.httpd.plist /usr/local/var/www/index.html -> /Users/bruno/Sites /usr/local/etc/httpd/httpd.conf /usr/local/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: `` `` `` Puis arrêter et redémarrer Apache: ```bash $ sudo apachectl stop $ sudo apachectl start ``` ### Nouvelle version de Python: Apache ne fonctionne plus. Regarder error_log: `Fatal Python error: Py_Initialize: unable to load the file system codec` `ModuleNotFoundError: No module named 'encodings'` Dans `https.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 mod_wsgi avec pip. ```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 ``` ### Liens: [:fa-link: https://getgrav.org/blog/macos-sierra-apache-multiple-php-versions](https://getgrav.org/blog/macos-sierra-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/)