Logo

How To Install WordPress with LAMP on CentOS 7

Apr 04, 2024

To install WordPress with LAMP on CentOS 7, follow the steps below:

Step 1 : Install LAMP Stack

If you haven't installed LAMP (Linux, Apache, MySQL, PHP) yet, you can follow this guide: CentOS 7 Guides.

Step 2 : Login to MySQL and create a new user and database for WordPress:

mysql -u root -p
CREATE DATABASE wordpress;
CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Step 3 : Download and Install WordPress

- Create a directory for your WordPress installation:

sudo mkdir /var/www/html/example.devtutorial.io
cd /var/www/html/example.devtutorial.io

- Download the latest version of WordPress and extract it:

wget https://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz

- Move WordPress files to the desired location and set permissions:

sudo mv wordpress/* ./
sudo chown -R apache:apache /var/www/html/example.devtutorial.io/
sudo chmod -R 755 /var/www/html/example.devtutorial.io/

- Clean up:

rm -rf wordpress latest.tar.gz

Step 4 : Create a virtual host configuration file for your WordPress site:

sudo nano /etc/httpd/conf.d/example.devtutorial.io.conf

Add the following configuration:

<VirtualHost *:80>
    ServerAdmin webmaster@devtutorial.io
    DocumentRoot /var/www/html/example.devtutorial.io
    ServerName example.devtutorial.io

    ErrorLog /var/log/httpd/example.devtutorial.io_error.log
    CustomLog /var/log/httpd/example.devtutorial.io_access.log combined

    <Directory /var/www/html/example.devtutorial.io>

        AllowOverride All

    </Directory>

</VirtualHost>

Save and close the file.

Step 5 : Test the Apache configuration for syntax errors:

sudo apachectl configtest

If no errors are reported, restart Apache:

sudo systemctl restart httpd

Step 6 : If SELinux is enabled, run the following command to allow Apache to write to the WordPress directories:

sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/example.devtutorial.io(/.*)?"
sudo restorecon -Rv /var/www/html/example.devtutorial.io

Step 7 : Open your browser and navigate to the link to install WordPress. Follow the on-screen instructions to set up WordPress:

- Visit http://example.devtutorial.io in your web browser.

- Select your preferred language.

- Click "Let's go!" and enter the database information you created earlier.

- If the information is correct, click "Run the installation."

- Enter your WordPress information and click "Install WordPress."

Step 8 : After installation, log in to your WordPress dashboard using the credentials you set up.

Step 9 : Explore the Dashboard

Congratulations! You have successfully installed WordPress on CentOS 7.