PHP Setup

From Wiki

Jump to: navigation, search


This article will address the basics of the PHP configuration used by servers where 1H software is installed. We will explain about the PHP Configuration files, their priority and provide instructions how to modify the global configuration, how to make adjustments per single user directory and how to setup or remove global limits that cannot be overwritten by the user.

Contents

PHP Configuration

As we know specific options in the PHP Configuration are modified using a php.ini file. Using the 1H Hive software and chrooted environment for your customers implies a few changes to the standard way PHP options are modified.

It is possible for each user to create custom php.ini file for each directory under his account.

Important: The custom php.ini will not work recursively for sub-directories and should be added in each directory where the user would like the options changed.

Lets first review the architecture and briefly explain the logic behind this setup. We will explain everything in more details later in this article.


Custom Configuration Files - Overview

There are 3 steps that are checked for specific configuration options for PHP when a script is ran in a certain directory. The configuration files are checked in the following order:

  1. The global configuration file for the currently used PHP version.
  2. The local php.ini file for the current folder where the script is executed (if it exists)
  3. The specific limitation files for the currently used PHP version.

The files are loaded in descending order. That means the last loaded file will overwrite all options that were already defined in the previous. Users have access to the second file in the list only.

Advantage - Custom Limits

What do you gain from this fact:

You can adjust specific limitations that will be applied regardless of the changes made by the user in a custom php.ini file. In the same time users retain the ability to modify most PHP settings via php.ini.

Disadvantage - None

What do you lose:

Basically nothing. In some cases there will be options in the limitation files that you would not want to set limits for. If this is the case – all you need to do is remove those from the limitation *.ini files. We will also address this below in more details.


Custom Configuration Files - Details

Global Configuration

First you have the global configuration file for the currently used PHP version:

/var/suexec/baseos/usr/local/php{VERSION}/lib/php.ini

Note that the {VERSION} will be replaced by the corresponding PHP version. For example:

/var/suexec/baseos/usr/local/php52/lib/php.ini


Custom User Configuration

The local php.ini file for the current folder where the script is executed. For example if the user is trying to open:

http://domain.com/some_folder/index.php

The php.ini configuration file that will be loaded second if present is:

/home/{user}/public_html/some_folder/php.ini

All options specified this files will overwrite the ones from the global php.ini.


Limitation Files

Next the special limitation *.ini files will be loaded:

/var/suexec/baseos/usr/local/php{VERSION}/etc/*.ini

Here is a list of possible files you can have present in the etc folder for the specific PHP version:

extensions.ini
limits.ini
mysql.ini
pgsql.ini

All options specified in the files above will overwrite those from the global php.ini and the custom php.ini file for the user.

The purpose of the limitation files is to disable any directive that you feel is not suitable for a hosting account. This is specifically helpful when working with shared hosting servers. As those *.ini files are loaded last – they can be used to override any “dangerous” options that a user can set in a custom php.ini file.


How to Add/Change/Remove Global PHP Limits

Note that custom limitation files are not included by default with a standard 1H Software installation. This functionality is enabled and you can use it to add custom limit files but they will not be present by default.

In order to modify the specific limits that are set by default for PHP you need to make the changes in the limitation files mentioned above. If you delete the files you would remove all limits and allow users to override each option. The limitation files will overwrite all custom php.ini files created by users on the server as well as the global php.ini configuration file.

You can use those files to Add, Change or Remove any specific PHP option.

For example you can create a file named:

mysql.ini

that has the following options in it:

mysql.default_port = 3306
mysql.default_host = localhost
mysql.connect_timeout = 20

Those will define the default port and host for the MySQL server as well as set the connection timeout to 20 seconds. This will overwrite those options in both the global PHP configuration file and in the custom php.ini files for the users on the server.


Summary

php.ini files are loaded in the following order:

  1. /var/suexec/baseos/usr/local/php{VERSION}/lib/php.ini
  2. /home/{USER}/public_html/some_folder/php.ini
  3. /var/suexec/baseos/usr/local/php{VERSION}/etc/*.ini

If you have a certain option defined in all 3 files the last one will always be used. The idea behind this functionality is to allow you to set global configuration, let customers apply their own options and also be able to apply limitations that cannot be overwritten by a customer.

You can change whatever you like in all files. The first one will affect the global configuration - changes made there will apply to all accounts/folders using the corresponding PHP version. The second affects only the current directory overwriting the global php.ini. The files from point 3 will apply after all of the above. You can use those in order to impose certain limitation that cannot be overwritten by customers php.ini files. All options set in those files will apply last and will overwrite all custom options set by users.

Important: Note that /var/suexec/baseos is kept in the memory so it is strongly advisable to copy the files you have changed to the same place at /root/baseos after editing any of those files.

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox