Centos 7 Install Nginx Php Mariadb


Centos 7 Install Nginx Php Mariadb

Installing Centos 7 for Nginx

CentOS 7 is one of the most widely used linux distributions for web servers, and it is an ideal platform for installing and running Nginx. To start, download the ISO file for Centos 7 from the Centos website and then burn it to a DVD or use it to create a bootable USB drive. Once you have the media ready, boot your server from the media and follow the on-screen instructions to install Centos 7. When the installation is complete, log in and start configuring your server.

Installing Nginx on Centos 7

To install Nginx on Centos 7, you will need to use the yum command. First, you need to add the EPEL repository to your Centos 7 server. You can do this by running the following command:

sudo yum install epel-release

Next, you need to update your system’s package repository. To do this, run the following command:

sudo yum update

After the update has finished, you can now install Nginx by running the following command:

sudo yum install nginx

Once the installation is complete, you can start Nginx by running the following command:

sudo systemctl start nginx

Nginx should now be running and you can check it by running the following command:

sudo systemctl status nginx

Installing PHP on Centos 7

In order to serve dynamic content, you need to install PHP on your Centos 7 server. To do this, you will need to use the yum command again. First, you will need to add the Remi repository to your Centos 7 server. You can do this by running the following command:

sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

Next, you need to enable the Remi repository by running the following command:

sudo yum –enablerepo=remi install php php-fpm

Once the installation is complete, you need to configure PHP-FPM by editing the php-fpm configuration file. To do this, you can run the following command:

sudo nano /etc/php-fpm.d/www.conf

Once you have made the necessary changes, you need to restart php-fpm by running the following command:

sudo systemctl restart php-fpm

Installing MariaDB on Centos 7

Finally, you need to install MariaDB on your Centos 7 server. To do this, you will need to use the yum command again. First, you need to install the MariaDB repository by running the following command:

sudo yum install mariadb-server

Next, you need to start MariaDB by running the following command:

sudo systemctl start mariadb

Once the installation is complete, you need to secure your MariaDB installation by running the following command:

sudo mysql_secure_installation

Follow the on-screen instructions to complete the installation. Once you are done, MariaDB should be installed and running on your Centos 7 server.

Configuring Nginx with PHP and MariaDB

Once you have installed Nginx, PHP, and MariaDB on your Centos 7 server, you need to configure them to work together. First, you need to configure the virtual host for your domain. To do this, you can create a virtual host configuration file in the /etc/nginx/conf.d/ directory.

Once you have created the virtual host file, you need to edit it and add the following lines:

server {
listen 80;
server_name example.com;
root /usr/share/nginx/html;

location / {
index index.html index.htm index.php;
}

location ~ .php$ {
include /etc/nginx/fastcgi_params;
fastcgi_index index.php;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}

Once you have added the above code to the virtual host file, you need to save it and then restart Nginx by running the following command:

sudo systemctl restart nginx

This will allow Nginx to use PHP and MariaDB when serving requests for the domain that you configured in the virtual host file.

Testing the Configuration

Once you have completed all of the configuration steps, you need to test it to make sure everything is working as expected. To do this, you need to create a file called info.php in the root directory of your domain. You can create this file by running the following command:

sudo nano /usr/share/nginx/html/info.php

Once you have created the file, you need to add the following code to it:

Save the file and then open it in a web browser. You should now be able to see the PHP info page, which should indicate that PHP is running and that it is using the MariaDB database.

Conclusion

In this guide, we have shown you how to install and configure Nginx, PHP, and MariaDB on a Centos 7 server. We have also shown you how to test the configuration to make sure everything is working properly. We hope this guide has been helpful to you. Thank you for reading this article.

Thank you for reading this article

We hope this article has been helpful to you. If you would like to learn more about installing and configuring web servers, please check out our other articles. Thank you for reading.

Leave a Reply

Your email address will not be published. Required fields are marked *