How to Change PHP Settings with Apache and CGI?

PHP is one of the most popular scripting languages that are used in developing websites. It is open source, and you can customize it by changing the PHP settings by yourself. In general, there are 2 ways to run PHP on Apache. One way is to run PHP as an Apache module, and the other way is to run it as a CGI module.

No matter which module the PHP is running as on your server, you should need to claim some changes to your PHP settings to make it more customizable. Thus, we have written this post to offer you some references about configuring your PHP settings with Apache module and CGI module (also, you can check our WordPress Pricing table plugin).

How about Apache Module and CGI Module?

Before learning how to change PHP settings with Apache and CGI, we would like to introduce you something about Apache module and CGI module. Actually, each of the 2 modes has its strong points.

On the one hand, Apache module is a little faster and more stable than CGI module in managing the requests and resources. On the other hand, CGI module is of more security, because under this mode, the server can exert some restrictions on the access to the binaries. That is to say, when PHP runs as a CGI module, nobody but you and your PHP scripts can read your database passwords that have been placed in a certain file (check the best WordPress booking calendar plugin integrated with PayPal).

You may wonder how you can find out whether your PHP runs as an Apache module or a CGI module. As a matter of fact, it is quite an easy task to see the PHP settings. You can view the “Server API” value using a PHP info page, which can be created with File Manager without effort. When the “Server API” lists “Apache”, then you are running PHP as an Apache module. However, if the value of “Server API” is “CGI”, then a CGI module is configured (also, check our WordPress Countdown Timer plugin).

Generally speaking, to update the PHP settings with Apache module, you can use .htaccess file, but if PHP is running as a CGI module, then you can change the PHP settings using php.ini file.

Change PHP Settings with Apache Module

As stated above, when PHP is running as Apache module, .htaccess file is needed to change the PHP settings. Let’s learn something about .htaccess file first. htaccess is the abbreviation of Hypertext Access. This file is a configuration file that is supported by several web servers that are based on Apache. Usually, files that begin with a dot (.) such as .htaccess file are hidden files (also, you can check this list – Best WordPress Charts and Graphs Plugins).

To see your .htaccess file, you should open the File Manager from your control panel like cPanel, and choose Show Hidden Files (dotfiles). However, there is a possibility that you are not allowed to edit the .htaccess file by your web host. In this case, you can create a file and name it .htaccess (also, check this useful post – WordPress default .htaccess file).

By editing the .htaccess file, you can modify most of your PHP settings, such as memory_limit, register_globals, max_post_size, max_input_time and many more settings. To declare changes to these settings with Apache module, you should use the basic syntax below in your .htaccess file:

For instance, if you want to modify the memory_limit from 60M to 120M, then the following need to be used in your .htaccess file:

To put the changes that have been made into effect, you need to refresh the PHP info page (also, check this useful tutorial – What is PHP.INI?).

Change PHP Settings with CGI Module

To modify PHP settings when your server is running PHP as a CGI module, you need to edit the php.ini file. Similarly, let’s have a basic understanding of php.ini file in the very beginning. php.ini file is a PHP configuration file that can be used to declare some specific changes to PHP, such as modifying the max_execution_time value, max_input_time value, memory_limit value, and many more values. Sometimes, php.ini file may not exist in your account. In this case, you can ask one from your hosting company or simply create a new php.ini file by yourself (also, check our WordPress Membership Plugins list).

Again, let’s take the memory_limit value as an example. You can open your File Manager and search for publich_html, and then find the php.ini file. After that, you should search for memory_limit and then you can see the following:

If you want to configure memory_limit value from 60M to 120M, you can change 60M to 120M directly. After this, you should save the file. Remember to refresh your PHP info page, because only in this way the changes you have declared can be seen.

Leave a comment