Cách chỉnh sửa file wp-config.php trong WordPress

Bạn đang cần Edit file wp-config.php nhưng lại chưa biết bắt đầu từ đâu. Chỉnh sửa nó như thế nào, rất may là bạn đang đọc bài viết này. Vì nó sẽ giúp ích cho bạn thực hiện việc này dễ dàng hơn bao giờ hết. Bạn có thể đọc trình tự từ trên xuống để thao tác không bị sai nhé.

Cách chỉnh sửa file wp-config.php trong WordPress

1. File wp-config.php là gì?

Bất kì một “Website động” nào được kích hoạt đều cần phải có một kết nối đến dữ liệu hay còn gọi là Database thông qua 1 file config. Với WordPress bạn sẽ tìm thấy những thông số này trong file wp-config.php. Vì vậy tệp tin này hết sức quan trọng, nếu trước kia bạn phải tự thay đổi bằng tay thì giờ đây nó tự sinh ra trong quá trình tiến hành cài đặt WordPress.

2. Wp-config.php dùng để làm gì?

Wp-config.php nhiệm vụ chính là khai báo các thông số để kết nối tới Cơ Sở Dữ Liệu WordPress cụ thể như sau:

/** Tên database */
define( 'DB_NAME', 'ten_database_cua_ban' );

/** Username của database */
define( 'DB_USER', 'username_cua_db' );

/** Mật khẩu của Username */
define( 'DB_PASSWORD', 'mk_cua_db' );

/** Database hostname */
define( 'DB_HOST', 'localhost' );

Ngoài ra tệp tin này còn rất nhiều nhiệm vụ khác nữa như khai báo các định nghĩa, tạo cache, tăng tốc website…….Bạn hoàn toàn có thể chỉnh sửa, thêm, xóa bớt code php vào file này nhé.

Để xem chi tiết hơn bạn có thể tham khảo tài liệu từ nguồn code wordpress nhé: https://codex.wordpress.org/vi:wp-config.php

3. Chỉnh sửa wp-config.php ở đâu?

Đa phần các bạn mới lần đầu tiên học WordPress không biết Source code nằm ở đâu. Ở đây tôi sẽ liệt kê một vài trường hợp bạn sẽ tìm thấy file config.

Trước tiên bạn cần xác định Website của mình đang sử dụng dịch vụ Hosting loại nào? Hosting Cpanel WordPress hay DirectAdmin hoặc một vài loại hosting khác. Để việc chỉnh sửa dễ dàng hơn nhé.

3.1 Trên Hosting Cpanel

Cách chỉnh sửa file wp-config.php trong WordPress

Cách chỉnh sửa file wp-config.php trong WordPress

Cách chỉnh sửa file wp-config.php trong WordPress

Cách chỉnh sửa file wp-config.php trong WordPress

Cách chỉnh sửa file wp-config.php trong WordPress

3.2 Trên Hosting DirectAdmin

Cách chỉnh sửa file wp-config.php trong WordPress

Cách chỉnh sửa file wp-config.php trong WordPress

Cách chỉnh sửa file wp-config.php trong WordPress

4. Cách bảo mật file wp-config.php như thế nào?

Việc bảo mật Website WordPress hết sức quan trọng. Đặc biệt là file wp-config.php, bạn nên phân quyền Chmod để an toàn hơn, bạn có thể chuyển về 400 nếu có thể.

4.1 Chmod File trên Hosting Cpanel

Cách chỉnh sửa file wp-config.php trong WordPress

Cách chỉnh sửa file wp-config.php trong WordPress

4.2 Chmod File trên Hosting DirectAdmin

Cách chỉnh sửa file wp-config.php trong WordPress

Bạn có thể xem thêm Video cách bảo vệ Website WordPress bị hacker tấn công

5. File wp-config-sample.php là gì?

Cách chỉnh sửa file wp-config.php trong WordPress

Bạn có đang thắc mắc wp-config-sample.php dùng để làm gì không nhỉ? Nó không phải tệp tin vô dụng đâu nhé. Một vài trường hợp Website bị hacker tấn công, file config bị hư hại hoặc mất đi. Trong trường hợp này bạn chỉ cần nhân bản lại file wp-config-sample.php và đổi tên lại thành wp-config.php để khôi phục lại như ban đầu nhé.

Bạn có thể Copy và sử dụng nội dung file wp-config-sample.php bên dưới nhé.

<?php

/**
* The base configuration for WordPress
*
* The wp-config.php creation script uses this file during the installation.
* You don't have to use the web site, you can copy this file to "wp-config.php"
* and fill in the values.
* This file contains the following configurations:
* * Database settings
* * Secret keys
* * Database table prefix
* * ABSPATH
* @link https://wordpress.org/documentation/article/editing-wp-config-php/
* @package WordPress
*/
// ** Database settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'database_name_here' );

/** Database username */
define( 'DB_USER', 'username_here' );

/** Database password */
define( 'DB_PASSWORD', 'password_here' );

/** Database hostname */
define( 'DB_HOST', 'localhost' );

/** Database charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );

/** The database collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );

/**#@+
* Authentication unique keys and salts.
* Change these to different unique phrases! You can generate these using
* the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}.
* You can change these at any point in time to invalidate all existing cookies.
* This will force all users to have to log in again.
* @since 2.6.0
define( 'AUTH_KEY', 'put your unique phrase here' );
define( 'SECURE_AUTH_KEY', 'put your unique phrase here' );
define( 'LOGGED_IN_KEY', 'put your unique phrase here' );
define( 'NONCE_KEY', 'put your unique phrase here' );
define( 'AUTH_SALT', 'put your unique phrase here' );
define( 'SECURE_AUTH_SALT', 'put your unique phrase here' );
define( 'LOGGED_IN_SALT', 'put your unique phrase here' );
define( 'NONCE_SALT', 'put your unique phrase here' );

/**#@-*/
* WordPress database table prefix.
* You can have multiple installations in one database if you give each
* a unique prefix. Only numbers, letters, and underscores please!
$table_prefix = 'wp_';
* For developers: WordPress debugging mode.
* Change this to true to enable the display of notices during development.
* It is strongly recommended that plugin and theme developers use WP_DEBUG
* in their development environments.
* For information on other constants that can be used for debugging,
* visit the documentation.
* @link https://wordpress.org/documentation/article/debugging-in-wordpress/

define( 'WP_DEBUG', false );
/* Add any custom values between this line and the "stop editing" line. */
/* That's all, stop editing! Happy publishing. */
/** Absolute path to the WordPress directory. */

if ( ! defined( 'ABSPATH' ) ) {
define( 'ABSPATH', __DIR__ . '/' );
}

/** Sets up WordPress vars and included files. */
require_once ABSPATH . 'wp-settings.php';

Với việc diễn giải mọi thứ về file config WordPress như trên, chúng tôi hi vọng các bạn hiểu rõ hơn về tệp tin này nhé.

0 0 đánh giá
Đánh giá bài viết
Theo dõi
Thông báo của
guest
0 Góp ý
Phản hồi nội tuyến
Xem tất cả bình luận