WordPress Hosting – Install PHP7, Nginx and Virtualmin on CentOS 7.2

install php7 wordpress and nginx

PHP 7 is out for an while and it brings a lot of new features and performance increase for runnign sites. I have a couple of droplets on DigitalOcean but they are on CentOS 6 and PHP 5.5, as the server has not been updated for a long time I want to create a new DigitalOcean droplet install the CentOS 7.2 with PHP 7 and Virtualmin to move the sites slowly there and see how the performance is working.

In this first article I will install PHP7 and Virtualmin and make the necessary configurations to the server.

1.Create the DigitalOcean Droplet with choosing the CentOS 7 and the data center is.

dig 1

gidiag 2

2. Login to the server with SSH perform the update and install the Virtualmin with PHP7

To be able to access the server with SSH you will need to download an SSH client like putty use the password from the email sent by digitalocen and login to the server. Once loged in just follow the below steps:

  • Upgrade centOS
yum update
yum upgrade
  • Upgrade the repo to get php7
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
  • Get Virtualmin and install it
wget http://software.virtualmin.com/gpl/scripts/install.sh -O /root/virtualmin-install.sh
cd /root/
chmod +x virtualmin-install.sh
yum install perl
  • Now the Virtual min is installed but is using the php5, next we will need to deinstall php5 and install php7
yum remove php-cli mod_php php-common
yum install mod_php70u php70u-cli php70u-mysqlnd
yum install php70w php70w-opcach
yum install php70w-fpm php70w-opcache
yum install php70w-mysql php70w-xml php70w-soap php70w-xmlrpc
  • Check the php version:
php -v

Now you can access the Virtualmin with https://<IP>:10000 and the GUI should be displayed.

3. Installing and configurating NGINX 1.9.11 or the last version

By default Virtualmin is comming with Apatch installed which is more slow then nginx. In this part you will see how to install and configure NGINX with PHPCGI to have an fast site.

  • Stop httpd
systemctl stop httpd
systemctl disable httpd
  • Use the last NGINX repo and install it
rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
[root@ns1 ~]# sudo vi /etc/yum.repos.d/nginx.repo
# nginx.repo

name=nginx repo
yum -y install nginx

----Start Nginx
 systemctl start nginx
  • So virtualmin to work with NGINX install the below:
yum install wbm-virtualmin-nginx wbm-virtualmin-nginx-ssl

4. Configure Virtualmin

  1. Login to Virtualmin as root, and go to Webmin -> Servers -> Nginx Webserver and make sure that Nginx and its configuration files are found.
  2. If not, click on the Module Config link and set the config and command paths correctly.
  3. Return to Virtualmin, and go to System Settings -> Features and Plugins.
  4. Un-check the “Apache website” , “SSL website” and “DAV Login”, “Mailman”, “Protected web directories”, “AWstats reporting” and “Subversion repositories” features.
  5. Check the “Nginx website” and “Nginx SSL website” features, then click “Save”.
  6. If Virtualmin reports that any other features cannot be used without Apache, go back and de-select them too.
  7. Go to the System Information page and click Refresh system information in the top right.
  8. Verify that Nginx is shown as running in the “Status” section.

5. Some Nginx  performance tweaks for WordPress

I am not realy and expert but I am using the below configurations for my NGINX server to host multiple WordPress sites and I never had an problem also the speed is very good.  You can use them also on your server, just follow the below points.

  • Open with editor the /etc/nginx/nginx.conf
cd /etc/nginx/
vi nginx.conf
  • my nginx.conf is as below you can modify it to be the same
user  nginx;
worker_processes  10;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;

http {
    fastcgi_buffers 31 16k;
    fastcgi_buffer_size 32k;
    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    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;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    client_max_body_size 20M;
    include /etc/nginx/conf.d/*.conf;
         server_names_hash_bucket_size 128;
         # Gzip Settings
         gzip  on;
         gzip_http_version 1.1;
         gzip_vary on;
         gzip_comp_level 6;
         gzip_proxied any;
         gzip_types text/plain text/css application/json  application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript text/x-js;
         gzip_buffers 16 8k;
         gzip_disable "MSIE [1-6]\.(?!.*SV1)";
        tcp_nopush off;
        tcp_nodelay on;

        server {
------Here it comes the part with the domains installed
  • Addidionaly I have created an drconf dir under /etc/nginx/ and added 2 files:
[root@ns1 drconf]# pwd
[root@ns1 drconf]# ls -ltr
total 8
-rw-r--r-- 1 root root 774 Feb 22 10:45 wpsecure.conf
-rw-r--r-- 1 root root 162 Feb 22 10:46 wpnocache.conf
[root@ns1 drconf]#

  • Below are the details you can use them
[root@ns1 drconf]# cat wpsecure.conf
# Deny access to any files with a .php extension in the uploads directory
# Works in sub-directory installs and also in multisite network
location ~* /(?:uploads|files)/.*\.php$ {
        deny all;

# Make sure files with the following extensions do not get loaded by nginx because nginx would display the source code, and these files can contain PASSWORDS!
location ~* \.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(\..*|Entries.*|Repository|Root|Tag|Template)$|\.php_
        return 444;

location ~* \.(pl|cgi|py|sh|lua)\$ {
        return 444;

    location ~* (roundcube|webdav|smtp|http\:|soap|w00tw00t) {
        return 444;

location ~ /(\.|wp-config.php|readme.html|license.txt) { deny all; }
[root@ns1 drconf]# cat wpnocache.conf
#Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
location ~*  \.(jpg|jpeg|png|gif|ico|css|js)$ {
   expires 10d;
  • Restart Nginx
systemctl stop nginx
systemctl start nginx
  • When an website is added you will need to add the below :
  location / {
                         include /etc/nginx/drconf/wpsecure.conf;
                         include /etc/nginx/drconf/wpnocache.conf;

                         try_files $uri $uri/ /index.php?q=$request_uri;

Here is an complete example:

 server {
                server_name wpdoze.com www.wpdoze.com;
                root /home/wpdoze/public_html;
                index index.html index.htm index.php;
                access_log /var/log/virtualmin/wpdoze.com_access_log;
                error_log /var/log/virtualmin/wpdoze.com_error_log;
                fastcgi_param GATEWAY_INTERFACE CGI/1.1;
                fastcgi_param SERVER_SOFTWARE nginx;
                fastcgi_param QUERY_STRING $query_string;
                fastcgi_param REQUEST_METHOD $request_method;
                fastcgi_param CONTENT_TYPE $content_type;
                fastcgi_param CONTENT_LENGTH $content_length;
                fastcgi_param SCRIPT_FILENAME /home/wpdoze/public_html$fastcgi_script_name;
                fastcgi_param SCRIPT_NAME $fastcgi_script_name;
                fastcgi_param REQUEST_URI $request_uri;
                fastcgi_param DOCUMENT_URI $document_uri;
                fastcgi_param DOCUMENT_ROOT /home/wpdoze/public_html;
                fastcgi_param SERVER_PROTOCOL $server_protocol;
                fastcgi_param REMOTE_ADDR $remote_addr;
                fastcgi_param REMOTE_PORT $remote_port;
                fastcgi_param SERVER_ADDR $server_addr;
                fastcgi_param SERVER_PORT $server_port;
                fastcgi_param SERVER_NAME $server_name;
                fastcgi_param HTTPS $https;
                location ~ \.php$ {
                        try_files $uri =404;
                        fastcgi_pass unix:/var/php-nginx/145616819715529.sock/socket;
  location / {
                         include /etc/nginx/drconf/wpsecure.conf;
                         include /etc/nginx/drconf/wpnocache.conf;

                         try_files $uri $uri/ /index.php?$args;


This are all the configurations needed to have an CentOS 7.2 VPS server running with PHP7 /NGINX and Virtualmin/Webmin. I have it running for coupe off days and the results are very good. The site is loading very fast even without an CDN, here are some results:

WPDOZE with content and a lot off plugines installed:


    1. Liew CheonFong March 25, 2016
      • admin March 25, 2016
        • Baka97 June 23, 2016
          • admin June 23, 2016
    2. Oliver March 31, 2016
    3. BryanTech June 5, 2016
    4. Madu August 17, 2016
      • admin August 17, 2016
    5. Ahmed Rifshaan March 5, 2017
      • admin March 6, 2017

    Add Your Comment