How to Restart PHP on Ubuntu

To restart PHP on Ubuntu, you’re likely working with PHP-FPM in conjunction with a web server like Nginx or Apache. Here’s how you can restart PHP depending on the version you’re using:

  1. For PHP 5.x and 7.x using Systemd (Ubuntu 16.04 and newer):
    sudo systemctl restart php7.x-fpm

    Replace 7.x with your PHP version. For example, if you’re using PHP 7.4, you would use:

    sudo systemctl restart php7.4-fpm
  2. For PHP 8.x:

    Replace the 7.x in the command above with 8.x:

    sudo systemctl restart php8.x-fpm

    For instance, for PHP 8.0:

    sudo systemctl restart php8.0-fpm
  3. For older versions using Upstart (Ubuntu 14.04 and older):
    sudo service php5-fpm restart

    If you’re using PHP 7.x:

    sudo service php7.x-fpm restart

    Again, replace 7.x with your PHP version.

  4. If you’re using Apache with libapache2-mod-php:

    In this scenario, PHP runs as an Apache module, so you’d need to restart the Apache service:

    sudo systemctl restart apache2

    Or for older versions:

    sudo service apache2 restart
  5. Check the Status:

    It’s also a good practice to check the status after restarting:

    sudo systemctl status php7.x-fpm

    Replace 7.x with your PHP version.

  6. Check for Active PHP Versions:

    If you’re unsure which version of PHP-FPM you’re running, you can check with:

    systemctl list-units --type=service | grep php

    This will list any PHP-related services that are currently managed by Systemd.

Remember, after making changes to PHP configurations, you should always restart the PHP service for those changes to take effect.

Leave a Reply

Your email address will not be published. Required fields are marked *