Best Practices for Configuring WordPress
Traducciones al EspañolEstamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.
WordPress is one of the most popular Content Management Systems (CMSs) around. It is open source and is an outstanding tool for creating your own blog or any content-centered website. This guide walks you through several ways that you can fine-tune your WordPress configuration beyond the basic installation. The steps in this guide should work for most Linux distributions.
If you have not already installed WordPress on your server, you can follow one of our guides below to do so:
- How to Install WordPress on Debian 10
- How to Install WordPress on Ubuntu 20.04
- How to Install WordPress Using WP-CLI on CentOS 8
- How to Install WordPress on AlmaLinux 8
Before You Begin
If you have not already done so, create a Linode account and Compute Instance. See our Getting Started with Linode and Creating a Compute Instance guides.
Follow our Setting Up and Securing a Compute Instance guide to update your system. You may also wish to set the timezone, configure your hostname, create a limited user account, and harden SSH access. sudo yum update
Replace all instances of
example.com
in this guide with your domain name.This guide uses PHP version 7.4, the minimum version required by the current WordPress release. Throughout this guide, replace the numbering in
php7.4
andphp74-php
with the numbering appropriate to your PHP version.If you are on CentOS and did not use the Remi repository to install PHP, you may have to replace
php74-php
withphp
throughout this guide.
sudo
. If you’re not familiar with the sudo
command, see the Linux Users and Groups guide.Install Optional PHP Extensions
WordPress has several features that only become available when you have certain PHP extensions installed. These are not required but can add some useful features to your WordPress site.
Each step below shows a PHP extension that can enable functionality for your WordPress site. There are many more PHP extensions, however, and many WordPress plugins require these extensions to function. Be sure to review the documentation for any WordPress plugins you want to use and install the appropriate PHP extensions as needed.
Install the
php-gd
extension if you want to be able to modify images within WordPress.On Debian and Ubuntu, use the following command:
sudo apt install php7.4-gd
On CentOS, use the following command:
sudo yum install php74-php-gd
This extension allows you to do things like crop uploaded images from within WordPress.
Install the
php-mbstring
extension to add support for languages other than English and to fix certain character-encoding issues.On Debian and Ubuntu, use the command below:
sudo apt install php7.4-mbstring
On CentOS, use the following command:
sudo yum install php74-php-mbstring
Install the
php-xmlrpc
extension to be able to use your WordPress site with the WordPress mobile application or to use Jetpack with WordPress.On Debian and Ubuntu, use the following command:
sudo apt install php7.4-xmlrpc
On CentOS, use the command below:
sudo yum install php74-php-xmlrpc
For more information on XML-RPC, review the WordPress XML-RPC guide. For more information on Jetpack, take a look at Jetpack for Wordpress.
Configure WordPress’s Maximum File Size
By default, PHP restricts web uploads to two megabytes. But you can configure PHP to allow larger file uploads.
Locate the
php.ini
file for your web server, then open it with your preferred text editor.If you are using Apache, you should be able to find the
php.ini
file at/etc/php/7.4/apache2/php.ini
.If you are using NGINX, you should be able to find the
php.ini
file at/etc/php/7.4/fpm/php.ini
.However, if you are using CentOS and installed PHP from the Remi repository, the
php.ini
file should be located at/etc/opt/remi/php74/php.ini
. If you did not use the Remi repository, thephp.ini
file should be located at/etc/php.ini
.
Find the
upload_max_filesize
variable in the file and modify its value as needed. If you cannot find the variable, you can add it.- File: php.ini
1 2 3 4
; Maximum allowed size for uploaded files. ; http://php.net/upload-max-filesize upload_max_filesize = 8M
Do the same for the
post_max_size
variable. Its default value may be different than the default forupload_max_filesize
, but you can make both variables the same value when adjusting them.- File: php.ini
1 2 3 4 5 6
; Maximum size of POST data that PHP will accept. ; Its value may be 0 to disable the limit. It is ignored if POST data reading ; is disabled through enable_post_data_reading. ; http://php.net/post-max-size post_max_size = 8M
Restart PHP.
If you are using Apache, use the command below:
sudo systemctl restart php7.4
If you are using NGINX, use the following command:
sudo systemctl restart php7.4-fpm
In the above commands, replace
php7.4
withphp74-php
if you are using CentOS.You can verify that the maximum file size for uploads has increased by navigating to your WordPress site’s administrator dashboard (
example.com/wp-admin
) and selecting Media from the menu on the left. Click Add New, and you should see an indication of the current upload limit.
Configure WordPress’s Permalinks
Permalinks — a combination of “permanent” and “hyperlink” — provide your pages with persistent URLs, making it easier for users to link to specific pages. By default, WordPress uses a number system for permalinks. For example, a page might have the URL example.com/?p=42
. However, you may want your WordPress site to have “prettier” — more readable — permalinks. Thankfully, you can achieve this easily with a setting on your WordPress dashboard and some changes in your web server’s configuration. You can find more information on WordPress’s permalinks in the WordPress Permalinks guide.
Select a Permalink Style in WordPress
Log into WordPress, and navigate to the administrator dashboard, via
example.com/wp-admin
.Select Permalinks from the Settings menu on the left.
Either select a permalink style from the existing options or create your own style using the Custom Structure option. Click Save Changes once you have made your selection.
To enable permalink styling change, follow the appropriate section for your web server, below.
Enable Permalink Styling in Apache
Open the Apache site configuration file —
/etc/apache2/sites-available/example.com.conf
— using your preferred text editor.Find the
Directory
section that identifies your website’s root directory, and modify it as follows:- File: /etc/apache2/sites-available/example.com.conf
1 2 3 4 5 6 7 8 9 10
# [...] <Directory /var/www/html/example.com/public_html> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> # [...]
Restart Apache to have the changes take effect.
sudo systemctl restart apache2
Enable Permalink Styling in NGINX
Open the NGINX site configuration file —
/etc/nginx/sites-available/example.com.conf
— using your preferred text editor.Find the
location /
block, and modify it as follows:- File: /etc/nginx/sites-available/example.com.conf
1 2 3 4 5
location / { index index.php index.html index.htm; try_files $uri $uri/ /index.php?$args; }
Restart NGINX to have the changes take effect.
sudo systemctl restart nginx
More Information
You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.
This page was originally published on