How to set up custom error pages for all domains in Plesk for Linux

Follow

Comments

2 comments

  • Avatar
    Octavio (Edited )

    If followed literally, the instructions for the backup will only work fine (seemingly "fine", at least) the first 2 times. The third time, it will fail. It sounds odd, but it happens. It took me a while to figure out the problem.

    - The first time, it creates an "error_docs_backup" directory which stores the backup, which is the intended result.

    - The second time you run this set of commands, since the "error_docs_backup" directories exist in each domain, the original "error_docs" directories in each domain get wrongly moved by the mv command into "error_docs_backup/error_docs" (instead of just being renamed)

    - The third time you run these commands, since even "error_docs_backup/error_docs" exists as well, you get lots error messages and nothing gets backed up.

    This leads to lots of confusion and wasted time. These instructions should be changed so they work every time they're used.

    My proposal is creating the directories beforehand (with -p so there is no error if they exist) and moving and copying the files instead of the actual directories, "chowning" them afterwards. This change will make this set of commands always provide consistent results.

    Also, you could simplify the two "chown" commands at the end to just the first chown with an additional -R argument, so both the directory and files get "chowned" with just one command. Finally, there is no need to query any database to get the username, as it can be obtained with "stat".

     

    This is my final set of commands:

    mkdir -p /var/www/vhosts/.skel/0/error_docs_backup/

    \cp /var/www/vhosts/.skel/0/error_docs/*.html /var/www/vhosts/.skel/0/error_docs_backup/

    plesk bin subscription -l > subscriptions.txt

    HTTPD_VHOSTS_D=$(cat /etc/psa/psa.conf | grep "HTTPD_VHOSTS_D" | awk '{print $2}')

    while read i; do mkdir -p $HTTPD_VHOSTS_D/$i/error_docs_backup/; chown $(stat -c %U $HTTPD_VHOSTS_D/$i/):psacln $HTTPD_VHOSTS_D/$i/error_docs_backup; mv -f $HTTPD_VHOSTS_D/$i/error_docs/*.html $HTTPD_VHOSTS_D/$i/error_docs_backup/; done < subscriptions.txt

    while read i; do cp $HTTPD_VHOSTS_D/.skel/0/error_docs/*.html $HTTPD_VHOSTS_D/$i/error_docs/; chown -R $(stat -c %U $HTTPD_VHOSTS_D/$i/):psacln $HTTPD_VHOSTS_D/$i/error_docs; done < subscriptions.txt

    This works every time with no inconsistent resuts.

     

    Also, for people who feel that they don't need a backup directory of the error pages every time they modify the "skeleton" error pages, this is the code to do it directly with no backup, which is way simpler:

    plesk bin subscription -l > subscriptions.txt

    HTTPD_VHOSTS_D=$(cat /etc/psa/psa.conf | grep "HTTPD_VHOSTS_D" | awk '{print $2}')

    while read i; do \cp $HTTPD_VHOSTS_D/.skel/0/error_docs/*.html $HTTPD_VHOSTS_D/$i/error_docs; chown -R $(stat -c %U $HTTPD_VHOSTS_D/$i/):psacln $HTTPD_VHOSTS_D/$i/error_docs; done < subscriptions.txt

    Hope this helps.

    1
    Comment actions Permalink
  • Avatar
    Francisco Garcia

    Hi Octavio,

    Thanks for your input as it helped to fix the article with the addition that instead of overwriting error doc files (if they're updated several times) to keep an historic in case of need to save it.

    0
    Comment actions Permalink

Please sign in to leave a comment.

Have more questions? Submit a request