Using your old Macmini as local webserver with
the latest versions of Apache, PHP and MySQL in AMP stack.
Revised on: May 22, 2024
MacPorts does the trick! I had no luck with HomeBrew, that only supports the latest versions of macOS, and not for example macOS High Sierra 10.13.6, the last version that supports my mid 2011 Macmini. Though Apple recommands to give it for free to them for recycling, I felt using it as a local webserver is even better for the environment and saves me the money of buying a new one.
Overview
Let's go through the following steps:
- Updating your Macmini. (optional).
- Installing MacPorts.
- Installation and setup of Apache2.
- Installing and setup of PHP. Ensuring Apache and PHP work nicely together.
- Downloading MySQL from MySQL Community Downloads and setup.
- MySQL setup for PHP to complete the AMP stack.
- Installing phpMyAdmin (optional), it enables you to check the proper working of the AMP stack.
- Installation of WordPress (Optional of course) and some tips to run it properly from a remote host.
Step1 : Updating your Macmini (optional).
To get your old Macmini (or iMac) up to todays speed, I would recommend to replace the old slow HardDisk with an SSD, for example a Samsung SSD 870 EVO 1TB, price € 50. You may skip this step, however if you would like to follow my recommendation, this is how to do it:
- Make a backup of your Macmini with TimeMachine on an external Harddisk.
- Download the macOS version that runs on your Macmini here from Apple support.
- Create a bootable installer for macOS as explained here on Apple support Website.
- Replace your HDD with an SSD as explained here on the iFixit Website. To open your Macmini you need some special screwdrivers. Look around on the internet to find a set that contains the ones you will need.
- Boot from the USB stick with the installer. When arriving at the Utilities Window, select DiskUtility and format your new SSD in APFS format. Next select "Install macOS". Later during the installation you will see the option to use your TimeMachine backup to configure your Macmini to how it was. Connect your external HDD. Select it and move on.
- Enjoy your fast (almost) brand new old Macmini!
Step2 : Installing MacPorts.
In case you had previously installed HomeBrew on your Macmini, just to make sure to uninstall it completely. The same for a previous installation of MASM. This avoids any potential trouble with MacPorts.
Though you don't need to install XCode, it's possible that MacPorts needs Apple's Command Line Developer Tools.
- Open Terminal and type the following line:
xcode-select --install
and hit "Enter". - Next, please note the version of macOS that's installed on your Macmini. In my case it's High Sierra. Visit the MacPorts website: Download MacPorts. Look for the link to download the "pkg" installer for your version of macOS, download it and install it.
Step3 : Installation and setup of Apache2.
Open Terminal and type the following command:
$ sudo port install apache2Activate your Apache installation so that it starts now and every time you boot your machine:
$ sudo port load apache2Open your browser on http://localhost. You should see a page telling you: "It Works!"
The Apache2 configuration file is located here: /opt/local/etc/apache2/httpd.conf.
Each time you edit httpd.conf, run the following commands to check if you didn't make any mistakes and to restart Apache2.
$ /opt/local/sbin/apachectl -t
$ sudo port unload apache2
$ sudo port load apache2
The Apache2 default DocumentRoot is located at /opt/local/www/apache2/html/, which you can only access with administrator rights. Let's change this. Create for example a subdirectory 'Sites' in your Home Directory. Follow the instructions below to make this the new DocumentRoot of Apache :
First, install the httpd-userdir.conf file:
$ sudo cp /opt/local/etc/apache2/extra/httpd-userdir.conf.orig /opt/local/etc/apache2/extra/httpd-userdir.confNext we need to make some changes to httpd.conf, so open it in nano:
$ nano /opt/local/etc/apache2/httpd.confand find the following two lines:
#LoadModule userdir_module lib/apache2/modules/mod_userdir.so
#Include etc/apache2/extra/httpd-userdir.confRemove the "#" at the beginning of each line.
Also we need to change the ServerName. Find ServerName and change it as follows:
ServerName localhost:80Find DocumentRoot and change in the two lines below DocumentRoot
/opt/local/www/apache2/html to /Users/username/SitesThis will make sure you don't need to use sudo commands when editing Apache's DocumentRoot.
Save the httpd.conf file and create a file index.html with content:
Sites is now Apache's DocumentRootUse the three commands mentioned at the top of this Step3 to check if you didn't make any mistakes when editing httpd.conf and restart Apache2. Open your browser and point it to http://localhost/. You should see the content of the index.html file. If not refresh the webpage in your browser.
Step4 : Installing and setup of PHP.
As we speak, PHP82 is the latest version. Let's install that one. Open Terminal and type the following commands:$ sudo port install php82
$ sudo port install apache82-apache2handler
$ sudo port install php82-mysql
$ cd /opt/local/etc/php82
$ sudo cp php.ini-development php.iniIf you need to change lateron the setup of PHP: the php.ini file is located at /opt/local/etc/php82. Next we will enable the php82-apachehandler:
$ cd /opt/local/lib/apache2/modules
$ sudo /opt/local/bin/apxs -a -e -n php mod_php82.soThis should return a message like:
[activating module `php8' in /opt/local/etc/apache2/httpd.conf].
Open the httpd.conf file:
$ sudo nano /opt/local/etc/apache2/httpd.confCheck that in the Dynamic Shared Object (DSO) Support section the following line has been added:
LoadModule php_module lib/apache2/modules/mod_php82.soFind in httpd.conf the block
<IfModule mime_module>and add at the end of it:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phpsSave httpd.conf and restart apache2.
create in the DocumentRoot ~/Sites a new file phpinfo.php with content:
<?php phpinfo(); ?>Open your browser and point it to localhost/phpinfo.php.
You should see a nice webpage in blue that shows PHP8.2 is active.
Step5 : Downloading and Installing MySQL.
Unfortunately installing mysql8-server with MacPorts fails. MacPorts downloads the source file from the mysql website and tries to compile it, which fails already in the configuration stage. Don't worry, a .dmg file is available on that website. There is a catch: you have to find the last version of MySQL that supports your macOS version, and the install paths are different from MacPorts. I wil furtheron show you how to correct for it.Please open your browser on the MySQL Download Website.
It shows the latest version of the MySQL Community Server (8.0.33) and tell you it's compatible with Ventura and Monterey. That's a warning! Installation of this version on an earlier macOS version is no problem. However when you open the MySQL Pane in System Preferences it crashes. Deïnstallation you have to do manually, before you may try another version. Not funny!
So open the Archives tab and look around to find the last version that supports the macOS version on your Macmini. I found the last version that still supports High Sierra on my Macmini is MySQL Community Server 8.0.23. That's what I downloaded and installed, following the installation instructions on the MySQL Installation Website.
If you also want to use phpMyAdmin (see Step7), select "Legacy Password Encryption", because phpMyAdmin does not support (yet?) Strong Encryption.
And enter a strong password for "root".
When done open System Preferences on your Mac and you wil see at the bottom the MySQL symbol. Click it and you get the MySQL Preference Pane that you may use to control your MySQL server.
To make it easier to access MySQL from the commandline, open Terminal and add two aliases:
$ alias mysql=/usr/local/mysql/bin/mysql
$ alias mysqladmin=/usr/local/mysql/bin/mysqladminor even better add /usr/local/mysql/bin to PATH.
Let's check if it works:
$ mysql -u root -pYou will be asked to enter the (MySQL) root password.
$ mysql> exit;If you get in, type exit; to leave the session. If you can't get in, you typed the wrong password.
Step6 : MySQL setup for PHP to complete the AMP stack.
PHP must know where it can find the MySQL default socket. Open Terminal and type the following commands:$ sudo -i
# cd /opt/local/etc/php82
# cp php.ini php.ini.bak
# defSock=$(/usr/local/mysql/bin/mysql_config --socket)
# cat php.ini | sed \
-e "s#pdo_mysql\.default_socket.*#pdo_mysql\.default_socket=${defSock}#" \
-e "s#mysql\.default_socket.*#mysql\.default_socket=${defSock}#" \
-e "s#mysqli\.default_socket.*#mysqli\.default_socket=${defSock}#" > tmp.ini
# grep default_socket tmp.ini # Check it!
# mv tmp.ini php.ini
# exit # OR rm php.ini.bak && exit
The cat command above is a multiline Terminal command: Each line ends with a backslash. Hit Enter after the backslash and you will enter the next line. TIP: Copy the first line cat php.ini | sed \ with Command C and paste it in the Terminal with Command V. Hit Enter and copy and paste the next line, etc...
The grep command should return:
pdo_mysql.default_socket=/tmp/mysql.sock
mysql.default_socket=/tmp/mysql.sock
mysqli.default_socket=/tmp/mysql.sock
All three lines must be shown. If for example mysql.default_socket=/tmp/mysql.sock is missing, open the php.ini file in your editor and add below one of the lines that is present a new line
mysql.default_socket=/tmp/mysql.sock. Repeat the cat command above but only for the missing part.
The grep should show now the three required lines.
To make these changes take effect, restart Apache2:
$ sudo port unload apache2
$ sudo port load apache2
Step7 : Installing phpMyAdmin (optional).
Install the latest version of phpMyAdmin with MacPorts:$ sudo port install phpmyadminConfigure it. You just need to create a new file:
$ cd /opt/local/www/phpmyadmin/
$ sudo cp config.sample.inc.php config.inc.phpCopy phpmyadmin to the Apache DocumentRoot:
$ sudo cp -R /opt/local/www/phpmyadmin/ /Users/username/Sites/phpmyadminphpMyAdmin also needs two missing dependencies. Install them:
$ sudo port install php82-iconv
$ sudo port install php82-mbstring
Open in your browser http://localhost/phpmyadmin, and you should get it's login page. Try to login as root with the MySQL password for root.
If you can't login and you see two pink colored boxes with cryptic error codes in it, make sure you did not make an error with the MySQL password for root. If no error was made, change the encryption for the user root in mySQL to legacy level:
$ mysql -u root -p
$ mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'here your password for root';
$ mysql> exit;Accessing databases in MySQL with phpMyAdmin should work now. If so it proofs, your AMP stack works properly. Well done!
Step8 : How to get WordPress working properly in your AMP stack.
Remove the files index.html and phpinfo.php from Apache's DocumentRoot (~/Sites). Create for WordPress a database and a user for example 'myWordPress' with a strong password:$ mysql -u root -p
$ mysql> create database wordpressdb;
$ mysql> create user myWordPress@localhost IDENTIFIED BY 'strong password';
$ mysql> grant all privileges on wordpressdb.* to myWorPress@localhost;
$ mysql> flush privileges;
$ mysql> exitDownload WordPress and copy it's files into DocumentRoot, and install it.
To enable access from a remote computer to WordPress pages on your local webserver on the Macmini, you have to make the folowing changes:
On your Mac with Wordpress open the WordPress Dasboard and go to Settings -> General. You will see the screen 'General Settings". As an example your Macs IP address might be 192.168.178.100. Make the following changes:
-- WordPress Address(URL) http://localhost -> http://192.168.178.100
-- Site Address(URL) http://localhost . -> http://192.168.178.100
-- Click Save Changes
If you don't know your Macs actual IP address, go to Apple -> System Preferences -> Network to find it.
To make sure published Pages and Posts are shown on your Website, open httpd.conf and find the following line:
#LoadModule rewrite_module /lib/apache2/modules/mod_rewrite.soand remove the # add the beginning of the line. Restart Apache.
Make in php.ini the following changes:
upload_max_filesize = 64M
post_max_size = 64M
memory_limit = 128M