How to Install WordPress on CentOS 7

To install WordPress on CentOS 7, you can follow these steps:

  1. Install LAMP stack – You need to install Apache, MySQL, and PHP on your CentOS 7 server. You can install all these components using the following command:
    sudo yum install httpd mariadb-server mariadb php php-mysql php-gd php-xml php-mbstring php-json
  2. Start and enable Apache and MySQL services using the following commands:
    sudo systemctl start httpd
    sudo systemctl enable httpd
    sudo systemctl start mariadb
    sudo systemctl enable mariadb
  3. Secure your MySQL installation by running the following command:
    sudo mysql_secure_installation
  4. Create a MySQL database and user for WordPress by logging into the MySQL shell using the following command:
    sudo mysql -u root -p

    Once you’re logged in, create a database for WordPress using the following command:

    CREATE DATABASE wordpress;

    Next, create a user and grant privileges to the database using the following commands:

    CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'password';
    GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost';
    FLUSH PRIVILEGES;
  5. Download and extract WordPress using the following commands:
    cd /var/www/html/
    sudo wget https://wordpress.org/latest.tar.gz
    sudo tar -xzvf latest.tar.gz
  6. Configure WordPress by renaming the wp-config-sample.php file to wp-config.php using the following command:
    sudo mv /var/www/html/wordpress/wp-config-sample.php /var/www/html/wordpress/wp-config.php

    Edit the wp-config.php file and enter the database details you created earlier, like database name, username, and password.

  7. Set appropriate file permissions using the following commands:
    sudo chown -R apache:apache /var/www/html/wordpress/
    sudo chmod -R 755 /var/www/html/wordpress/
  8. Create a virtual host configuration file for WordPress using the following command:
    sudo vi /etc/httpd/conf.d/wordpress.conf

    Add the following content to the file and save it:

    <VirtualHost *:80>
    ServerAdmin admin@example.com
    DocumentRoot /var/www/html/wordpress
    ServerName example.com
    ServerAlias www.example.com
    <Directory /var/www/html/wordpress/>
    AllowOverride All
    Require all granted
    </Directory>
    ErrorLog /var/log/httpd/wordpress_error.log
    CustomLog /var/log/httpd/wordpress_access.log combined
    </VirtualHost>
  9. Restart Apache service using the following command:
    sudo systemctl restart httpd
  10. Access your WordPress installation by visiting your server’s IP address or domain name in a web browser. Follow the prompts to complete the installation by entering your database credentials and setting up your WordPress administrator account.

That’s it! You should now have a working WordPress installation on your CentOS 7 server.