WordPress Mariadb Nginx On Centos 7


WordPress Mariadb Nginx On Centos 7

Installing Apache

Apache is the most popular web server in the world. It is a powerful, versatile, and free open source software available for most operating systems. CentOS 7 ships with Apache installed by default, and it is designed to work with the WordPress Mariadb Nginx stack that we will be using. To get started, we will install Apache using yum. First, make sure that your yum repositories are up to date:

sudo yum update

Then, install Apache with the following command:

sudo yum install httpd

Now that Apache is installed, we need to configure it to run properly with WordPress Mariadb Nginx. We will do this by editing the /etc/httpd/conf/http.conf file. Look for the and add the following lines, adjusting the AllowOverride directive to match your needs:

AllowOverride All
Order Allow,Deny
Allow from All

Next, we need to enable Apache to run at boot time. To do this, use the following command:

sudo systemctl enable httpd.service

Finally, start Apache with the following command:

sudo systemctl start httpd.service

Installing MariaDB

MariaDB is a fast and reliable open source database and will be the back-end data store for our WordPress Mariadb Nginx stack. To install MariaDB on CentOS 7, use the following command:

sudo yum install mariadb-server mariadb

Once the installation is complete, start MariaDB with the following command:

sudo systemctl start mariadb

To make sure MariaDB is running properly, check its status:

sudo systemctl status mariadb

In order for MariaDB to be secure, we need to run a few commands. First, we need to set a root password for MariaDB. To do this, use the mysql_secure_installation command. Follow the prompts to set a secure root password. Next, we need to set up a user and a database for WordPress. To do this, log in to MariaDB as the root user with the following command:

mysql -u root -p

Create a user and a database for WordPress with the following commands:

CREATE DATABASE wordpress;
CREATE USER wordpressuser@localhost IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost;

To make sure the commands have been executed successfully, use the FLUSH PRIVILEGES; command.

Installing Nginx

Nginx is a lightweight and high-performance web server. It is the ideal choice for WordPress Mariadb Nginx stack because it can handle a large amount of requests quickly. To install Nginx on CentOS 7, use the following command:

sudo yum install nginx

Once the installation is complete, start Nginx with the following command:

sudo systemctl start nginx

To make sure Nginx is running properly, check its status:

sudo systemctl status nginx

Next, we need to configure Nginx for WordPress Mariadb Nginx. The default Nginx configuration file for CentOS 7 is located in the /etc/nginx/conf.d directory. We need to create a new configuration file for WordPress. To do this, create a new file with the following command:

sudo vim /etc/nginx/conf.d/wordpress.conf

Add the following lines to the configuration file:

server {
listen 80;
server_name mydomain.com www.mydomain.com;
root /var/www/html/wordpress;
index index.php index.html index.htm;
location / {
try_files $uri /index.php?$args;
}
location ~ .php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}

Now, test the configuration file with the following command. If there are no errors, the configuration file is valid. If there are any errors, they will be outputted and you will need to fix them.

sudo nginx -t

Installing WordPress

WordPress is the content management system of choice for millions of websites and blogs. To install WordPress, we need to first obtain the latest version from the official website. To do this, download the WordPress .tar.gz archive and extract it with the following command:

tar xvf latest.tar.gz

Next, rename the extracted directory to WordPress with the following command:

mv wordpress-* wordpress

Now, we need to upload the WordPress files to the Apache document root directory. To do this, use the following command:

sudo mv wordpress/ /var/www/html/

Once the files have been uploaded, we need to update the ownership and permissions of the files. To do this, use the following commands:

sudo chown -R apache:apache /var/www/html/wordpress
sudo chmod -R 755 /var/www/html/wordpress

Now, we need to create a WordPress configuration file. To do this, copy the sample configuration file with the following command:

sudo cp /var/www/html/wordpress/wp-config-sample.php /var/www/html/wordpress/wp-config.php

Open the configuration file in an editor and add the MariaDB credentials as well as the salt keys. When you are done, save the file and exit the editor.

Installing and Configuring PHP

PHP is a server-side scripting language used for creating dynamic web pages. To install PHP on CentOS 7, use the following command:

sudo yum install php php-mysql

Once the installation is complete, start PHP-FPM with the following command:

sudo systemctl start php-fpm

To make sure PHP-FPM is running properly, check its status:

sudo systemctl status php-fpm

Now, we need to configure Nginx to use PHP-FPM. To do this