How to install Logrotate for Magento 2 on CPanel Server

 Today we are going through a how-to article on installing the Logrorate for your Magento 2 install which is very useful for you to optimize your Magento performance and overall storage of your server. So going through in detail this article we wish to explain to you the process of installing the log rotate utility in your Cpanel Server.



Things you need for doing this install

A CPanel Server

Root Access

Terminal Software, We use Putty


Steps to install Logrotate for Magento 2 in CPanel Server

1. log in to your Cpanel Server via Putty with root privilege, assuming you know this

2. After this use this command on the terminal 

cd /etc/logrotate.d/

3. Then let's create the conf file for that you use the popular terminal code editor nano, 

 nano magento2.conf

4. Now use the below code for your file.  As you can see the code start with /home/username/ you have to replace the username with your Cpanel username and we assume that you installed the magento2 on the root of the Cpanel directory else find your var/log file location and update the below file accordingly. 

/home/usename/public_html/var/log/*.log {

su root root

    # Rotate daily

    daily

    # Rotate when the size is bigger than 200MB

    size 200M

    # Compress old log files

    compress

    # Always keep 4 days of log files

    rotate 4

    # Create a new log file with mode 0600

    create 0600

    # Don't rotate file if not found

    missingok

    # Don't rotate the log if the file is empty

    notifempty

}

5. Save this with command 

cntrl+O and hit Return ( enter)

6. Now You have to set the cronjob for the file to run, for that you have to edit the crontab file, you can use the below code to edit the crontab file, and we are configuring the crontab file to run the above code every 15 days, the above code will check the log files above 200MB 

7. Now create a crontab using the command line 

crontab -e

And click insert on the keyboard and paste the below as your cronjob

* * */15 * * /usr/sbin/logrotate -v /etc/logrotate.d/magento2.conf --state /etc/logrotate.d/.logrot_state >/dev/null 2>&1


and save it by entering:wq

You had successfully completed the corn job,  You can give a test if that works fine by running the below code,


/usr/sbin/logrotate -v /etc/logrotate.d/magento2.conf --state /etc/logrotate.d/.logrot_state ; echo $?



Remember: Take backups before doing any change. And we are sharing our knowledge on this topic, but we don't take any responsibility this may cause to your server anyway, We advise you to check as per your way before applying any change to the server. 


Post a Comment (0)
Previous Post Next Post