How To Change PHP Variable For My Website

Most of the website nowadays rely and build using PHP language and most of the hosting company provide PHP with their hosting services. As you know, PHP comes with customizable variable globally and also per user based. This article will help you to change php value for your website.

Viewing Your Current PHP Value

Before you make any changes to your php variable, you will need to see what is the current value for your php variable. You will need to have a php info page. If you do not know how to create php info page, please follow our article How To Create PHP Info Page.

It is also important for you to know how does PHP being load to your web server. You can have this info when you are able to access your php info page. Again, please refer to How To Create PHP Info Page. There are two ways to load PHP.

1. as apache modules

2. CGI module.

each modules have it’s own way to process changes to the php variable.

PHP As Apache Module

If your server load PHP as an apache module, you will be able to change PHP variable thru .htaccess. You can find .htaccess file inside your public_html folder. it is a hidden file. So you need to make sure that your account able to access this file. If you cannot find this file, you should be able to create it manually.

You will need to use the correct syntax. Please refer below:

php_value <Directive> <value>

For example you would like to change your memory_limit, you will need to specify as below:

php_value memory_limit 128M

 

PHP As CGI Module

If you find your server load PHP as CGI module, changes to PHP variable can only be done by creating php.ini file inside your public_html folder. However, you need to make sure that your server able to load this file recursive so the changes will affect inside all folders.

Now you need to create a php.ini file. The syntax will be the same as global php.ini.

<Directive> = <value>;

For example you would like to change your memory_limit, you will need to specify as below:

memory_limit = 128M;

Now you can refresh your php info page again. You should see your memory limit has been change to the value that you specify.