To install WordPress on CentOS 7, you can follow these steps:
- 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
- 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
- Secure your MySQL installation by running the following command:
sudo mysql_secure_installation
- 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;
- 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
- Configure WordPress by renaming the
wp-config-sample.php
file towp-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. - 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/
- 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>
- Restart Apache service using the following command:
sudo systemctl restart httpd
- 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.