Install Nginx Php5.6 Mysql Centos 7


Install Nginx Php5.6 Mysql Centos 7

Requirements

Before we get started, let us go through the system requirements to install Nginx, Php5.6 and MySQL on CentOS 7.

  • CentOS 7
  • Root user
  • Enough disk space and memory
  • SSH client

All the packages needed for installing these elements will be downloaded from the official CentOS repositories.

Installation of Nginx

First, we will install Nginx from the official CentOS repositories. To do this, we need to use either yum or dnf. The exact command for using yum for installing the Nginx package is given below:


$ yum install nginx

Once the command is successfully executed, you will see the installation process, and at the end, you will receive a notification that the installation was successful.

Nginx is now installed, but it won’t start automatically. To start it, use the following systemctl command:


$ systemctl start nginx

If you want to make sure that the service is running, you can do a check on it using the status command.


$ systemctl status nginx

Installation of Php5.6

To install Php5.6 on CentOS 7, we need to use either yum or dnf. The exact command for using yum for installing the Php5.6 package is given below:


$ yum install php56

Once the command is successfully executed, you will see the installation process, and at the end, you will receive a notification that the installation was successful.

The next step is to install additional packages that are necessary for running web applications. These packages can be installed with the following command:


$ yum install php56-pdo php56-mysqlnd php56-xml

Once the command is successfully executed, you will see the installation process, and at the end, you will receive a notification that the installation was successful.

Installation of MySQL

To install MySQL on CentOS 7, we need to first use the yum command like we did for installing Nginx and Php5.6. The exact command for using yum for installing the MySQL package is given below:


$ yum install mysql-server

Once the command is successfully executed, you will see the installation process, and at the end, you will receive a notification that the installation was successful.

Next, you need to start MySQL by using the following command:


$ systemctl start mysqld

The last step is to secure MySQL by creating a root password. To do this, use the following command:


$ mysql_secure_installation

Configuring Nginx

Now that we have installed all the necessary components, we need to configure Nginx. To do this, we will be creating a virtual host file.

First, make sure that you have the default Nginx configuration file in the following path:


/etc/nginx/conf.d/default.conf

Once you have the file in place, edit it with a text editor of your choice and then add the following code to it:


server {
listen 8080;
server_name domain.tld www.domain.tld;
root /srv/domain.tld/httpdocs;
index index.html index.htm;
location / {
include fastcgi_params;
try_files $uri /index.php?$query_string;
fastcgi_pass 127.0.0.1:9000; #this value might be different for you
}
error_page 404 /404.html;
location = /404.html {
root /srv/domain.tld/httpdocs;
}
location ~ .php$ {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000; #this value might be different for you
}
}

This code needs to be modified with your own parameters (domain name, IP address, etc). Once you have done that, you need to save the file and restart Nginx. To do that, use the following command:


$ systemctl restart nginx

Testing the Setup

Now that we have installed and configured everything, it is time to test the setup. To do this, first create a file in the /srv/domain.tld/httpdocs directory and name it index.php. Then add the following code to it:


echo phpinfo();
?>

This code will generate information about the version of PHP you are using. Now, visit the domain in a browser and you should see the PHP information page. If you see it, then you have successfully installed Nginx, Php5.6 and MySQL on CentOS 7!

Conclusion

In this article, we have gone through the process of installing and configuring Nginx, Php5.6 and MySQL on CentOS 7. We have also seen how to create a virtual host file and how to test the setup.

Thank you for reading this article. Please read other articles for more interesting and informative topics.

Leave a Reply

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