• Hi,
    i try to make some changes on iThemes Security but it says “.htaccess cannot be written”.
    “Allow iThemes Security to write on wp-config.php et .htaccess” is checked.
    .htaccess rights are 644.
    Any idea ?

    thanks 🙂

    • This topic was modified 5 years, 5 months ago by gregmurf.
    • This topic was modified 5 years, 5 months ago by gregmurf.
Viewing 15 replies - 1 through 15 (of 37 total)
  • Probably best to enable the Show Error Codes setting in the Global Settings module (Scroll down all the way to the bottom to find the setting).

    Then reproduce the error and share all the error info displayed on your screen.

    To prevent any confusion, I’m not iThemes.

    Thread Starter gregmurf

    (@gregmurf)

    Thanks. Here is the full error:
    /var/www/html/wordpress/.htaccess n’a pas pu être écrit. C’est peut être dû à un problème de permissions. Assurez-vous que PHP est lancé avec les permissions utilisateurs nécessaires pour écrire à cet emplacement. (itsec-lib-file-write-file-put-contents-failed)

    Ok, so the full error translated in English is:

    /var/www/html/wordpress/.htaccess could not be written. This could be due to a permissions issue. Ensure that PHP runs as a user that has permission to write to this location.(itsec-lib-file-write-file-put-contents-failed)

    You will have to contact your hosting provider and let them check that the user running the PHP process has write permission to your /var/www/html/wordpress/.htaccess file.

    Thread Starter gregmurf

    (@gregmurf)

    I host my linux server on OVH. Everything else is made by myself.
    www-data is the wordpress folder owner.
    If i put “echo(exec(“whoami”));die();” on index.php, www-data is shown as user running.
    .htaccess is 644.

    • This reply was modified 5 years, 5 months ago by gregmurf.

    Ok, I see. You may need to debug the iTSec plugin script responsible for generating the error. It’s the write method in the wp-content/plugins/better-wp-security/core/lib/class-itsec-lib-file.php file.

    The write method is called like this:

    return ITSEC_Lib_File::write( $file, $contents );

    Return values are boolean or WP_Error. Boolean true on success, WP_Error object otherwise.

    Thread Starter gregmurf

    (@gregmurf)

    I put the write method on the class-itsec-lib-file.php file and now it returns:
    (itsec-settings-page-server-error-ajax-response: error "Internal Server Error")

    Ah, ok. My apologies. I should explain better.

    Whatever change(s) you made, undo it first. Then follow the steps below:

    In the better-wp-security/core/lib folder create a backup copy of the original class-itsec-lib-file.php file. Name it class-itsec-lib-file.php.old
    We are making this copy to be able to quickly restore the default setup after we are done debugging.

    Then create a new file (itsec-write-test.php) in the WordPress wp-admin folder and enter the following content in the file:

    <?php
    
    /** WordPress Administration Bootstrap */
    require_once __DIR__ . '/admin.php';
    
    /** Only users with manage options capability allowed */
    if ( ! current_user_can( 'manage_options' ) ) {
    	wp_die( __( 'Sorry, you are not allowed to manage options on this site.' ) );
    }
    
    /** Write to a new test file */
    $result = ITSEC_Lib_File::write( '/var/www/html/wordpress/test1.txt', "This is a test.\n" );
    
    /** Check and show the result */
    if ( is_wp_error( $result ) ) {
    	 echo 'Error msg: ' . $result::get_error_message();
    } else {
    	 echo 'File writing ' . ( $result?'succeeded.':'failed.' );
    }

    Next (from the browser) you should log into the WordPress Dashboard as usual. Then open a second tab in the browser and enter the address to the itsec-write-test.php file:

    http://www.domain.fr/wp-admin/itsec-write-test.php

    Where http://www.domain.fr should be substituted with your domain name. (If using SSL use https instead of http).

    At this point, let me know the first and second result (simply refresh the second tab in the browser for the second result).

    We will continue debugging after these results are known.

    • This reply was modified 5 years, 5 months ago by nlpro.
    Thread Starter gregmurf

    (@gregmurf)

    Done (you missed ?> at the end of code) 🙂
    Result => File writing succeeded.

    Ok, great.

    The test script is based upon the wp-admin/index.php file. There is no php end tag included in that file so I saw no reason to add it to our test script 😉 Also most WordPress php files do not include the php end tag. It’s not a fatal error …

    Anyway, we have a positive result when writing to a NEW file in the same folder where the .htaccess file exists. Did the second write test also return a positive result ? (Oh, to keeps things tidy you can delete the newly created test1.txt file).

    Before starting debugging we need to make sure we can reproduce the issue when using the test script. So next we will try to write to the existing .htaccess file.

    IMPORTANT: First create a backup copy of the .htaccess file !!

    Then change the test script (itsec-write-test.php) and simply change the filename “test1.txt” into “.htaccess”

    Now run the test script again. If the issue reproduces it should return:

    Error msg: /var/www/html/wordpress/.htaccess could not be written. This could be due to a permissions issue. Ensure that PHP runs as a user that has permission to write to this location.

    If the issue does not reproduce, check the content of the .htaccess file. If the content is overwritten RESTORE the .htaccess file from the backup file we created earlier!

    • This reply was modified 5 years, 5 months ago by nlpro.
    Thread Starter gregmurf

    (@gregmurf)

    i delete test1.txt. But i dont understand how to perform the “second write test” ?
    Do you mean this: “Then change the test script (itsec-write-test.php) and simply change the filename “test1.txt” into “.htaccess”
    Now run the test script again.” ?

    • This reply was modified 5 years, 5 months ago by gregmurf.
    Thread Starter gregmurf

    (@gregmurf)

    Done: change the itsec-write-test.php to

    /** Write to a new test file */
    $result = ITSEC_Lib_File::write( '/var/www/html/wordpress/.htaccess', "This is a .htaccess test.\n" );

    And i have this error:

    une erreur critique est survenue sur votre site. Veuillez consulter la boite de réception de l’e-mail d’administration de votre site pour plus d’informations.
    En apprendre plus sur le débogage de WordPress.

    .htaccess is not modified and WP is up.

    I use Wordfence. It’s not a problem ?

    • This reply was modified 5 years, 5 months ago by gregmurf.
    • This reply was modified 5 years, 5 months ago by gregmurf.

    Using Wordfence should not be a problem.

    I think adding .htaccess twice may be the problem.

    So change the write line to look like this:

    $result = ITSEC_Lib_File::write( '/var/www/html/wordpress/.htaccess', "This is a test.\n" );

    Then retry.

    Thread Starter gregmurf

    (@gregmurf)

    Same error.
    itsec-write-test.php content:

    <?php
    
    /** WordPress Administration Bootstrap */
    require_once __DIR__ . '/admin.php';
    
    /** Only users with manage options capability allowed */
    if ( ! current_user_can( 'manage_options' ) ) {
            wp_die( __( 'Sorry, you are not allowed to manage options on this site.' ) );
    }
    
    /** Write to a new test file */
    /**$result = ITSEC_Lib_File::write( '/var/www/html/wordpress/.htaccess', "This is a .htaccess test.\n" );*/
    $result = ITSEC_Lib_File::write( '/var/www/html/wordpress/.htaccess', "This is a test.\n" );
    
    /** Check and show the result */
    if ( is_wp_error( $result ) ) {
             echo 'Error msg: ' . $result::get_error_message();
    } else {
             echo 'File writing ' . ( $result?'succeeded.':'failed.' );
    }
    • This reply was modified 5 years, 5 months ago by gregmurf.

    Last option, remove the extra comment line:

    /**$result = ITSEC_Lib_File::write( '/var/www/html/wordpress/.htaccess', "This is a .htaccess test.\n" );*/

    Thread Starter gregmurf

    (@gregmurf)

    Still the same error:
    WP error

    • This reply was modified 5 years, 5 months ago by gregmurf.
    • This reply was modified 5 years, 5 months ago by gregmurf.
Viewing 15 replies - 1 through 15 (of 37 total)

The topic ‘Cannot write .htaccess’ is closed to new replies.