Drupal 7基础文件结构咨询及站点迁移文件部署与数据库连接错误排查需求
Hey there! Let's break down your Drupal 7 questions step by step—this stuff can feel overwhelming when you're new to the platform, but we'll get it sorted out.
Drupal 7基础文件结构与站点文件位置
Drupal 7 has a clear separation between core system files and site-specific content, which helps keep things organized:
- Core system files: These live in the root directory, including folders like
includes/,modules/,themes/, andmisc/. These are Drupal's core code files—you shouldn't edit them directly unless you know exactly what you're doing. - Site-specific content: All your custom modules, themes, uploaded files, and configuration live inside the
sites/directory. For a single-site setup (most common), you'll use thesites/default/subfolder:sites/default/files/: This is the default storage location for all user-uploaded content—images, generated cache files, custom CSS/JS that's been uploaded, and other media assets go here.sites/default/modules/: Store third-party or custom modules here (distinct from core'smodules/folder).sites/default/themes/: Same for third-party or custom themes.sites/default/settings.php: The critical configuration file where you define your database connection details and other site-wide settings.
迁移文件的正确处理方法
First off, splitting the backup into code.tar.gz, db.tar.gz, and files.tar.gz is totally standard and smart—here's why:
code.tar.gzcontains Drupal core plus your custom code (modules, themes, settings).files.tar.gzholds all user-uploaded assets (like the images and CSS you mentioned), which are often larger and change more frequently than code.db.tar.gzis the database backup with all your site's content, users, and configuration.
Here's the correct way to unpack everything:
- Unpack
code.tar.gzdirectly into your website's root directory (e.g.,/home/xxx/public_html/). This will create the core folders and thesites/directory structure. - Unpack
files.tar.gzand move all its contents intosites/default/files/. If thefiles/folder already exists from unpacking the code, just merge the contents (overwriting duplicates is fine—they're the same assets). Do NOT unpackfiles.tar.gzinto the root directory—this will mess up Drupal's structure and cause errors, which is probably what happened earlier. - Next, you'll need to import the
db.tar.gzbackup into a MySQL database. Use phpMyAdmin, themysqlcommand line, or your hosting provider's database tool to do this.
解决PDOException数据库访问错误
That error message (PDOException: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost') is telling you exactly what's wrong: Drupal can't connect to your database because the credentials it's using are invalid. Here's how to fix it:
- Go to
sites/default/and make sure you have asettings.phpfile. If you only seedefault.settings.php, copy that file and rename it tosettings.php. - Open
settings.phpand find the database configuration section—it looks like this:$databases = array ( 'default' => array ( 'default' => array ( 'database' => 'your_database_name', 'username' => 'your_db_user', 'password' => 'your_db_password', 'host' => 'localhost', 'port' => '', 'driver' => 'mysql', 'prefix' => '', ), ), ); - Update these values to match your database setup:
database: The name of the database you importeddb.tar.gzinto.username: A database user that has full access to that database (it's best practice to use a dedicated user for your Drupal site, notroot—but if you're usingroot, double-check the password).password: The correct password for that database user.host: Leave aslocalhostif your database is on the same server as your website.
- Save the
settings.phpfile, then refresh your website. If everything is correct, Drupal should connect to the database and load your site.
内容的提问来源于stack exchange,提问作者Lena Shore

