Looking for CentOS help? Visit our CentOS 7 help and tutorials page.

In this tutorial, we will show you how to install Varnish cache and phpMyAdmin on a CentOS 7 VPS with Nginx, MariaDB and PHP-FPM. Varnish cache is a web application accelerator created for speeding up dynamic web sites. phpMyAdmin is an open-source web application, created to handle the administration of MySQL databases through a web browser. Use the following article to install Nginx, MariaDB and PHP-FPM on a CentOS 7 VPS.

Then, it is time to install Varnish and phpMyAdmin.

Enable EPEL Repository:

rpm -Uvh http://dl.fedoraproject.org/pub/epel/beta/7/x86_64/epel-release-7-0.2.noarch.rpm
yum update
yum install varnish phpMyAdmin

Create a self-signed SSL Certificate so you can access phpMyAdmin using SSL:

mkdir -p /etc/nginx/ssl
cd /etc/nginx/ssl
openssl genrsa -des3 -out server.key 1024
openssl req -new -key server.key -out server.csr
cp server.key server.key.org
openssl rsa -in server.key.org -out server.key
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

Configure Varnish to run on port 80 while Nginx on port 8080 and pass the SSL requests straight through to Nginx web server without having to pass it through Varnish. Modify the main Nginx configuration file:

vi /etc/nginx/nginx.conf
user  nginx;
worker_processes  2;

error_log  /var/log/nginx/error.log;

pid        /run/nginx.pid;

events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;

    keepalive_timeout  60;

    include /etc/nginx/conf.d/*.conf;

    index   index.html index.htm;

    server {
        listen  127.0.0.1:8080;
        root         /usr/share/nginx/html;
        location / {
        }

        error_page  404              /404.html;
        location = /40x.html {
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
        }

    location ~ \.php$ {
      root   /usr/share/nginx/html;
      fastcgi_split_path_info  ^(.+\.php)(.*)$;
      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;
}
    }


server {
    listen       443;

    ssl                  on;
    ssl_certificate      /etc/nginx/ssl/server.crt;
    ssl_certificate_key  /etc/nginx/ssl/server.key;

    ssl_session_timeout  5m;

    ssl_protocols  SSLv2 SSLv3 TLSv1;
    ssl_ciphers  HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers   on;

location / {
root   html;
index  index.html index.htm;
}
location ~* ^/phpMyAdmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ { root /usr/share/;
}

location ~ \.php$ {
      root   /usr/share/nginx/html;
      fastcgi_split_path_info  ^(.+\.php)(.*)$;
      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;
}
}
}

Open ‘/etc/php-fpm.d/www.conf’ and add/modify the following lines:

vi /etc/php-fpm.d/www.conf
listen = /var/run/php-fpm/php-fpm.sock
user = nginx
group = nginx

Edit the ‘/etc/varnish/default.vcl’ file and add/modify the following lines:

vi /etc/varnish/default.vcl
backend default {
    .host = "127.0.0.1";
    .port = "8080";
}

Edit the ‘/etc/varnish/varnish.params’ file:

vi /etc/varnish/varnish.params
VARNISH_LISTEN_ADDRESS=your_IP
VARNISH_LISTEN_PORT=80

Make sure to change ‘your_IP’ with your actual server IP address.
Enable varnish service to start automatically on server boot using the following command:

systemctl enable varnish.service

Edit the ‘/etc/phpMyAdmin/config.inc.php’ phpMyAdmin configuration file and modify the following line:

vi /etc/phpMyAdmin/config.inc.php

$cfg['Servers'][$i]['auth_type']     = 'http';

Edit ‘php.ini’ and change the ‘session.save_path’ default value to ‘/var/lib/php/session’:

php -i | grep php.ini
Configuration File (php.ini) Path => /etc
Loaded Configuration File => /etc/php.ini
vi /etc/php.ini
session.save_path = "/var/lib/php/session"

Change the ownership of ‘/var/lib/php/session’ directory on your CentOS 7 VPS:

chown -R nginx:nginx /var/lib/php/session

Restart php-fpm, nginx and varnish services:

systemctl restart php-fpm
systemctl restart nginx
systemctl restart varnish

To verify that the Varnish cache is working, check the HTTP response headers:

curl -I http://your_IP

HTTP/1.1 200 OK
Server: nginx/1.6.1
Date: Sat, 16 Aug 2014 00:35:10 GMT
Content-Type: text/html
Last-Modified: Fri, 15 Aug 2014 19:27:58 GMT
ETag: "53ee5f3e-e74"
X-Varnish: 2
Age: 0
Via: 1.1 varnish-v4
Content-Length: 3700
Connection: keep-alive

Open https://your_IP/phpMyAdmin/index.php , enter your MariaDB username and password, and start managing your MariaDB databases.
That’s All Enjoy.

Note: if you’re looking for cheap VPS hosting, VPSCheap has got you covered 😉

 

Untitled-3

Facebooktwittergoogle_plusredditpinterestlinkedinmail