2024-03-10
Here's how I managed to install Apache, PHP, MySQL and phpMyAdmin on a MacBook Pro 2023 (Apple M2).
From the terminal, enter the following commands:
xcode-select --install
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zshrc
source ~/.zshrc
brew doctor
From the terminal, enter the following commands:
cd /etc
sudo cp hosts hosts_bak
sudo nano hosts
In the /etc/hosts file, add the following local domains:
127.0.0.1 macbp01.local
127.0.0.1 macbp02.local
Save the /etc/hosts file and clear the cache:
sudo dscacheutil -flushcache
From the terminal, enter the following commands:
sudo apachectl stop
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist 2>/dev/null
brew install httpd
brew install php
brew services start httpd
which apachectl
sudo apachectl -k start
php --version
From your browser, enter the following URL to check the proper functioning of Apache:
http://localhost:8080
From the terminal, enter the following commands:
sudo apachectl -k stop
cd /opt/homebrew/etc/httpd
cp httpd.conf httpd_bak.conf
nano httpd.conf
Edit the httpd.conf file as follows.
Search for:
Listen 8080
User _www
Group _www
Replace with:
Listen 80
User myusername
Group staff
Uncomment the following directives:
Include /opt/homebrew/etc/httpd/extra/httpd-vhosts.conf
LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so
Add the following directives at the end of the file:
LoadModule php_module /opt/homebrew/opt/php/lib/httpd/modules/libphp.so
Include /opt/homebrew/etc/httpd/extra/httpd-php.conf
From the terminal, enter the following commands:
cd /opt/homebrew/etc/httpd/extra
nano httpd-php.conf
In the httpd-php.conf file, integrate the following directives:
From the terminal, enter the following commands:
cd /opt/homebrew/etc/httpd/extra
cp httpd-vhosts.conf httpd-vhosts_bak.conf
nano httpd-vhosts.conf
In the httpd-vhosts.conf file, add the following virtual hosts:
If you eventually have to manage a project that takes up a lot of disk space, you could configure a virtual host (macbp02.local) from an external disk.
Start the Apache server:
sudo apachectl -k start
From the browser, enter the following URL addresses to check the proper functioning of Apache and PHP:
http://192.168.50.105
http://macbp01.local
http://macbp02.local
From the terminal, enter the following commands:
brew install mysql
brew services start mysql
mysql --version
Test the correct functioning of MySQL:
mysql -u root
In MySQL, create a new user:
CREATE USER 'myusername'@'localhost' IDENTIFIED BY 'mypassword';
GRANT ALL PRIVILEGES ON *.* TO 'myusername'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
exit
From the terminal, enter the following commands:
brew install phpmyadmin
Create a phpMyAdmin configuration file.
nano /opt/homebrew/etc/httpd/extra/phpmyadmin.conf
In the phpmyadmin.conf file, integrate the following code:
Open the httpd.conf file.
nano /opt/homebrew/etc/httpd/httpd.conf
Add the following directive to the end of the file.
Include /opt/homebrew/etc/httpd/extra/phpmyadmin.conf
Restart the Apache server:
sudo apachectl -k restart
From the browser, enter the following URL address to check the proper functioning of phpMyAdmin:
http://localhost/phpmyadmin/
My technical notes are not tutorials. They are reminders of commands to be executed from a terminal. I do not provide any explanation of the nature of the commands described in my documents. Do not execute them if you don’t understand the meaning of the commands. To avoid losing data or destabilising your workstation, it is preferable to test the commands from a virtual machine, with snapshots.
The names of directories and IP addresses must match the configuration of your workstation and peripherals.