141 views0November 30, 2022Updated on February 1, 2023host_know_user
Introduction
PHP and MySQL are used by WordPress, a free and open source blogging and website building platform. The most widely used content management system (CMS) on the Internet right now is WordPress, which has over 20,000 plugins to increase its functionality. This makes WordPress a fantastic option for easily and rapidly launching a website.
This tutorial will show you how to set up a WordPress instance on CentOS 7 with an Apache web server.
Prerequisites
There are a few things that need to be done before you start using this guide.
You’ll need a CentOS 7 server with a non-root user with sudo privileges installed and set up.
A LAMP stack installed on your server
You can carry on with the WordPress installation after completing these steps.
Step 1: Create a WordPress user and MySQL database.
Preparation is the first action we’ll take. Information for the website and its users is managed by WordPress using a relational database. This feature can be provided by MariaDB, a derivative of MySQL, which is already installed. However, we must create a database and a user for WordPress to use.
Start by entering the following command to log into the root (administrative) account of MySQL:
# mysql -u root –p
The root account password that you specified when installing MySQL will be required when you are prompted. After you enter that password, a MySQL command prompt will appear.
We’ll first build a fresh database that WordPress can manage. You can give this any name you wish, but for the purposes of this example, I’ll use wordpress.
# CREATE DATABASE wordpress;
Note: If you encounter any problems, double-check that there is a semicolon (;) at the end of every MySQL statement or command.
The next step is to create a fresh MySQL user account that will only be used to manage the brand-new WordPress database. It is a good idea to create databases and accounts with a single purpose because this enables better control over permissions and other security requirements.
The new account will be given the name “wordpressuser,” and I’ll give it the password “password.” Since the username and password used in these examples are not very secure, you should definitely use something else.
CREATE USER wordpressuser@localhost IDENTIFIED BY 'password';
You currently have a database and user account that were both created especially for WordPress. The user cannot access the database, though. By giving our user access to the database, we can connect the two elements.
GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost IDENTIFIED BY 'password';
We must flush the privileges now that the user has access to the database so that MySQL is aware of the most recent privilege modifications we’ve made:
FLUSH PRIVILEGES;
When all of these operations have been carried out, we can leave the MySQL command prompt by typing:
exit
You ought to now be at the standard SSH command prompt.
Step 2: Install WordPress
One PHP module needs to be installed before we download WordPress in order for it to function properly. WordPress won’t be able to resize photos to make thumbnails without this module. Using yum, we can obtain that package straight from the CentOS default repositories:
# sudo yum install php-gd
In order for Apache to recognise the new module, we must now restart it:
# sudo service httpd restart
We are now prepared to access the project website, download, and install WordPress. We can access the most recent version of WordPress by typing this because the WordPress team consistently links the most recent stable version of their software to the same URL:
cd ~
wget http://wordpress.org/latest.tar.gz
This will download an archive file that is compressed and contains every WordPress file we require. With the aid of tar, we can extract the archived files and rebuild the WordPress directory:
tar xzvf latest.tar.gz
Your home directory will now contain a directory with the name “wordpress.” By moving the unzipped files to Apache’s document root, where they can be served to website visitors, we can complete the installation. With rsync, we can move our WordPress files there while keeping the files’ default permissions:
sudo rsync -avP ~/wordpress/ /var/www/html/
The whole contents of the directory you unzipped will be carefully copied by rysnc to the document root at /var/www/html/. Yet another folder that WordPress can use to store uploaded files has to be added. The mkdir command will enable us to do that:
mkdir /var/www/html/wp-content/uploads
Now we must give our WordPress files and folders the appropriate ownership and rights. This will improve security while maintaining WordPress’s intended functionality. To accomplish this, we’ll use chown to give Apache’s user and group ownership:
sudo chown -R apache:apache /var/www/html/*
With this modification, the web server will now have the ability to create and modify WordPress files as well as enable content uploading.
Step 3: Configure WordPress
Later, a web interface will be used to complete the majority of WordPress settings. To make sure that WordPress can connect to the MySQL database that we set up for it, we must perform several tasks from the command line.
Enter the Apache root directory where WordPress was installed first:
# cd /var/www/html
WordPress’s primary configuration file is known as wp-config.php. The default installation comes with a sample configuration file that largely matches the settings we require. To enable WordPress to identify and utilise the file, all we need to do is copy it to the place designated by default for configuration files:
cp wp-config-sample.php wp-config.php
Let’s open the configuration file we now have to deal with in a text editor:
nano wp-config.php
The parameters that hold the data from our database are the only parts of this file that need to be changed. The DB NAME, DB USER, and DB PASSWORD variables must be changed in the MySQL settings section for WordPress to successfully connect and authenticate to the database that we built.
With the data from the database you established, fill in the values of these parameters. It should seem as follows:
// ** MySQL settings – You can get this info from your web host ** // /** The name of the database for WordPress */ define(‘DB_NAME’, ‘wordpress’);
/** MySQL database username */ define(‘DB_USER’, ‘wordpressuser’);
/** MySQL database password */ define(‘DB_PASSWORD’, ‘password’);
You just need to edit these settings, so save the file when you are done and then close it.
Step 4: Finish the installation process using the web interface
You can finish installing WordPress using the online interface once your files are ready and your software is set up. Go to the public IP address or domain name of your server in your web browser:
http://server_domain_name_or_IP
You must first choose the language in which you want to install WordPress. You will be taken to the WordPress first configuration screen after choosing a language and pressing Continue, where you will establish an initial administrator account:
Complete the necessary fields to create an administrative account for the site. When finished, proceed by clicking the Install WordPress button at the bottom.
WordPress will confirm the installation before prompting you to log in using the newly created account:
To proceed, click the Log in link at the bottom and then enter your administrator account details as follows:
You will see your new WordPress dashboard after clicking Log in:
Conclusion
On your CentOS 7 server, a WordPress instance ought to be active right now.