• Resolved grindlay

    (@grindlay)


    Problems uploading media when your host uses suPHP, or has file_uploads off in php.ini ?
    This has caught me out a few times, so here is my workaround.

    Firstly, file uploads are off in php.ini, a common security measure for sensible hosting companies.
    To override, you need to place a custom php.ini file in your web space, along the lines of :

    ;;;;;;;;;;;;;;;;
    ; File Uploads ;
    ;;;;;;;;;;;;;;;;
    
    ; Whether to allow HTTP file uploads.
    file_uploads = On
    
    ; Temporary directory for HTTP uploaded files (will use system default if not
    ; specified).
    upload_tmp_dir = /home/account_name/tmp/uploads
    
    ; Maximum allowed size for uploaded files.
    upload_max_filesize = 2M

    Bear in mind that using a wee snippet like this will mean that the rest of your php.ini variables will take on default values, rather than those specified in your host’s global php.ini.
    If you can lay your hands on the server global php.ini, use that instead and just modify the relevant lines to match the above.

    This will work OK until your host deploys suPHP, another sensible security measure for sensible hosts. To get the php.ini snippet working with suPHP, you need to add the following line to the .htacess file in the root of your WP installation:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress
    
    suPHP_ConfigPath "/home/account_name/php"

    When WP is updated (or re-installed), this line may get overwritten, so write yourself a note to remind you put the line back in.

    Best to keep your php.ini snippet out of the public web space and hidden from prying eyes, so don’t put it somewhere like /public_html/php or /www/php. Put it in the folder above and reference it with the correct path in the .htaccess file.

  • The topic ‘File uploads and suPHP’ is closed to new replies.