Restart php cli ubuntu

How to Restart PHP-FPM Service and Reload Config

To restart the PHP-FPM service and reload the configuration file, firstly check which version of PHP you are running:

.15-1+ubuntu18.04.1+deb.sury.org+1 (cli) (built: Feb 8 2019 15:38:01) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.15-1+ubuntu18.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies 

Above we can see we are running PHP v7.2, therefore the service name should be php7.2-fpm .

To restart the PHP-FPM service, run;

Читайте также:  Byte input python 3

Let me know if this helped. Follow me on Twitter, Facebook and YouTube, or 🍊 buy me a smoothie.

p.s. I increased my AdSense revenue by 200% using AI 🤖. Read my Ezoic review to find out how.

4 replies

Leave a reply Cancel reply

This command is not working here :

[email protected]:/etc/php/7.0/apache2# service php7.0-fpm restart
Failed to restart php7.0-fpm.service: Unit php7.0-fpm.service not found.

[email protected]:/etc/php/7.0/apache2# php -v
PHP 7.0.32-0ubuntu0.16.04.1 (cli) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.32-0ubuntu0.16.04.1, Copyright (c) 1999-2017, by Zend Technologies

Are you running PHP-FPM? Is there an FPM folder in /etc/php/7.0/ ?

sudo apt-get install php-fpm libapache2-mod-php php-mysql php-curl php-xml
Reading package lists… Done
Building dependency tree
Reading state information… Done
libapache2-mod-php is already the newest version (1:7.0+49).
php-curl is already the newest version (1:7.0+49).
php-fpm is already the newest version (1:7.0+49).
php-mysql is already the newest version (1:7.0+49).
php-xml is already the newest version (1:7.0+49).
0 upgraded, 0 newly installed, 0 to remove and 376 not upgraded.
Failed to restart php7.2-fpm.service: Unit php7.2-fpm.service not found.
pluto199: cd /etc
pluto200: cd php
pluto201: ls
7.0/
php -v
PHP 7.0.33-0+deb9u10 (cli) (built: Oct 6 2020 17:08:28) ( NTS )
Yes indeed, this is the correct php version.

What am I doing wrong? I must be doing something dumb.

Источник

How to Restart PHP in Linux / Unix

If you are a relatively new Linux user and you manage a server with PHP, it is important that you know that after editing the php.ini file , you must restart the PHP service.

PHp is associated with your web server or with your external FastCGI process manager. In most cases, after editing the php.ini file , you only need to restart your server, which is probably Apache, Nginx or Lighttpd, depending on what you have installed on your operating system. In this way you can apply the new saved configuration .

We will see how to restart PHP, for which, you must restart your web server. Depending on your web server, you must execute one of the following commands:

Restart Apache to restart PHP

If you use Apache, type the following command:

Or also, with the service command:

If you use CentOS, the server will have the name of httpd instead of Apache2:

Restart Nginx to restart PHP

If you use the Nginx web server, type the following command to restart it:

You can also use the service command:

Restart Lighttpd to restart PHP

If you use the Lighttpd web server, type the following command to restart it:

Restart PHP-FAM FastCGI to restart PHP

If you use PHP from the PHP-FAM fastcgi manager , use one of the following commands. Depending on your version of Linux, it may be one or the other:

For PHP5 you can also run:

And finally you can also try:

Donations/Tips for Technibuzz.com
Do you find my tutorials useful? Please consider supporting my website. It is hard to keep the site running when so many people block ads. Donating money to Technibuzz is easy!

The tutorials here on Technibuzz.com are provided free of charge. If you wish to make a small contribution, you can choose one of the following options:

  1. BTC (Bitcoin) Address: 1BfQdqBs4sVBUijX4m8jTri51ET2w1FmrH
  2. ETH (Ethereum) Address: 0x498e0bf35d20b1ed80dbe9cd7437808adc5e603f
  3. XMR (Monero) Address:
    87MX19uzcEjgbzsBqU1dEpBnHd86TthwuMEQMZ17E3wN71VZf4qDYPi7GVTEMMeJtyira9cUZvUkLDMwTeNaxEsLLrPj8Jg
  4. Paypal: cybersecurity@technibuzz.com

Share this:

Источник

Php linux restart php cli service code example

=) Solution 3: Assuming: Call the same script file x number of times Re-call if it gets interrupted/ended/stopped Automated process for infinite loop Some options come to mind to achieve your goal [Unix/Linux based solutions]: Use a BASH script, so that the PHP script after stopped/ended/interrupted can be resumed: The Fat Controller execution handler, this are the key features you’re looking for: Used to repeatedly run other programs Can run many instances of any script/program in parallel any script can be rerun once it finishes executing very similar to CRON but this key features are just what you need Using a CRON, you can have it call your PHP script at intervals of e.g., one minute , then with this code at the very beggining of you PHP script, you will be able to control the number of threads running, exiting if 8 are already running: search for processes running with the same path of the current file, and returns the number of processes found. To launch a separate process change the restartMyself function to: This can certainly be an adventure, chasing processes that restart immune to your kill if you manage to catch them in process.

Restart php in linux

php restart

systemctl restart php-fpm.service

restart php windows

Win + R type:iisreset Or, more verbose: iisreset inside a powershell opened as administrator - or even inside a Cygwin shell.

Restart php linux Code Example, service php-fpm restart # typical service php5-fpm restart # debian-style service php7.0-fpm restart # debian-style PHP 7 service php7.2-fpm restart # debian-style PHP 7.2 service php7.4-fpm restart # debian-style PHP 7

Automatically Restart PHP Script on Exit

A PHP Script can also restart itself with PCNTL.

Disclaimer: the point of this exercise is only to prove that PHP is perfectly capable of restarting itself and to answer the question:

Is there a way I can automatically restart a PHP script whenever it exits, regardless of whether it has been exited properly, or has terminated due to an error?

It is therefor beyond our scope to go into any detail about unix processes so I would suggest you start with the PCNTL book or refer to php-pcntl for more details.

In the examples we will assume it is a PHP CLI script launched in a *nix environment from a terminal with a semi-decent shell using the command:

$ php i-can-restart-myself.php 0 

We pass a restart count attribute as indicator that the process was restarted.

Can I automatically restart a PHP Script?

Yes I can!

 echo "\n========== end =========\n"; // restart myself pcntl_exec($_, $argv); 

Regardless of whether it has been terminated properly?

Yes I can restart if terminated!

); echo "\n======== start =========\n"; // do a lot of stuff $cnt = 0; while( $cnt++ < 10000000 )<>echo "\n========== end =========\n"; die; // exited properly // we can't reach here pcntl_exec($_, $argv); 

Or terminated due to an error?

Ditto!

); echo "\n======== start =========\n"; // do a lot of stuff $cnt = 0; while( $cnt++ < 10000000 )<>echo "\n===== what if? =========\n"; require 'OOPS! I dont exist.'; // FATAL Error: // we can't reach here echo "\n========== end =========\n"; die; // exited properly // we can't reach here pcntl_exec($_, $argv); 

But you know I am going to want more than that right?

Certainly! I can restart on kill, hub even Ctrl-C!

; register_shutdown_function($restartMyself); pcntl_signal(SIGTERM, $restartMyself); // kill pcntl_signal(SIGHUP, $restartMyself); // kill -s HUP or kill -1 pcntl_signal(SIGINT, $restartMyself); // Ctrl-C echo "\n======== start =========\n"; // do a lot of stuff $cnt = 0; while( $cnt++ < 10000000 )<>echo "\n===== what if? =========\n"; require 'OOPS! I dont exist.'; // FATAL Error: // we can't reach here echo "\n========== end =========\n"; die; // exited properly // we can't reach here pcntl_exec($_, $argv); 

How do I terminate it now?

If you flood the process by holding down Ctrl-C you might just catch it somewhere in the shutdown.

I don’t want to see all these errors can I restart on those too?

No problem I can handle errors too!

; register_shutdown_function($restartMyself); pcntl_signal(SIGTERM, $restartMyself); pcntl_signal(SIGHUP, $restartMyself); pcntl_signal(SIGINT, $restartMyself); set_error_handler($restartMyself , E_ALL); // Catch all errors echo "\n======== start =========\n"; // do a lot of stuff $cnt = 0; while( $cnt++ < 10000000 )<>echo $CAREFUL_NOW; // NOTICE: will also be caught // we would normally still go here echo "\n===== what if? =========\n"; require 'OOPS! I dont exist.'; // FATAL Error: // we can't reach here echo "\n========== end =========\n"; die; // exited properly // we can't reach here pcntl_exec($_, $argv); 

Although this appears to be working fine at first glance, because pcntl_exec runs in the same process we do not notice that things are terribly wrong. If you wanted to spawn a new process and letting the old one die instead, which is a perfectly viable alternative see next post, you will notice 2 processes are started each iteration, because we trigger a PHP NOTICE and an ERROR due to a common oversight. Which of course can easily be rectified by ensuring we die() or exit() after the call to pcntl_exec in the error handler, otherwise PHP assumes tolerance were accepted and continues.

The point I am trying to make is that even if you are able to relaunch a script that failed this is not an excuse to allow broken code. Although there may exist viable use cases for this practice, I strongly disagree that restart on failure should be employed as a solution for scripts failing due to errors! As we can see from these examples there is no way of knowing exactly where it failed so we cant be sure where it will start from again. Going for the «quick fix» solution which could appear to be working fine may have more problems now then before.

I would instead prefer to see the defect addressed with some proper unit tests which will help flush out the culprit so we may rectify the problem. If PHP runs out of memory it can be avoided through conservative use of resources by unsetting the variables after use. (btw. you will find assigning null is much quicker than using unset for the same result) I am afraid though, if left unresolved, restarting would most definitely serve as suitable opener to the can of worms you already have.

Here be dragons.

Advanced usage and not for the faint of heart.

To launch a separate process change the restartMyself function to:

This can certainly be an adventure, chasing processes that restart immune to your kill if you manage to catch them in process. =)

Ensure that the script has enough to do so you may have enough time to kill it.

to insist the undead stay dead. This is no idle reference as you would be wise to consider zombies and orphans but ultimately even the toughest processes usually still need a parent so killing the shell session should see them to rest.

All standard disclaimers apply, good luck! =)

  • Call the same script file x number of times
  • Re-call if it gets interrupted/ended/stopped
  • Automated process for infinite loop

Some options come to mind to achieve your goal [Unix/Linux based solutions]:

    Use a BASH script, so that the PHP script after stopped/ended/interrupted can be resumed:

#!/bin/bash clear date php -f my_php_file.php sleep 100 # rerun myself exec $0 
  • Used to repeatedly run other programs
  • Can run many instances of any script/program in parallel
  • any script can be rerun once it finishes executing

very similar to CRON but this key features are just what you need

exec('ps -A | grep ' . escapeshellarg(basename(__FILE__)) , $results); if (count($results) > 7)

Restart php 8 ubuntu Code Example, service php-fpm restart # typical service php5-fpm restart # debian-style service php7.0-fpm restart # debian-style PHP 7 service php7.2-fpm restart # debian-style PHP 7.2 service php7.4-fpm restart # debian-style PHP 7

Run php from command line with short tags

The INI tag can be set directly from the CLI:

In ubuntu/debian you have to change

And you no need to restart any service after this, just use your console php.

Restart php 7.4 ubuntu Code Example, service php-fpm restart # typical 2 service php5-fpm restart # debian-style 3 service php7.0-fpm restart # debian-style PHP 7 4 service php7.2-fpm restart # debian-style PHP 7.2 5 service php7.4-fpm restart # debian-style PHP 7.4 6 Source: serverfault.com ubuntu restart php shell by …

Fix kali linux asking to restart services

fix kali linux asking to restart services

apt-get install debconf-utils debconf-get-selections > answers.conf

Источник

Оцените статью