Virtualmin, PHP-FPM, NGINX module update! More support!

Hey I have been using Virtualmin for some time now and never really coded anything in Perl before. So I have been reading through the documentation and applying edits to the current module. I recently decided to install Virtualmin again within CentOS 7. After doing this I realised that I would have to configure files each time I created a server for PHP-FPM and Nginx to work together… I kinda wanted to automate this process and make a few changes to the current Nginx Virtualmin mod as I realised it doesn’t cater for a number of things.

With the updated plugin, for Nginx and Nginx SSL a few things that have been added and some fixes to the previous code are:
Allows multiple server blocks instead of just 1.
When backing up, if you have multiple server blocks for one domain it will backup both server blocks and restore them correctly.
When renaming the domain or changing IP address it will do this in all server blocks related to the domain.
I fixed some of the bugs when doing some renaming and editing of the Virtualhost. I did notice there were a few bugs.

This will automatically create a new php-fpm pool file for each virtual host created in php-fpm.d and configure the domains Nginx config file for PHP-FPM.
You can choose between using the old previous php-fcgi mode or php-fpm with both of them supporting socks and TCP connection.
You can choose which mode you wish to use and all configuration files will be setup accordingly.
Supports full backup and restore ability.

This also fix’s a lot of the Selinux permission issues automatically when creating a virtual host PHP-FPM and Nginx.

I have added a function to try and automatically detect which PHP-FPM version you are using and its location. If unable to detect you can got the module configration page and insert the location to your PHP-FPM directories manually.

This is the same for the start,stop and restart commands for PHP-FPM.
A lot has been done to the code but the overall result is this.

You can now create virtual hosts for a domain name and this will setup an Nginx config and PHP-FPM config automatically and your domain will be instantly usable by PHP.

If anyone would like to contribute the code and make improvements please do post!

This mod has actually taken a very long time to get right. So I would appreciate some feedback and if it worked for you as I have not been able to test in multiple environments. So you know my exact setup from start to finish, here is how to setup CentOS 7 with Webmin, Virtualmin, Nginx, PHP-FPM and MariaDB. Without going into too much detail. Remember this is a basic setup and you must secure your server after doing this!

Install Centos 7 minimal or what ever you prefer. This should also work with CentOS 6.

Update,Upgrade,remove old packages and clean CentOS

yum update
yum upgrade
yum autoremove
yum clean all

Install nano and wget
yum Install nano and wget

Install the Epel repository.
yum install epel-release

Install the Remi repository.
sudo rpm -Uvh remi-release-7*.rpm

Enable Remi and PHP56
nano /etc/yum.repos.d/remi.repo
set enabled=1 under [remi] and [remi-php56]

Create an Nginx Repository.
nano /etc/yum.repos.d/nginx.repo
Paste these lines with right click if using putty.
name=nginx repo

Ctrl + x and type y to save.

Create a Virtual Repository.
nano /etc/yum.repos.d/virtualmin.repo
Paste these lines with right click if using putty.
name=RHEL/CentOS/Scientific $releasever - $basearch - Virtualmin

name=Virtualmin Distribution Neutral Packages
Ctrl + x and type y to save.

Install Webmin and Virtualmin RPM keys
cd /etc/pki/rpm-gpg/
cd ~
wget && rpm --import jcameron-key.asc

Install Webmin.
yum install webmin
You can then login to webmin using your IP addesss
Once here you can use this chance to change the default port of Webmin and SSH.

Install Virtualmin
yum install wbm-virtual-server

Install MariaDB
yum install mariadb mariadb-server

After install go to Webmin -> servers -> virtual servers GPL and go through the setup. Once finished go to features and plugins and disable;
Apache website
Bind DNS
Mail for domain
Webalizer reporting

Install Nginx
yum install Nginx

Install the virtualmin nginx and virtualmin nginx ssl module that I have provided. Download the file, go to webmin -> webmin configuration -> webmin modules and install the module from the download you may want to click enable for all users also.

Install php56
yum install php56 php56-php-xml php56-php-gd php56-php-imap php56-php-mysql php56-php-odbc php56-php-pear php56-php-snmp php56-php-xmlrpc php56-php-mbstring php56-php-fpm php56-php-mcrypt

Once all this is installed don’t forget to run mysql_secure_installation

So once we have finished installing and setting up everything we now need to make sure we have disabled the plugins and features listed above.
You also need to check Virtualmin configuration and setup what Virtualmin will be used for.

Head over to Virtualmin -> System Settings -> Features and plugins and click on configure on Nginx website. Execute PHP scripts using PHP-FPM, check this radio box.
You can setup the paths and commands to php-fpm if you know them but it will attempt to get them automatically on first creation of virtual server and save them for you.

Also is best to use a directory for new virtual hosts so check “File or directory for new virtual hosts” and insert a location such as /etc/nginx/conf.d
Save and then create your first virtual host.

You should notice a new conf file inside your Nginx conf.d directory and your php-fpm.d directory and that’s pretty much it for setting up nginx and php-fpm automatically.

Here is a screenshot of my setup configuration for Nginx.

I plan on adding a panel for php-fpm to edit zones and configuration panels easily with a gui. I already started to code a panel.

I may of missed some things out also all comments and replies are welcome!

More info or questions can be answered @

How to do NGINX, MariaDB on Ubuntu?

Use the automated standard Virtualmin install script, and then install and switch the web server and the database server to your preferences. Doing it manually would work, but is unnecessary complexity.

i’m interested to try this on centos 7.3, but i’m new to virtualmin. some questions:

  • what would you do if you wanted php7? which repo would you get it from? ( then would you setup symlinks (cd /bin; ln -s php-70 php; ln -s php-70-cgi php-cgi, etc)?
  • in step 13, when you disable Mail for domain, does that mean this domain can’t send and receive email? or is roundcube/dovecot a separate matter than this “Mail for domain”?
  • in step 13, when you disable “DNS domain enabled”, is this affecting > Webmin > Servers > BIND DNS server? Or is it just for the specific domain?

also, what are your thoughts on roland’s work on nginx as reverse proxy?

under Configure Virtualmin, he’s listed a script that will automate the creation of website virtual host Nginx configuration file each time Virtualmin created a new server.

he’s setting things up for drupal in mind, but i guess i could replace drupal with wordpress and adjust accordingly

thank you!