WordPress is a popular CMS for building websites and blogs. On CentOS, Fedora, and Red Hat, WordPress requires a LAMP stack (Apache, MySQL, PHP) to function. Proper configuration ensures optimal performance and security. This guide focuses on how to install and configure WordPress efficiently in this environment.

The LAMP stack provides the necessary infrastructure. Apache handles web traffic, MySQL stores data, and PHP processes the content. WordPress relies on MySQL to store site data, such as posts and user information, while Apache serves dynamic pages with help from mod_rewrite, important for SEO.

For a secure and functional setup, ensure correct permissions and configurations. The steps include setting up a MySQL database, configuring Apache for WordPress, and securing file permissions. Each step is necessary to avoid vulnerabilities and performance issues.

Steps to install and configure WordPress on CentOS, Fedora, or Red Hat:

  1. Download the latest version of WordPress from the official website.
    $ cd /var/www/html
    $ sudo wget https://wordpress.org/latest.tar.gz
  2. Extract the WordPress archive to the web root directory.
    $ sudo tar -xvzf latest.tar.gz
  3. Move the extracted files to the desired directory.
    $ sudo mv wordpress/* /var/www/html/
    $ sudo rm -rf wordpress latest.tar.gz
  4. Set the ownership of WordPress files to the Apache user and ensure proper permissions.
    $ chown -R apache:apache /var/www/html/*
    $ chmod -R 755 /var/www/html/
  5. Log in to MySQL as root and create a database for WordPress.
    $ sudo mysql -u root -p
    mysql> CREATE DATABASE wordpress_db;
  6. Create a new MySQL user and assign a password.
    mysql> CREATE USER 'wordpress_user'@'localhost' IDENTIFIED BY 'password';
  7. Grant the MySQL user privileges on the WordPress database.
    mysql> GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wordpress_user'@'localhost';
  8. Flush privileges and exit MySQL.
    mysql> FLUSH PRIVILEGES;
    mysql> EXIT;
  9. Copy the sample WordPress config file and rename it.
    $ sudo cp /var/www/html/wp-config-sample.php /var/www/html/wp-config.php
  10. Edit the WordPress config file with your database information and secure keys.
    $ sudo vim /var/www/html/wp-config.php
    // Set the following lines //
    define('DB_NAME', 'wordpress_db');
    define('DB_USER', 'wordpress_user');
    define('DB_PASSWORD', 'password');
    define('DB_HOST', 'localhost');

    Use the WordPress secret key generator at https://api.wordpress.org/secret-key/1.1/salt/ to generate security keys. Replace the placeholders with the generated values.

  11. Create an Apache configuration file for WordPress and enable mod_rewrite.
    $ sudo vim /etc/httpd/conf.d/wordpress.conf
    // Add the following configuration //
    <Directory "/var/www/html">
        AllowOverride All
    </Directory>
  12. Restart Apache to apply changes.
    $ sudo systemctl restart httpd
  13. Open your server’s IP address in a web browser to complete the WordPress setup.

    Navigate to http://your_server_ip/ in your browser.

  14. Set secure file permissions for WordPress directories and files.
    $ sudo find /var/www/html/ -type d -exec chmod 755 {} \;
    $ sudo find /var/www/html/ -type f -exec chmod 644 {} \;
  15. Disable file editing in the WordPress dashboard by updating the config file.
    $ sudo vim /var/www/html/wp-config.php
    // Add this line to disable file editing //
    define('DISALLOW_FILE_EDIT', true);
Discuss the article:

Comment anonymously. Login not required.