How can Apache be restarted effectively after updating PHP to ensure the changes take effect?

After updating PHP, Apache needs to be restarted to ensure the changes take effect. This can be done by using the command line to restart the Apache service.

<?php
// Execute the command to restart Apache
exec('sudo service apache2 restart');
?>