### Configure WordPress (wp-config.php)
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/before-install/howto-install.md
Renames the sample configuration file `wp-config-sample.php` to `wp-config.php` and instructs to edit it with database credentials. This file is essential for WordPress to connect to its database and is created automatically if not present during installation.
```shell
# Optional: Rename and edit wp-config-sample.php
# mv wp-config-sample.php wp-config.php
# Then edit wp-config.php with your database details.
```
--------------------------------
### Configure wp-config.php for Multiple Databases
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/before-install/multiple-instances.md
This snippet shows the database connection parameters that need to be configured in the wp-config.php file for each WordPress instance when using a separate database for each installation. It specifies the database name, user, password, and host.
```PHP
define('DB_NAME', 'wordpress'); // The name of the database
define('DB_USER', 'username'); // Your MySQL username
define('DB_PASSWORD', 'password'); // The users password
define('DB_HOST', 'localhost' ); // The host of the database
```
--------------------------------
### Download WordPress Package
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/before-install/howto-install.md
Downloads the latest WordPress package from the official repository using the `wget` command. This is a common method for server-side downloads when shell access is available.
```shell
wget https://wordpress.org/latest.tar.gz
```
--------------------------------
### Apache DirectoryIndex Configuration
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/before-install/howto-install.md
Ensures Apache serves index.php by default to prevent directory listings. This is typically done via a .htaccess file or server configuration.
```apache
DirectoryIndex index.php
```
--------------------------------
### Extract WordPress Archive
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/before-install/howto-install.md
Extracts the downloaded WordPress archive file (`latest.tar.gz`) using the `tar` command. This unpacks the WordPress files into a directory, preparing them for upload to the web server.
```shell
tar -xzvf latest.tar.gz
```
--------------------------------
### WordPress wp-config.php Configuration
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/before-install/howto-install.md
Details the essential database connection settings and security keys required for the wp-config.php file. This file is critical for WordPress to connect to its database and maintain security.
```APIDOC
// ** MySQL settings - You can get this info from your web host ** //
// ** Database Name **
// The name of the database you created for WordPress.
// Example: "wordpress_db"
// ** Database User **
// The username you created for WordPress.
// Example: "wp_user"
// ** Database Password **
// The password you chose for the WordPress username.
// Example: "s3cr3tP@ssw0rd"
// ** Database Host **
// The hostname for your database. Usually 'localhost', but may vary.
// If a port, socket, or pipe is necessary, append it with a colon.
// Example: "localhost:3306"
// ** Database Charset **
// The database character set. Typically should not be changed.
// Example: "utf8mb4"
// ** Database Collate **
// The database collation. Should normally be left blank.
// Example: ""
/* Authentication Unique Keys and Salts. */
// Generate unique keys and salts for enhanced security. These are used for authentication.
// Example: "put your unique phrase here"
```
--------------------------------
### Nginx: WordPress Single Site Setup
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/server/nginx.md
Sets up the primary Nginx server block for a single WordPress installation. It defines the server name, root directory, index file, and includes global restriction and WordPress core configuration files.
```nginx
server {
server_name example.com;
root /var/www/example.com;
index index.php;
include global/restrictions.conf;
# Additional rules go here.
# Only include one of the files below.
include global/wordpress.conf;
# include global/wordpress-ms-subdir.conf;
# include global/wordpress-ms-subdomain.conf;
}
```
--------------------------------
### IIS web.config for Subdirectory Install
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/server/wordpress-in-directory.md
This IIS configuration file is used when WordPress is installed in a subdirectory and the website is served from the root. It contains rewrite rules similar to .htaccess for Apache, directing traffic to the correct WordPress core location.
```IIS
```
--------------------------------
### Compress Backup File with bzip2
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/security/backup-database.md
Compresses a previously created SQL backup file ('blog.bak.sql') using the bzip2 utility, creating a compressed archive named 'blog.bak.sql.bz2'.
```bash
user@linux:~/files/blog> bzip2 blog.bak.sql
```
--------------------------------
### cPanel X MySQL Database Backup
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/security/backup-database.md
Instructions for backing up a MySQL database using the cPanel X control panel. This method downloads a compressed database file (`*.gz`) directly to your local drive.
```APIDOC
cPanel X MySQL Database Backup:
Action: Download a MySQL Database Backup
Process:
1. Log into cPanel X.
2. Navigate to the backup feature.
3. Select 'Download a MySQL Database Backup'.
4. Click the name of your WordPress database.
Output: A *.gz file containing the database backup is downloaded.
Restoration:
- Upload the *.gz file via cPanel.
- Ensure database user and password match wp-config.php if changing hosts or passwords.
```
--------------------------------
### SELinux Package Check
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/server/file-permissions.md
Command to list installed SELinux-related packages on RPM-based systems to verify its presence.
```shell
$ rpm -qa | grep selinux
selinux-policy-targeted-3.13.1-166.el7_4.7.noarch
selinux-policy-3.13.1-166.el7_4.7.noarch
libselinux-2.5-11.el7.x86_64
libselinux-python-2.5-11.el7.x86_64
libselinux-utils-2.5-11.el7.x86_64
```
--------------------------------
### Unzip Database Backup (.tar.gz)
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/security/backup-database.md
Command to extract a tar.gz compressed SQL backup file. Use this if your database backup was archived and compressed using tar and gzip.
```bash
tar -zxvf blog.bak.sql.tar.gz
```
--------------------------------
### .htaccess for Root Install
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/server/wordpress-in-directory.md
This Apache configuration file redirects requests from the website root to a WordPress installation located in a subdirectory, without changing the SITE_URL. It handles host matching and excludes existing files/directories.
```Apache
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/my_subdir/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /my_subdir/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ my_subdir/index.php [L]
```
--------------------------------
### WP-CLI Tool Reference
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/upgrade/upgrading.md
WP-CLI is a command-line interface for WordPress. It allows users to manage WordPress installations, perform updates, and execute various administrative tasks directly from the console.
```APIDOC
WP-CLI:
Description: Command-line interface for WordPress.
URL: https://wp-cli.org/
Usage: Run WordPress commands directly via console.
Example: wp core update
Related: Facilitates manual update processes mentioned in upgrade guides.
```
--------------------------------
### WP-CLI PHP Compatibility Check
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/performance/php.md
A WP-CLI command is available to perform a general compatibility check for PHP versions. While useful, it's noted that this command is not 100% accurate and should be used as a guide.
```APIDOC
WP-CLI Command for PHP Compatibility:
Command:
wp-cli php-compat
Description:
Performs a general compatibility check of your WordPress environment against different PHP versions.
Usage:
wp-cli php-compat
Note:
This command provides a general assessment and may not catch all compatibility issues. Thorough testing on staging environments is recommended.
```
--------------------------------
### Change Directory for Backup
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/security/backup-database.md
Navigates to the desired directory on the local system where the database backup file will be saved. This is a prerequisite step before executing backup commands.
```bash
user@linux:~> cd files/blog
user@linux:~/files/blog>
```
--------------------------------
### Restore Database Using MySQL/MariaDB Command
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/security/backup-database.md
Command to import a SQL backup file into a MySQL/MariaDB database. It requires specifying the host, username, password, and database name.
```bash
user@linux:~/files/blog> mysql -h mysqlhostserver -u mysqlusername -p databasename < blog.bak.sql
Enter password: (enter your mysql password)
user@linux:~/files/blog>
```
--------------------------------
### Unzip Database Backup (.bz2)
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/security/backup-database.md
Command to decompress a bzip2 compressed SQL backup file. This is a prerequisite for restoring the database using MySQL/MariaDB commands.
```bash
user@linux:~/files/blog> bzip2 -d blog.bak.sql.bz2
```
--------------------------------
### WordPress Multisite URL Patterns
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/multisite/prepare-network.md
Illustrates the URL structures used for domain-based (subdomain) and path-based (subdirectory) WordPress multisite installations. This helps understand how sub-sites are accessed within a network.
```APIDOC
WordPress Multisite URL Patterns:
1. **Domain-based (Subdomain) Installs**:
* Uses subdomains to represent different sites within the network.
* URL structure: `https://subsite.example.com`
* Requires wildcard subdomains configured at the DNS and server level.
* WordPress installation should ideally be at the root of the webfolder (e.g., `public_html`).
2. **Path-based (Subfolder/Subdirectory) Installs**:
* Uses subdirectories of the main domain to represent different sites.
* URL structure: `https://example.com/subsite`
* Works well with existing pretty permalinks.
* Main site posts may use a `blog` slug (e.g., `https://example.com/blog/[postformat]/`), which is difficult to remove without manual network option edits.
**Note**: Path-based installs do not require wildcard DNS or complex virtual host configurations, making them simpler for some setups.
```
--------------------------------
### WordPress Network Setup Configuration
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/multisite/create-network.md
Instructions for enabling a WordPress network by adding specific lines to wp-config.php and .htaccess files. This process is crucial for activating the multisite functionality.
```APIDOC
WordPress Multisite Configuration:
This documentation outlines the critical configuration steps required to enable a WordPress network (multisite).
1. **wp-config.php Modification**:
* **Purpose**: To define WordPress multisite constants and enable the network.
* **Location**: Add the following lines to your `wp-config.php` file, typically just after the `WP_DEBUG` line or similar core configuration settings.
* **Content**:
```php
/* Multisite */
define( 'WP_ALLOW_MULTISITE', true );
```
* **Notes**: Ensure `WP_ALLOW_MULTISITE` is set to `true` to enable the network setup interface.
2. **Enabling Network via Tools Menu**:
* **Action**: Navigate to **Tools** > **Network Setup** in the WordPress admin dashboard.
* **Configuration**: Choose between sub-domains or sub-directories for your network sites. Fill in the 'Network Title' and 'Network Admin E-mail'.
* **Output**: The system will provide specific lines to add to your `wp-config.php` and `.htaccess` files based on your choices.
3. **.htaccess File Modification**:
* **Purpose**: To handle the routing for sub-domain or sub-directory based sites within the network.
* **Location**: Add the provided lines to your `.htaccess` file located in the WordPress root directory. If the file does not exist, create it.
* **Content Example (Sub-directory based)**:
```apache
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-content/.*) $1$2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*.php)$ $2 [L]
RewriteRule . index.php [L]
```
* **Content Example (Sub-domain based)**:
```apache
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-content/.*) $1$2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*.php)$ $2 [L]
RewriteRule . index.php [L]
```
* **Important Notes**:
- If you already have a `.htaccess` file, replace any existing WordPress-specific rules with the new ones provided.
- In some server configurations, you might need to add `Options FollowSymlinks` at the beginning of the `.htaccess` file.
- After modification, you may need to clear your browser's cache and cookies.
**Related Actions**:
- Backup `wp-config.php` and `.htaccess` before making changes.
- Ensure server requirements, including wildcard DNS if using sub-domain mapping, are met.
- Refer to WordPress documentation for specific server environment configurations.
```
--------------------------------
### Execute mysqldump Backup and Save to File
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/security/backup-database.md
Executes the mysqldump command to back up a WordPress database ('wp') from a specified host and user, redirecting the output to a file named 'blog.bak.sql'. The command prompts for the database password.
```bash
user@linux:~/files/blog> mysqldump --add-drop-table -h db01.example.net -u dbocodex -p wp > blog.bak.sql
Enter password: (type password)
```
--------------------------------
### phpMyAdmin Database Backup (Quick Export)
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/security/backup-database.md
A simplified method for backing up all tables in a WordPress database using phpMyAdmin. This process exports the database without compression, suitable for databases without existing tables during restoration.
```APIDOC
phpMyAdmin Quick Database Export:
Purpose: Backup all tables in the WordPress database without compression.
Prerequisites: phpMyAdmin installed and accessible, database selected.
Steps:
1. Log into phpMyAdmin.
2. Select your WordPress database from the left-side window.
3. Click the 'Export' tab.
4. Ensure 'Quick' option is selected.
5. Click 'Go' to initiate the download.
Output: A SQL file containing the database backup is downloaded.
Restoration Note: Target database should be empty (no tables) before restoring this backup.
```
--------------------------------
### CPanel Wildcard Subdomain Setup
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/server/subdomains-wildcard.md
Instructions for setting up a wildcard subdomain within the CPanel interface. This involves creating a subdomain named '*' and pointing it to the correct directory.
```cpanel
Create a subdomain named "*" (wildcard).
Point this wildcard subdomain to the same folder location where your wp-config.php file is located.
```
--------------------------------
### WP-CLI Search Replace Command
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/upgrade/migrating.md
Executes a search and replace operation within the WordPress database using WP-CLI. It replaces 'example.dev' with 'example.com', skipping the 'guid' column to avoid potential issues.
```shell
wp search-replace 'example.dev' 'example.com' --skip-columns=guid
```
--------------------------------
### Apache Options Directive Examples
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/server/httpd.md
This snippet demonstrates the use of Apache's Options directive to control server features in a directory. It shows how to disable all options and then specifically enable FollowSymLinks, which is often required for mod_rewrite.
```apache-config
Options None
Options FollowSymLinks
```
--------------------------------
### phpMyAdmin Database Backup (Custom Export)
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/security/backup-database.md
A detailed method for backing up WordPress databases using phpMyAdmin, allowing customization of tables, compression, and output format. This provides more control over the backup process.
```APIDOC
phpMyAdmin Custom Database Export:
Purpose: Backup WordPress database with custom options for tables, compression, and format.
Prerequisites: phpMyAdmin installed and accessible, database selected.
Steps:
1. Log into phpMyAdmin.
2. Select your WordPress database.
3. Click the 'Export' tab.
4. Select 'Custom' option.
5. Configure Export Options:
- Table section: Select specific tables (e.g., those starting with 'wp_' or your custom table_prefix). Default is 'Select All'.
- Output section:
- Compression: Choose 'zipped' or 'gzipped' for compression.
- Format section:
- Format: Ensure 'SQL' is selected.
- Format-specific options: Leave as default.
6. Click 'Go' to initiate the download.
Output: A compressed SQL file containing the selected database backup is downloaded.
```
--------------------------------
### Basic WordPress .htaccess Configuration
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/server/httpd.md
This snippet provides the standard .htaccess configuration for a basic WordPress installation. It enables the rewrite engine, sets the base directory, and handles requests by routing them to index.php for pretty permalinks.
```apache-config
# BEGIN WordPress
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
```
--------------------------------
### CSS Background Image Path in Sandbox
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/debug/test-driving.md
This CSS code example illustrates how to define a background image for an HTML element, such as a header. It shows the correct path structure for images located in a subfolder within the sandbox environment.
```css
header {
margin:5px;
padding:10px;
background:url(images/background.jpg)....
}
```
--------------------------------
### MySQL Client: Create Database and User
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/before-install/creating-database.md
Demonstrates how to connect to the MySQL server, create a new database, create a user, grant privileges, and flush privileges using SQL commands in the shell.
```Shell
$ mysql -u adminusername -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5340 to server version: 3.23.54
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> CREATE DATABASE databasename;
Query OK, 1 row affected (0.00 sec)
mysql> CREATE USER "wordpressusername"@"hostname" IDENTIFIED BY "password";
mysql> GRANT ALL PRIVILEGES ON databasename.* TO "wordpressusername"@"hostname";
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
mysql> EXIT
Bye
```
--------------------------------
### WordPress Multisite .htaccess for SubFolder Installs
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/multisite/administration.md
Provides .htaccess rules for WordPress Multisite when installed in subfolders (path-based). Includes configurations for WordPress versions 3.0-3.4+ and 3.5+.
```Apache
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
# uploaded files
RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
# END WordPress
```
```Apache
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
# END WordPress
```
--------------------------------
### WordPress Multisite .htaccess for SubDomain Installs
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/multisite/administration.md
Provides .htaccess rules for WordPress Multisite when installed using subdomains (domain-based). Includes configurations for WordPress versions 3.0-3.4+ and 3.5+.
```Apache
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
# uploaded files
RewriteRule ^files/(.+) wp-includes/ms-files.php?file=$1 [L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule . index.php [L]
# END WordPress
```
```Apache
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ wp/$1 [L]
RewriteRule . index.php [L]
# END WordPress
```
--------------------------------
### cPanel: Database and User Creation Steps
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/before-install/creating-database.md
Details the process of creating a WordPress database and user via the cPanel hosting control panel. It guides through the MySQL Database Wizard, including database and user creation, and privilege assignment.
```APIDOC
CPanelDatabaseManagement:
Access:
- Log in to cPanel.
- Locate and click the 'MySQL Database Wizard' icon under the 'Databases' section.
CreateDatabase:
- Step 1: Enter the database name and click 'Next Step'.
- Step 2: Enter the database username and a strong password, then click 'Create User'.
- Step 3: Grant 'All Privileges' to the user for the database by checking the checkbox and clicking 'Next Step'.
- Step 4: Note down the database name, username, and password. The hostname is typically 'localhost'.
```
--------------------------------
### Insecure Host Configuration Example (Apache)
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/security/https.md
An example Apache VirtualHost configuration stanza for an insecure (HTTP) site. It specifies the DocumentRoot and includes rewrite rules to handle WordPress permalinks and redirect specific administrative paths to the secure site. This configuration includes rules for feed redirection.
```apache
ServerName www.mysite.com
DocumentRoot /var/www/ii/mysite
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^wp-admin/(.*) https://www.example.com/wp-admin/$1 [C]
RewriteRule ^.*$ - [S=40]
RewriteRule ^feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?&feed=$1 [QSA,L]
```
--------------------------------
### Plesk: Database and User Creation Steps
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/before-install/creating-database.md
Outlines the steps to create a database and user for WordPress using the Plesk hosting control panel. This involves navigating to the Databases section and adding new database credentials.
```APIDOC
PleskDatabaseManagement:
Access:
- Log in to Plesk.
- Navigate to 'Websites & Domains' > 'Custom Website' > 'Databases'.
CreateDatabase:
- Click 'Add New Database'.
- Optionally change the database name.
- Create a database user by providing credentials.
- Click 'OK' to complete.
```
--------------------------------
### Secure Virtual Host Configuration Example (Apache)
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/security/https.md
An example Apache VirtualHost configuration stanza for a secure (HTTPS) site. It includes SSL engine settings, certificate paths, and rewrite rules to redirect public traffic to the insecure site, ensuring seamless user experience. This configuration is for port 443.
```apache
ServerName www.example.com
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/thissite.crt
SSLCertificateKeyFile /etc/apache2/ssl/thissite.pem
SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
DocumentRoot /var/www/mysite
RewriteEngine On
RewriteRule !^/wp-(admin|includes)/(.*) - [C]
RewriteRule ^/(.*) https://www.example.com/$1 [QSA,L]
```
--------------------------------
### Set WordPress Language in wp-config.php
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/before-install/in-your-language.md
Manually configure the WordPress administrative language by editing the `wp-config.php` file. This involves adding or modifying the `define('WPLANG', '...')` directive with the appropriate language code (e.g., `pt_BR` for Brazilian Portuguese) corresponding to your downloaded `.mo` language file. This method is primarily for older WordPress versions (3.9.2 and below) or when automatic installation is not preferred.
```PHP
define ( 'WPLANG', 'pt_BR' );
```
--------------------------------
### PHP: Get Server Information with phpinfo()
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/server/server-info.md
This snippet demonstrates how to use the PHP `phpinfo()` function to generate a detailed report of the server's configuration, including PHP version, server software, and operating system. It requires a PHP-enabled web server. The output is a comprehensive report displayed in the browser.
```php
```
--------------------------------
### WooCommerce Product Import (CSV)
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/wordpress/import.md
Instructions for importing WooCommerce products using a CSV file. This feature is available if the WooCommerce plugin is installed.
```woocommerce
1. Ensure WooCommerce plugin is installed.
2. Navigate to Tools -> Import.
3. Select the "WooCommerce Products (CSV)" importer.
4. Click "Run Importer".
5. Upload your CSV file containing product data.
```
--------------------------------
### Custom User and Usermeta Tables Configuration
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/before-install/multiple-instances.md
Define constants in wp-config.php to point to custom user and usermeta tables, allowing a shared userbase across multiple WordPress sites on the same domain. This is useful for managing a single user directory for distinct blog instances.
```PHP
define( 'CUSTOM_USER_TABLE', 'wp_your_blog_users' );
define( 'CUSTOM_USER_META_TABLE', 'wp_your_blog_usermeta' );
```
--------------------------------
### Joomla to WordPress Migration with FG Joomla to WordPress
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/wordpress/import.md
Using the FG Joomla to WordPress plugin to migrate content from Joomla installations to WordPress.
```APIDOC
Joomla Migration:
- Plugin: FG Joomla to WordPress
- Compatibility: Tested with Joomla versions 1.5 through 4.0.
- Features: Supports large databases and multisite installations.
- Source: https://wordpress.org/plugins/fg-joomla-to-wordpress/
```
--------------------------------
### Nginx Generic Startup Configuration
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/server/nginx.md
This Nginx configuration file serves as the main startup file, equivalent to nginx.conf. It defines worker processes, error logging, event handling, MIME types, client body size limits, and upstream configurations for PHP-FPM.
```nginx
# Generic startup file.
user {user} {group};
#usually equal to number of CPUs you have. run command "grep processor /proc/cpuinfo | wc -l" to find it
worker_processes auto;
worker_cpu_affinity auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
# Keeps the logs free of messages about not being able to bind().
#daemon off;
events {
worker_connections 1024;
}
http {
#rewrite_log on;
include mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
sendfile on;
#tcp_nopush on;
keepalive_timeout 3;
#tcp_nodelay on;
#gzip on;
#php max upload limit cannot be larger than this
client_max_body_size 13m;
index index.php index.html index.htm;
# Upstream to abstract backend connection(s) for PHP.
upstream php {
#this should match value of "listen" directive in php-fpm pool
server unix:/tmp/php-fpm.sock;
# server 127.0.0.1:9000;
}
include sites-enabled/*;
}
```
--------------------------------
### Backup and Compress Database in One Command (gzip)
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/security/backup-database.md
Combines database dumping and compression into a single command using gzip. It pipes the output of mysqldump directly to gzip for on-the-fly compression, saving the result to 'blog.bak.sql.gz'. Gzip is generally faster than bzip2 for compression and decompression.
```bash
user@linux:~/files/blog> mysqldump --add-drop-table -h db01.example.net -u dbocodex -p wp | gzip > blog.bak.sql.gz
```
--------------------------------
### WooCommerce Tax Rate Import (CSV)
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/wordpress/import.md
Instructions for importing WooCommerce tax rates using a CSV file. This functionality is available upon installation of the WooCommerce plugin.
```woocommerce
1. Ensure WooCommerce plugin is installed.
2. Navigate to Tools -> Import.
3. Select the "WooCommerce Tax Rates (CSV)" importer.
4. Click "Run Importer".
5. Upload your CSV file containing tax rate data.
```
--------------------------------
### Backup and Compress Database in One Command (bzip2)
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/security/backup-database.md
Combines database dumping and compression into a single command. It pipes the output of mysqldump directly to bzip2 for on-the-fly compression, saving the result to 'blog.bak.sql.bz2'. This method is effective but can be slower for very large databases compared to gzip.
```bash
user@linux:~/files/blog> mysqldump --add-drop-table -h db01.example.net -u dbocodex -p wp | bzip2 -c > blog.bak.sql.bz2
Enter password: (type password)
```
--------------------------------
### wp-config.php Settings for Development Error Display
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/wordpress/wp-config.md
Example settings to override php.ini defaults in wp-config.php for development environments. This configuration enables immediate error display and debugging features.
```PHP
@ini_set( 'log_errors', 'Off' );
@ini_set( 'display_errors', 'On' );
define( 'WP_DISABLE_FATAL_ERROR_HANDLER', true ); // 5.2 and later
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', false );
define( 'WP_DEBUG_DISPLAY', true );
```
--------------------------------
### WordPress Theme Customization Strategy
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/resources/faq.md
Explains how core WordPress upgrades can overwrite custom changes made to default theme files and recommends using child themes to safeguard customizations.
```APIDOC
WordPress Theme Upgrade Considerations:
Core upgrades replace existing theme files with new versions. Direct modifications to files like `wp-content/themes/twentysixteen/style.css` will be overwritten.
Recommended Practice: Child Themes
Utilize child themes to apply customizations. This approach isolates your changes from the parent theme, ensuring they are preserved during future theme updates.
File Preservation:
Files not part of the core distribution and not explicitly deleted during an upgrade are generally preserved. However, direct modification of core theme files is not recommended.
```
--------------------------------
### Define WP_ALLOW_MULTISITE to Enable Multisite
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/wordpress/wp-config.md
This snippet enables the WordPress Multisite (Network) functionality by defining WP_ALLOW_MULTISITE as true. This setting is crucial for setting up a network of sites from a single WordPress installation.
```php
define( 'WP_ALLOW_MULTISITE', true );
```
--------------------------------
### Configure Multisite Network Type (wp-config.php)
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/multisite/administration.md
Defines the network installation type (sub-domain or sub-directory) by modifying the SUBDOMAIN_INSTALL constant in wp-config.php. Essential for setting up WordPress Multisite.
```PHP
define( 'SUBDOMAIN_INSTALL', true );
```
```PHP
define( 'SUBDOMAIN_INSTALL', false );
```
--------------------------------
### DirectAdmin DNS and Httpd Configuration
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/server/subdomains-wildcard.md
Guides for configuring wildcard subdomains in DirectAdmin, including adding DNS records and custom HTTPD configurations for domain aliasing.
```dns
* A 192.0.2.1
```
```apache
ServerAlias *.|DOMAIN|
```
--------------------------------
### Configure wp-config.php Table Prefix for Single Database
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/before-install/multiple-instances.md
This snippet demonstrates how to set the table prefix in the wp-config.php file when multiple WordPress instances share a single database. A unique prefix for each instance prevents table name conflicts.
```PHP
$table_prefix = 'wp_'; // example: 'wp_' or 'b2' or 'mylogin_'
```
```PHP
$table_prefix = 'main_';
```
```PHP
$table_prefix = 'projects_';
```
```PHP
$table_prefix = 'test_';
```
--------------------------------
### PHP Configuration Files
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/performance/php.md
PHP settings are primarily managed through configuration files. The main file is php.ini, but some environments allow customization via .htaccess or .user.ini files. These files contain directives that control PHP's behavior.
```APIDOC
Configuration Files:
php.ini:
- The primary configuration file for PHP.
- Contains directives that control PHP's runtime behavior.
- Location varies by server setup (e.g., server root, PHP installation directory).
.htaccess:
- Apache configuration file that can override server settings.
- Can be used to set PHP values using directives like 'php_value' or 'php_flag'.
- Not available on all server types (e.g., Nginx).
.user.ini:
- Similar to php.ini but can be placed in directories to override settings.
- Often used in shared hosting environments.
- Directives are typically applied recursively to the directory and its subdirectories.
See official PHP documentation for a comprehensive list of directives and their usage.
```
--------------------------------
### Server Configuration Directives for WordPress Multisite
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/multisite/prepare-network.md
Details essential server configuration directives required for WordPress Multisite. This includes Apache's .htaccess file settings, Nginx configuration, and web.config for IIS, ensuring proper rewrite rules and directory permissions are enabled.
```APIDOC
Server Configuration Requirements for WordPress Multisite:
1. **Apache (.htaccess)**:
* Requires `mod_rewrite` to be loaded.
* Requires support for `.htaccess` files.
* `Options FollowSymLinks` must be enabled or not permanently disabled.
* `AllowOverride` directive in `httpd.conf` or vhost configuration should be set to `All` or `Options All` for the relevant directory.
Example `.htaccess` snippet (conceptual):
```apache
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
```
2. **Nginx (nginx.conf)**:
* Requires specific server block configuration to handle rewrite rules for multisite.
Example Nginx configuration snippet (conceptual):
```nginx
location / {
try_files $uri $uri/ /index.php?q=$request_uri;
}
```
3. **IIS (web.config)**:
* Requires URL Rewrite module and specific configuration for multisite.
Example `web.config` snippet (conceptual):
```xml
```
**Dependencies**: `mod_rewrite` for Apache, URL Rewrite module for IIS.
**Limitations**: Specific configurations may vary based on server setup and hosting provider. Consult hosting documentation for precise directives.
```
--------------------------------
### User Role Troubleshooting Steps
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/resources/faq.md
Provides sequential steps to resolve issues related to user roles and author names, often involving creating, demoting, and promoting users.
```text
1. Create new admin user (e.g. newadmin) with Administrator Role
2. Login as 'newadmin'
3. Degrade the old 'admin' user to Role of Subscriber and Save
4. Promote the old 'admin' back to Administrator Role and Save
5. Login as the old 'admin'
```
```text
1. Create a new admin user (e.g. newadmin) with Administrator Role
2. Login as 'newadmin'
3. Delete the old 'admin' user and assign any posts to 'newadmin'
4. Create 'admin' user with Administrator Role
5. Login as 'admin'
6. Delete 'newadmin' user and assign posts to 'admin'
```
--------------------------------
### Backup All Database Tables with mysqldump
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/security/backup-database.md
Uses the mysqldump utility to create a full backup of a MySQL/MariaDB database. The --add-drop-table option ensures that DROP TABLE statements are included, allowing for easy restoration by overwriting existing tables. It requires specifying the host, username, and database name, and prompts for the password.
```bash
mysqldump --add-drop-table -h mysql_hostserver -u mysql_username -p mysql_databasename
```
--------------------------------
### Define NOBLOGREDIRECT to Redirect Nonexistent Blogs
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/wordpress/wp-config.md
This code defines the NOBLOGREDIRECT constant to specify a URL for redirecting users who attempt to access a non-existent subdomain or subfolder within a WordPress multisite installation.
```php
define( 'NOBLOGREDIRECT', 'https://example.com' );
```
--------------------------------
### PHPMailer Class for DKIM Configuration
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/server/mail.md
API documentation for the PHPMailer class, specifically detailing properties related to DKIM (DomainKeys Identified Mail) signing. This information is crucial for developers looking to implement DKIM support within WordPress by hooking into 'phpmailer_init'.
```APIDOC
PHPMailer:
__construct()
Initializes the PHPMailer class.
DKIM_domain: string
The domain name for DKIM signing.
DKIM_selector: string
The DKIM selector used for the signature.
DKIM_private: string
The path to the private key file for DKIM signing.
DKIM_passphrase: string | null
The passphrase for the private key, if any.
DKIM_identity: string | null
The identity to sign with (e.g., 'selector._domainkey.domain.com').
DKIM_canonicalization: string
The DKIM canonicalization method (e.g., 'relaxed/simple').
sign_dkim_headers(): void
Signs the email headers with DKIM.
send(): bool
Sends the email after applying all settings, including DKIM signing if configured.
```
--------------------------------
### WordPress PHPMailer Initialization Hook
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/server/mail.md
Demonstrates how to hook into the 'phpmailer_init' action in WordPress to customize PHPMailer settings, such as adding DKIM keys for email authentication. This allows WordPress to send emails with proper DKIM signatures.
```php
add_action( 'phpmailer_init', 'my_custom_phpmailer_settings' );
function my_custom_phpmailer_settings( PHPMailer $phpmailer ) {
// Example: Set DKIM properties
// $phpmailer->DKIM_domain = "example.com";
// $phpmailer->DKIM_selector = "wordpress";
// $phpmailer->DKIM_private = "/path/to/your/private.key";
// $phpmailer->DKIM_passphrase = "your_passphrase";
// Add other custom PHPMailer settings here
// $phpmailer->isSMTP();
// $phpmailer->Host = 'smtp.example.com';
// $phpmailer->Port = 587;
// $phpmailer->SMTPAuth = true;
// $phpmailer->Username = 'user@example.com';
// $phpmailer->Password = 'password';
}
```
--------------------------------
### Set Database Table Prefix
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/wordpress/wp-config.md
Defines the prefix for all WordPress database tables. This is useful for installing multiple WordPress blogs in the same database, especially with multisite. The prefix should only contain numbers, letters, and underscores.
```PHP
$table_prefix = 'example123_'; // Only numbers, letters, and underscores please!
```
--------------------------------
### SPIP to WordPress Plugin
Source: https://github.com/wordpress/advanced-administration-handbook/blob/main/wordpress/import.md
Details about the FG SPIP to WordPress plugin, which migrates categories, articles, news, and images from SPIP to WordPress. It supports various SPIP versions and multisite installations.
```wordpress-plugin
Plugin: FG SPIP to WordPress
Compatibility: SPIP versions 1.8, 1.9, 2.0, 3.0, 3.1, 3.2
Features: Migrates categories, articles, news, and images.
Notes: Compatible with multisite installations.
```