WordPress is, by some margin, the most widely used content management system in the world. It’s also, with the addition of the WooCommerce plugin, one of the most popular ecommerce applications.
In this article, we’re going to walk through the process of installing WordPress on a freshly provisioned Linux server. The details are tailored to CentOS 7 and 8, but a similar approach will work on any Linux distribution.
Choose Your WordPress Server
The first step is to select a server. WordPress will run on any ServerMania server. However, while a low-end cloud server makes an excellent WordPress development platform, for busier sites and ecommerce stores we recommend more powerful cloud servers, hybrid servers, or dedicated servers.
While it is possible to host WordPress on a Windows server using a WAMP stack, the most common configuration is the LAMP stack, which includes a Linux OS, Apache web server, MySQL database, and PHP programming language. The web server and database can be swapped for alternatives, but the LAMP stack is by far the most common configuration and the one we’ll focus on here.
Before we start on the installation process, we will assume that you have selected a server, completed any initial server set up, and have root access to the command-line or to a web control panel such as cPanel.
Install WordPress Prerequisites
WordPress has several dependencies, which may or may not be already installed on your Linux distribution. They are:
- A web server, usually Apache (httpd).
- A database, usually MySQL, although CentOS uses a drop-in replacement called MariaDB.
- The PHP programming language, and the PHP extensions WordPress uses.
The easiest way to install these is via your Linux distribution’s package manager. For CentOS, this will install the main dependencies, but you may need to check your distribution or WordPress’s documentation for details about additional PHP extensions and Apache modules:
yum install install httpd mariadb-server php phpmysqlnd
Next, you need to start the web and database servers and create firewall rules to allow incoming connections to the webserver.
On CentOS, the following commands should do the trick:
firewall-cmd --permanent —add-service=http
firewall-cmd --permanent —add-service=https
systemctl start httpd
systemctl start mariadb
systemctl enable httpd
systemctl enable mariadb
CentOS 7’s repositories include an outdated version of PHP. It will work, but WordPress’s developers do not support it. To install an up-to-date version of PHP, you will have to use a third-party repository. This article discusses the process of adding the new repository and installing PHP 7 on CentOS.
At this point, you should be able to enter your server’s domain name or IP address in a browser and see Apache’s test page. If not, SELinux may be preventing the page from loading. See this page to learn more about SELinux.
Create a Database
WordPress uses its MySQL database to store pages, posts, comments, account information, and various other data. Before installing WordPress, we need to create a database for it.
There are various ways to add a database. If you are a cPanel user, follow cPanel’s documentation. You can also set up a database from your server’s command line using the “mysql” client. The process of creating a database is the same for all distributions, but the details of logging in to MySQL as the root user may differ.
On CentOS, enter:
mysql -u root
Next, enter the following SQL command on a single line, replacing the lowercase sections with the relevant details for your WordPress site.
GRANT ALL PRIVILEGES ON database–name.* TO "username"@"hostname" IDENTIFIED BY "password";
The correct ‘hostname’ value is most likely to be ‘localhost’. It is important to remember the details you enter. You will need them later when configuring WordPress.
Finally, enter these commands to make sure MySQL recognizes the new privileges and to exit the MySQL client.
Download and Configure WordPress
It’s time to download and configure WordPress. Go to the WordPress download page and choose the appropriate version. WordPress downloads in a zipped archive, which you can unpack using your operating system’s tools.
WordPress looks for its database details in the “wp-config.php” file. In the top-level of the WordPress folder, you will find the “wp-config-sample.php.” We’re going to edit it and rename it to “wp-config.php.”
Open the file in a text editor (not a word processor). Scroll to “MySQL Settings,” which looks like this.
Edit the “DB_NAME”, “DB_USER”, “DB_PASSWORD”, and “DB_HOST” values to match those you chose for your database.
Next, you must provide authentication keys and salts, which are entered further down the file beneath the MySQL section. WordPress has a web service that generates them for you. Copy the text from that page and paste it in place of the sample text.
Save the file and rename it to “wp-config.php”.
Upload WordPress to Your Server
Now that WordPress is configured, it’s time to upload it to your server and place it in the web server’s root folder. The simplest way to upload the WordPress folder is to use the File Manager in cPanel or the equivalent in other web control panels.
If you want to access your WordPress site at “example.com”, upload the contents of the WordPress folder to Apache’s web root, which is typically found at “/var/www/html/.” You can also create a folder in the web root for your site; for example, if you want to access the site at “example.com/blog,” upload to a folder within the web root called “blog.”
Run WordPress’s Installation Script
The final step is running WordPress’s installation script, which will take care of the remaining configuration. To get started, open “http://example.com/wp-admin/install.php” in a web browser, replacing “example.com” with your domain or IP address. The installation script walks you through the process of creating an admin user and various other settings.
Once you have finished with the installation script, you will have a fully functional WordPress site up-and-running on your server. Now, you can log in and start to configure the site, select a theme, install plugins, and more.