Apache, MySQL & PHP on macOS Catalina

Apple macOS 10.15 ships with both a recent version of Apache (2.4.x), as well as PHP (7.3.x), so you’ll just have to install MySQL and go through a few steps to get everything up and running.

Apache

First, you have to create a web root in your user account:

mkdir ~/Sites

Then add a configuration for your user:

sudo tee /etc/apache2/users/$USER.conf <<EOF
<Directory "$HOME/Sites/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>
EOF

Now we have to make sure that our user config above actually gets loaded:

sudo tee -a /etc/apache2/other/$USER-settings.conf <<EOF
Include /private/etc/apache2/users/*.conf
EOF

If you want to use vhosts, you’ll also have to make sure that the vhosts config gets loaded:

sudo tee -a /etc/apache2/other/$USER-settings.conf <<EOF
Include /private/etc/apache2/extra/httpd-vhosts.conf
EOF

After that, configure vhosts as necessary in /etc/apache2/extra/httpd-vhosts.conf (don’t forget to remove the examples in there).

It seems that mod_rewrite no longer gets loaded by default, so we’ll also add that to our config:

sudo tee -a /etc/apache2/other/$USER-settings.conf <<EOF
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
EOF

PHP

PHP doesn’t get loaded by default. So we’ll also add it to our config:

sudo tee -a /etc/apache2/other/$USER-settings.conf <<EOF
LoadModule php7_module libexec/apache2/libphp7.so
EOF

You should also configure a few settings in /etc/php.ini:

sudo tee -a /etc/php.ini <<EOF
date.timezone = "`sudo systemsetup -gettimezone | awk '{print $3}'`"
display_errors = on
error_reporting = -1
EOF

To activate these settings you have to restart Apache:

sudo apachectl restart

If you also need PEAR/PECL, follow these instructions.

MySQL

MySQL is not shipped with macOS, so we’ll have to install that manually. Instead of going for an installer package, we’ll use Homebrew. Once Homebrew is installed, installing MySQL is as simple as:

brew install mysql

If you want to start MySQL automatically, run:

brew services start mysql

Any comments? Ping me on Twitter. 👉🏻 Get my newsletter for occasional updates. ✌🏻

PEAR on macOS 10.15 Catalina

macOS no longer ships with PEAR, but installing it is quite easy. Once that’s done PEAR and PECL work as expected (if you also want to set up and install Apache, PHP and MySQL, check this post).


Installing PEAR

cd /tmp
curl -s -O https://pear.php.net/install-pear-nozlib.phar
sudo php install-pear-nozlib.phar -d /usr/local/lib/php -b /usr/local/bin

If that fails

autoconf may be missing. To install it just use Homebrew. Once Homebrew is installed, installing autoconf is as simple as:

brew install autoconf

After autoconf is installed, try running the pear installer above again.

Upgrade PEAR

sudo pear channel-update pear.php.net
sudo pecl channel-update pecl.php.net
sudo pear upgrade-all --ignore-errors

Xcode Command Line Developer Tools

You will run into problems installing pecl extensions, if you don’t have the Xcode Command Line Extensions installed, so we’ll also install them.

xcode-select --install

Configuring PHP

Open /etc/php.ini and add .:/usr/local/lib/php/pear to include_path (if /etc/php.ini does not exist, create it with the following content).

include_path = ".:/usr/local/lib/php/pear"

Any comments? Ping me on Twitter. 👉🏻 Get my newsletter for occasional updates. ✌🏻

Cleaning up old data in Ansible Tower

Older Ansible Tower versions don’t have cleanup tasks scheduled by default, which may lead to a very slow or even unusable Tower instance with lots of historic data. At that point it may not even be possible to schedule cleanup task and even if they are set up with lots of patience they may be so slow that they timeout. Luckily there’s a command line tool called awx-manage, but in my case even that failed as the cleanup tasks also timed out.

At that point the only remedy is to manually delete data in Tower. I managed to unstuck a Ansible Tower 2.1.4 instance as follows:

Run the Tower shell via awx-manage (ideally in a screen session, this may take a while):

sudo awx-manage shell_plus

Paste the following code into the shell to cleanup objects in the database:

from awx.main.models import Job
for record_id in range(1, 200000):
    try:
        db_object = Job.objects.get(id=record_id)
        db_object.delete()
    except:
        pass

This iterates through all Job objects up to record_id=200000 and deletes them. You may have a lot less or a lot more objects in your Tower database, so you might have to adjust the 200000 to something else. I also had to delete the UnifiedJob objects, so you also might have to run this:

from awx.main.models import UnifiedJob
for record_id in range(1, 200000):
    try:
        db_object = UnifiedJob.objects.get(id=record_id)
        db_object.delete()
    except:
        pass

This took several hours in my case, your mileage may vary. After this manual deletion went through the following awx-manage cleanup commands started working again for me:

sudo awx-manage cleanup_deleted --days=0
sudo awx-manage cleanup_jobs --days=0
sudo awx-manage cleanup_activitystream --days=0

Finally I restarted Ansible Tower and the webinterface was reasonably fast again. Hope it works for you, too!


Any comments? Ping me on Twitter. 👉🏻 Get my newsletter for occasional updates. ✌🏻

Apache, MySQL & PHP on macOS Mojave

Apple macOS 10.14 ships with both a recent version of Apache (2.4.x), as well as PHP (7.1.x), so you’ll just have to install MySQL and go through a few steps to get everything up and running.

Apache

First, you have to create a web root in your user account:

mkdir ~/Sites

Then add a configuration for your user:

sudo tee /etc/apache2/users/$USER.conf <<EOF
<Directory "$HOME/Sites/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>
EOF

Now we have to make sure that our user config above actually gets loaded:

sudo tee -a /etc/apache2/other/$USER-settings.conf <<EOF
Include /private/etc/apache2/users/*.conf
EOF

If you want to use vhosts, you’ll also have to make sure that the vhosts config gets loaded:

sudo tee -a /etc/apache2/other/$USER-settings.conf <<EOF
Include /private/etc/apache2/extra/httpd-vhosts.conf
EOF

After that, configure vhosts as necessary in /etc/apache2/extra/httpd-vhosts.conf (don’t forget to remove the examples in there).

It seems that mod_rewrite no longer gets loaded by default, so we’ll also add that to our config:

sudo tee -a /etc/apache2/other/$USER-settings.conf <<EOF
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
EOF

PHP

PHP doesn’t get loaded by default. So we’ll also add it to our config:

sudo tee -a /etc/apache2/other/$USER-settings.conf <<EOF
LoadModule php7_module libexec/apache2/libphp7.so
EOF

You should also configure a few settings in /etc/php.ini:

sudo tee -a /etc/php.ini <<EOF
date.timezone = "`sudo systemsetup -gettimezone | awk '{print $3}'`"
display_errors = on
error_reporting = -1
EOF

To activate these settings you have to restart Apache:

sudo apachectl restart

If you also need PEAR/PECL, follow these instructions.

MySQL

MySQL is not shipped with macOS, so we’ll have to install that manually. Instead of going for an installer package, we’ll use Homebrew. Once Homebrew is installed, installing MySQL is as simple as:

brew install mysql

If you want to start MySQL automatically, run:

brew services start mysql

Any comments? Ping me on Twitter. 👉🏻 Get my newsletter for occasional updates. ✌🏻

PEAR on macOS 10.14 Mojave

macOS no longer ships with PEAR, but installing it is quite easy. Once that’s done PEAR and PECL work as expected (if you also want to set up and install Apache, PHP and MySQL, check this post).


Installing PEAR

cd /tmp
curl -s -O https://pear.php.net/install-pear-nozlib.phar
sudo php install-pear-nozlib.phar -d /usr/local/lib/php -b /usr/local/bin

If that fails

autoconf may be missing. To install it just use Homebrew. Once Homebrew is installed, installing autoconf is as simple as:

brew install autoconf

After autoconf is installed, try running the pear installer above again.

Upgrade PEAR

sudo pear channel-update pear.php.net
sudo pecl channel-update pecl.php.net
sudo pear upgrade-all --ignore-errors

Xcode Command Line Developer Tools

You will run into problems installing pecl extensions, if you don’t have the Xcode Command Line Extensions installed, so we’ll also install them.

xcode-select --install

Configuring PHP

Open /etc/php.ini and add .:/usr/local/lib/php/pear to include_path (if /etc/php.ini does not exist, create it with the following content).

include_path = ".:/usr/local/lib/php/pear"

Any comments? Ping me on Twitter. 👉🏻 Get my newsletter for occasional updates. ✌🏻