Install new CentOS server with VirtualMin Nginx And PHP (PHP-FPM)

virtualmin-nginx-and-phpVirtualmin is a powerful and flexible web hosting control panel for Linux and UNIX systems based on the well-known Open Source web-based systems management GUI, Webmin. Popular web server associating with PHP-based application is Apache, but Nginx is also a good replacement for high-traffic websites. This article discusses about how to install a new server with VirtualMin Nginx and PHP (PHP-FPM).

1. Install Webmin

  • create the /etc/yum.repos.d/webmin.repo file containing 
    name=Webmin Distribution Neutral
  •  fetch and install my GPG key with which the packages are signed, with the commands:
    rpm --import jcameron-key.asc
  • Install webmin with command:
    yum install webmin

2. Install Virtualmin

  • Create IP with hostname by adding the following line to /etc/hosts: 
    x.x.x.x server1
  • Verify hostname:
    hostname --fqdn
  • Install virtualmin:

3. Remove Apache and install Nginx

  • Shut down Apache with the command 
    • /etc/init.d/httpd stop ; service httpd off (on RHEL or CentOS),
    • or /etc/init.d/apache2 stop ; update-rc.d apache2 remove (on Debian).
  • Install Nginx with the command
    • yum install nginx (on RHEL or CentOS)
    • or apt-get install nginx (on Debian).
  • Start the Nginx webserver with the command
    • /etc/init.d/nginx start
  • Install Virtualmin’s Nginx plugin with the command
    • yum install wbm-virtualmin-nginx wbm-virtualmin-nginx-ssl (on RHEL or CentOS)
    • or apt-get install webmin-virtualmin-nginx webmin-virtualmin-nginx-ssl (on Debian).

4. Configure Virtualmin to use nginx

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

5. Using NginX

  • Once Nginx support has been configured, you should be able to create virtual servers just as you would with Apache. However, on the Create Virtual Server page you will need to select Enable Nginx website? in theEnabled features section, instead of Enable Apache.
  • When creating a domain from the command-line API, you will need to use the --virtualmin-nginx flag instead of--ssl . For SSL websites, you will need to use --virtualmin-nginx-ssl instead of --ssl .
  • Similarly, when creating a domain via the remote API, you will need to use the virtualmin-nginx= parameter instead of web= .

6. Install PHP-FPM

  • Install RHEL EPEL repository: 
    sudo rpm -Uvh remi-release-6*.rpm epel-release-6*.rpm
  • Install  spawn-fcgi if needed
    yum --enablerepo=remi install php-cli spawn-fcgi
  • Configure spawn-fcgi
    cd /opt
    wget -O
    mv /usr/bin/php-fastcgi
    chmod +x /usr/bin/php-fastcgi
    wget -O
    mv /etc/rc.d/init.d/php-fastcgi
    chmod +x /etc/rc.d/init.d/php-fastcgi
    # chkconfig --add php-fastcgi
    # chkconfig php-fastcgi on
    # /etc/init.d/php-fastcgi start
  • Install php-fpm:
    cd /etc/yum.repos.d
    yum --enablerepo=remi install php-fpm
    service php-fpm start
    chkconfig --add php-fpm
  • Done

About NhocConan

A super lazy guy who tries to write tech blog entries in English. He is lazy, so he can only write when he is in a good mood or when he is tired of coding.

Leave a comment

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