Table des matières

Installer Apache et PHP7 sur macOS Mojave

Installation avec Brew.

Installer Apache

Arrêter le Apache natif de macOS:

sudo apachectl stop

Installer Apache avec Homebrew:

brew install httpd

Lancer le service Apache:

brew services start https

En allant sur http://localhost:8080, il devrait s'afficher le classique It works !.

Configurer Apache

Modifier le fichier /usr/local/etc/httpd/httpd.conf:

Redémarrer Apache:

sudo apachectl restart

Tout devrait fonctionner en allant sur http://localhost.

Installer PHP

brew install php@7.2

Dans le fichier /usr/local/etc/httpd/httpd.conf, ajouter le module PHP7, à la fin de la liste des modules:

LoadModule php7_module /usr/local/opt/php@7.2/lib/httpd/modules/libphp7.so

Dans ce même fichier, 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>

Démarrer le service PHP:

brew services start php@7.2

Redémarrer Apache:

sudo apachectl restart

Tout devrait fonctionner en allant sur une page PHP.

Avoir la bonne version de PHP en ligne de commande

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