Blog / Linux/ How to Fix the FTP Credential Prompt in WordPress on LNMP

How to Fix the FTP Credential Prompt in WordPress on LNMP

LNMP 环境下解决 WordPress 安装插件/主题时要求 FTP 账号的问题

Fixing the FTP Credential Prompt When Installing WordPress Plugins/Themes in LNMP

When installing plugins or themes in WordPress on an LNMP (Linux, Nginx, MySQL/MariaDB, PHP) stack, you may encounter a prompt requesting FTP credentials. This typically occurs because the web server process (running as a user like www or nginx) lacks write permissions for the WordPress directory.

Solution: Change Directory Ownership

The most direct solution is to change the ownership of your WordPress installation directory to the web server's user via SSH.

Use the following command:

chown -R www /path/to/your/wordpress

Replace /path/to/your/wordpress with your actual WordPress root directory (e.g., /home/wwwroot/example.com).

Key Considerations

  • Identify the Web Server User: First, confirm the user your web server runs as. Common users are www, nginx, or www-data. You can check with ps aux | grep nginx or by reviewing your Nginx configuration.
  • Use the Correct Path: Ensure the path in the command points to the WordPress root directory containing wp-admin, wp-content, and wp-includes.
  • Recursive Operation: The -R flag applies the ownership change recursively to all subdirectories and files.

Alternative: Modify wp-config.php

If you prefer not to change file ownership, you can add the following line to your WordPress configuration file, wp-config.php (located in the root directory):

define('FS_METHOD', 'direct');

This instructs WordPress to attempt direct filesystem writes, often bypassing the FTP prompt. Note that this requires the wp-content directory to already be writable by the web server user.

Summary

The core issue is insufficient write permissions for the web server process. Using the chown command to modify directory ownership is the recommended, standard solution for LNMP environments.

Post a Comment

Your email will not be published. Required fields are marked with *.