Kristian
Kristian

Reputation: 21840

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

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?

Upvotes: 8

Views: 23839

Answers (5)

Dharmesh Patel
Dharmesh Patel

Reputation: 129

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.

Upvotes: 0

JoshuaEvan
JoshuaEvan

Reputation: 66

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

Upvotes: 0

Ryan Shirley
Ryan Shirley

Reputation: 339

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.

Upvotes: 3

Giorgi Bigvava
Giorgi Bigvava

Reputation: 71

On Linux you can do :

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

Upvotes: 7

Travis Weston
Travis Weston

Reputation: 924

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

Upvotes: 19

Related Questions