Home » Php » unix – php.log: what is the proper way to clear log file?

unix – php.log: what is the proper way to clear log file?

Posted by: admin July 12, 2020 Leave a comment

Questions:

I’m troubleshooting a php log file that has expanded way too rapidly and used up a lot of disk space.

What is the best way to clear a log file?

is it a problem to simply delete the log file? And will that log file be recreated as php tries to write to it?

How to&Answers:

It is entirely safe to just delete the php.log file. It will be auto-created the next time it is needed.

Answer:

On Linux you can do :

cat /dev/null > /var/logs/php.log   

Answer:

On Mac OS X 10.6 I deleted /var/log/apache2/error_log. Minor panic when it didn’t re-appear upon refreshing my page. Just had to restart apache by going through the Sharing settings. Now she’s back.

Answer:

It IS safe to delete the log file by doing the following:

  1. Delete the php.log file altogether.
  2. If on Apache Restart the Server using “service apache2 restart” command
  3. If on NGINX you do not have to restart the server

Answer:

You can run this simple command from terminal(in WHM) or From SSH terminal.

find -name error_log -type f -exec rm -rf {} \;

This command will find all files with name “error_log” and remove it.

Enjoy.