Play sound with PHP on a Raspberry Pi

Configure the sound output interface :

sudo raspi-config
Option 1 System Options
Option S2 Audio

Install the necessary software : Apache HTTPd, PHP 7 and the PHP Apache module :

sudo apt install apache2 php libapache2-mod-php

Allow Apache to access audio devices by adding its user to the audio group :

sudo usermod -a -G audio www-data

in the PHP script, execute the aplay command :

<?php exec('aplay '.DIR.'/sound.wav'); ?>