You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WordPress相关文章代码本地正常,部署至DigitalOcean服务器后白屏

Troubleshooting WordPress White Screen on DigitalOcean (Works Locally)

Hey there, let’s tackle that frustrating white screen issue you’re facing after deploying to DigitalOcean—when local works but remote breaks, it’s usually a configuration, permission, or environment mismatch problem. Let’s break down the most likely fixes based on your code snippet and setup:

1. First, Enable Debug Mode to See the Real Error

The white screen (WSOD) almost always hides a PHP error that’s just not being displayed. Let’s force WordPress to show you what’s wrong by editing your wp-config.php file on the server:

define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', true);
@ini_set('display_errors', 1);

After saving this, reload your page—you’ll now see a specific error message instead of a blank screen, which will point us straight to the problem.

Looking at your snippet, you’re using wp_get_attachment_image_src() to pull a featured image. Here’s what could go wrong on the server:

  • Undefined $post variable: If this code is running outside the main loop or a single post template context, $post->ID might not be defined on the server (even if it worked locally—sometimes local environments have looser error reporting). Try replacing $post->ID with get_the_ID() to make it more reliable:
    $backgroundImg = wp_get_attachment_image_src( get_post_thumbnail_id(get_the_ID()), 'full' );
    
  • Missing featured image: If the post on your server doesn’t have a featured image (or the image wasn’t properly migrated), $backgroundImg will be false, and $backgroundImg[0] will throw an error. Add a check to avoid this:
    $backgroundImg = wp_get_attachment_image_src( get_post_thumbnail_id(get_the_ID()), 'full' );
    $heroStyle = $backgroundImg ? "background: url('{$backgroundImg[0]}') no-repeat center center / cover;" : "";
    ?>
    <div class="full-width blog-single-hero hero" style="<?php echo $heroStyle; ?>">
    

3. Fix File/Directory Permissions on DigitalOcean

Permissions are one of the most common culprits on DigitalOcean servers. WordPress needs specific permissions to read/write files:

  • Set all files to 644 and directories to 755:
    sudo find /path/to/your/wordpress/site -type f -exec chmod 644 {} \;
    sudo find /path/to/your/wordpress/site -type d -exec chmod 755 {} \;
    
  • Make sure the wp-content/uploads directory is owned by the web server user (usually www-data):
    sudo chown -R www-data:www-data /path/to/your/wordpress/site/wp-content/uploads
    

4. Increase PHP Memory Limit

Your server might have a lower PHP memory limit than your local environment, which can cause a WSOD. Add this line to your wp-config.php:

define('WP_MEMORY_LIMIT', '256M');

If that doesn’t work, you can edit your server’s php.ini file (or create a .user.ini file in your WordPress root) to set memory_limit = 256M.

5. Verify All Files Were Deployed Correctly

Double-check that all theme files (especially the Starkers_Utilities class file) were uploaded to the server. If the Starkers_Utilities::get_template_parts() function is missing, that’ll throw a fatal error and cause a white screen. Compare your local theme folder with the server’s to ensure nothing is missing or corrupted.

6. Check PHP Version Compatibility

Local and server PHP versions might differ—for example, if you’re using PHP 7.4 locally but DigitalOcean is running PHP 8.1, older code (like parts of the Starkers framework) might not be compatible. Check your server’s PHP version via cPanel, SSH, or your hosting dashboard, and adjust it to match your local environment if needed.

Once you enable debug mode, you’ll have a clear direction on which fix to prioritize. Let me know if you get a specific error message and I can help narrow it down further!

内容的提问来源于stack exchange,提问作者FoamyMedia

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 08:18:14