PHP and Virtualmin

This legacy document is here only to insure incoming links continue to work. You likely want to start with the new documentation index or search for what you want to know about. This document is unmaintained!
  • This legacy document is here only to insure incoming links continue to work. You likely want to start with the new documentation index or search for what you want to know about. This document is unmaintained!

    Virtualmin Professional includes a complete application deployment stack for both PHP version 4 (note that PHP 4 has been End-of-Lifed by the PHP developers, and should be used only as a last resort, or when the package is provided by your OS vendor, as in the case of CentOS/RHEL 4) and PHP version 5. Through the use of mod_fcgid, suexec, and php-cgi, it is possible to execute scripts compatible with either or both versions of PHP.

    PHP Execution Architecture

    Virtualmin Professional, by default, configures all scripts, including PHP, to execute as the owner of the virtual server account via the usage of suexec. This precludes the use of mod_php, and takes the place of hacks like suphp. Because execution of PHP as a CGI script can be slower than mod_php, Virtualmin makes use of mod_fcgid which allows PHP scripts to exist as long-running processes. This leads to PHP execution speed on par with running under mod_php while still providing a level of security only available to scripts running under suexec.

    Individual PHP Configuration

    One pleasant feature of executing PHP scripts under mod_fcgid is that each user has their own private php.ini, which can be configured in any way that makes sense for the scripts the user is executing. Given that many scripts have requirements that can adversely effect security, it is of great value in a virtual hosting environment, but it also imposes additional complexity on the system and administrator. In general, Virtualmin maintains the php.ini files and the administrator need never think of them, but there are instances where manual configuration is required.

    Individual php.ini files are stored in $HOME/etc/php4/php.ini and $HOME/etc/php5/php.ini, and can be administered using the PHP Configuration module found under the Services menu under each domain within Virtualmin. As with all configuration files under Virtualmin, it is also safe to modify the files directly using your favorite text editor.

    Note 1: Changing /etc/php.ini will not effect changes in the php.ini of individual virtual servers, e.g. /home/ The php.ini of individual virtual servers have to be modified by hand, or via sed or similar command line editing tools, if required. There is no way of implementing global changes to all php.ini files.

    Note 2: [For ZEND OPTIMIZER users] After installing Zend Optimizer, copy the [Zend] section contained in /usr/local/Zend/etc/php.ini to the php.ini of virtual server you wish to use Zend Optimizer with. Note that if you wish to activate Zend Optimizer on both PHP4 and PHP5, you have to modify both /home/ and /home/

    Examples of Mass-update of Individual php.ini Using sed and the shell

    As mentioned, since the php.ini files are all independently maintained when using mod_fcgid, updating the whole system to use some new php.ini directive can be a time-consuming process. sed and other command line tools can make that process painless.

    A common change is to increase the memory_limit from the default 8M to something a bit more reasonable like 32M. To do that with sed, for all virtual servers, you could execute:

    find /home -name php.ini | xargs sed -i "s/memory_limit =.*/memory_limit = 32M/"

    This find command will find all php.ini files in all subdirectories of /home, and sed will modify them. If for some reason you have other php.ini files located in those directories, you might add a grep after the pipe to refine the list a bit. Of, if you only want to edit php4 configuration and not php5, you could do the following:

    find /home -name php.ini | grep php4 | xargs sed -i "s/memory_limit =.*/memory_limit = 32M/"

    It is possible to refine with infinite precision through additional options to find (such as file age) or via one or more regular expressionsusing grep.

    You can also append whole sections to php.ini, similarly to the examples above, using the cat command and what is known as a here document/.

    For example, to append a Zend section to all top-level (e.g. /home/domain/etc/php*/php.ini) php.ini files, one could execute something like the follow:

    cat <<EOF >> /home/*/etc/php*/php.ini

    Note: The Zend section is very specific to your environment and version. Do not copy this verbatim, as it will be wrong for your system and Zend!

    Bleeding Edge PHP Packages

    Virtualmin, Inc. maintains an unsupported repository of bleeding edge versions of some software that is occasionally version dependent, PHP among them. If you'd like to use the latest released version of PHP, on your system, and understand the risks involved in running software that is dramatically less well-tested and vetted (for security, stability, and performance) than the version provided by your OS, and a repository for your OS is available, it can be used to get the latest features of PHP.

    We do not recommend use of the Virtualmin bleeding edge repository, for PHP or otherwise. But, if you need the latest version of anything, we recommend you get it from our repository rather than building from source or obtaining it from other sources (which are likely to be even less well-tested, compatible, and concerned with security).

    Read more about the Virtualmin Bleeding Edge Packages.