Setup Nginx server with latest Mariadb and latest PHP 5.6
CentOS 7 (with root user)
Step 1: Installing Remi Repository
# yum update && yum install epel-release
# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
Install locate function to find the location of files
# yum install mlocate
# updatedb
Install Vim to edit file easily
# yum install vim
Step 2: Enabling the Remi Repository
Now you make sure that remi repository is enabled and all set to install chosen PHP version, to do this open remi.repo file and make sure the line set to enabled=1 as instructed below, in order to install PHP 5.5 or 5.6.
[remi]
name=Remi's RPM repository for Enterprise Linux 6 - $basearch
#baseurl=http://rpms.remirepo.net/enterprise/6/remi/$basearch/
mirrorlist=http://rpms.remirepo.net/enterprise/6/remi/mirror
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
Step 3: Install Nginx
#yum install nginx
Start Nginx on your VPS
# systemctl start nginx
Enable Nginx to start on boot
# systemctl enable nginx
Step 4: Install Mariadb
For MariaDB Installation on RHEL/CentOS 7 and Fedora 18-24
To enable the MariaDB repository on RHEL/CentOS 7 distributions, create a file named /etc/yum.repos.d/mariadb.repo with the following contents:
# vi /etc/yum.repos.d/mariadb.repo
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.2.6/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
After enabling MariaDB repository, then do:
# yum install mariadb-server mariadb
# systemctl start mariadb
# mysql_secure_installation
# systemctl enable mariadb
Step 5: Install PHP
# yum install php php-mysql php-fpm
Install php extensions
# yum install php-pcre php-mbstring php-mcrypt php-spl php-ctype php-openssl php-intl php-dom
Configure the PHP Processor
# vim /etc/php.ini
What we are looking for in this file is the parameter that sets cgi.fix_pathinfo. This will be commented out with a semi-colon (;) and set to "1" by default.
This is an extremely insecure setting because it tells PHP to attempt to execute the closest file it can find if a PHP file does not match exactly. This basically would allow users to craft PHP requests in a way that would allow them to execute scripts that they shouldn't be allowed to execute.
We will change both of these conditions by uncommenting the line and setting it to "0" like this: cgi.fix_pathinfo=0
Save and close the file when you are finished.
Next, open the php-fpm configuration file www.conf:
# vim /etc/php-fpm.d/www.conf
Find the line that specifies the listen parameter, and change it so it looks like the following:
# listen = /var/run/php-fpm/php-fpm.sock
Next, find the lines that set the listen.owner and listen.group and uncomment them. They should look like this:
# listen.owner = nobody
# listen.group = nobody
# listen.mode = 0666
Lastly, find the lines that set the user and group and change their values from "apache" to "nginx":
# user = nginx
# group = nginx
Then save and quit.
Now, we just need to start our PHP processor by typing:
# systemctl start php-fpm
This will implement the change that we made.
Next, enable php-fpm to start on boot:
# systemctl enable php-fpm
Step 6: Configure Nginx to Process PHP Pages
Now, we have all of the required components installed. The only configuration change we still need to do is tell Nginx to use our PHP processor for dynamic content.
We do this on the server block level (server blocks are similar to Apache's virtual hosts). Open the default Nginx server block configuration file by typing:
# vim /etc/nginx/conf.d/default.conf
The changes that you need to make are in red in the text below. If you prefer, you may just copy and paste everything, then replace the value of server_name with the appropriate domain name or IP address:
server {
listen 80;
server_name server_domain_name_or_IP;
# note that these lines are originally from the "location /" block
root /usr/share/nginx/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
When you've made the above changes, you can save and close the file.
Restart Nginx to make the necessary changes:
# systemctl restart nginx
Final step: Step Five — Test PHP Processing on your Web Server
In order to test that our system is configured properly for PHP, we can create a very basic PHP script.
We will call this script info.php. In order for Apache to find the file and serve it correctly, it must be saved to a very specific directory, which is called the "web root".
In CentOS 7, this directory is located at /usr/share/nginx/html/. We can create the file at that location by typing:
# vi /usr/share/nginx/html/info.php
This will open a blank file. We want to put the following text, which is valid PHP code, inside the file:
Test PHP Script
<?php phpinfo(); ?>
Revisions
- June 16, 2017 @ 11:39:48 [Current Revision] by Sharing Solution
- June 16, 2017 @ 11:39:48 by Sharing Solution
Revision Differences
There are no differences between the June 16, 2017 @ 11:39:48 revision and the current revision. (Maybe only post meta information was changed.)
No comments yet.