php.ini; The Small File That Makes a Big Difference - VPS,Hosting,Domains,Website.
Web Hosting admin  

php.ini; The Small File That Makes a Big Difference

If you’re not familiar with PHP (Hypertext Pre-processor), it’s a popular server scripting language that converts a static page into a dynamic web page. If you dive into the make-up of your site, you’ll notice that many of your files are in the .php format, that’s because features on your site rely on a PHP script to run. If you're running WordPress, Magento, Joomla or Drupal your site is already powered by PHP!

You may also notice you have a php.ini file. This small but powerful file is where you can declare changes to the configuration of your website’s default PHP settings. Simple changes like editing the maximum file size or maximum execution time can fix common PHP errors that are thrown by your website.

In this post I highlight common PHP errors and problems, and share quick fixes all of which require simple changes to be made to your php.ini file. But, before we get started, allow me to explain where you can find your php.ini file and how to safely edit it.

How to edit your php.ini file:

If you’re using our cloud hosting platform you can use the built in File Manager. Alternatively you can use FTP. To locate your php.ini file use Ctrl+F. When you make a change don’t forget to save your work. A php.ini file is specific to a certain version of php.ini and server. This means that you shouldn't take a copy of a php.ini file that you've found on the internet, and upload that to your web space with Tsohost. You'll probably find that it breaks your website or breaks certain functionality; because paths, modules and so on are peculiar to each server and set up of PHP. If in doubt, just ask our support team for a copy of the php.ini file and they'll copy it over for the right version of PHP for you.

#1:

Fatal error: Allowed memory size of X bytes exhausted (tried to allocate Y bytes)

Solution:

This is a common PHP error thrown to WordPress users while uploading or updating a new plugin, post, image, etc. To rid your site of this error, you simply need to increase your sites default PHP memory limit. In most cases the maximum limit you can have is 786 M (M stands for megabytes) which is more than enough for a WordPress site.

# 2:

Site time-out while uploading a file

Solution:

If you're having difficulty uploading files and your site is timing out, you can resolve this by editing the upload_max_filesize in your php.ini file. In most cases upload_max_filesize is set to a 100MB, preventing any larger files from being uploaded to your site. Change this default limit to meet your file size or allow a considerable increase to avoid future headaches.

#3:

Some scripts use what in PHP is called a POST method. This is used to send data from your website to the web server to be used immediately or stored for a later date. Sometimes, the limit of this is not enough to transfer all the information gathered. This generates an error

Solution:

The maximum file size that can be uploaded using the POST method is determined in the php.ini file by the post_max_size field. In most cases it is equal to 100MB and this is quite a lot and should be enough in most cases, but there are always exceptions. If you need more, you can just edit this value to be 200MB or however much you need. In most cases this will be the solution to the issue.

#4:

A script fails to execute

Solution:

Many plugins and scripts require longer that the max_execution default time of 60 seconds to run. These will fail to execute. To get these up and running increase the max_execution in your php.ini file to 120, this should be more than enough time for almost every script to execute.

#5:

Special characters are not being recognised

Magic Quotes, is a relatively insecure process used to automatically escape all incoming data to a PHP script. This process doesn't recognise special characters that are often used in PHP scripts. For example \n means a new line, however with magic quotes activated, it needs to be typed as \n to be processed.

Solution:

Magic Quotes isn’t supported in PHP 5.6, and if you're running older PHP versions we highly recommend that you disable Magic Quotes from within your php.ini file. There a few lines that need to be added to the php.ini in order to disable Magic Quotes. Here they are:

; Magic quotes for incoming GET/POST/Cookie data. magic_quotes_gpc = Off
; Magic quotes for runtime-generated data, e.g. data from SQL, from exec(), etc. magic_quotes_runtime = Off

; Use Sybase-style magic quotes (escape ' with '' instead of \'). magic_quotes_sybase = Off

#6:

At times PHP is verbose and generates many warnings and notices that don’t cause any harm or issues to your site. Often they don't block your site content but pop up at the top or bottom of your web page.

Solution:

Once again the best solution is to use the php.ini file. Within the file you can opt not to display warnings and notices by editing the error_reporting value. To stop warnings and notices showing change the value to the following:

error_reporting = E_ALL & ~E_NOTICE & ~E_WARNING

This will remove all warnings, but it will not remove any errors. It is possible to block all PHP errors from showing on your site. However, it's not advised as it makes it extremely difficult to debug and unearth any issue you experience. If you do not wish visitors to see errors, there is one safe workaround, which will enable you to see all site errors, but your guest will be none the wiser. Add the following code snippet:

error_reporting = E_ALL & ~E_DEPRECATED

#7:

Your site is loading slower than normal

Solution:

Because our cloud platform uses memcached based session storage instead of files, if you upload a php.ini file, or define an incomplete php.ini that is not from our system then you may find performance significantly slower. This is because PHP will revert to the default file based session storage. If you suspect this might be the cause, rename your php.ini and test briefly. Finally, if you're in any doubt as to whether your php.ini file is working, or what any values are currently set to, you can use something called phpinfo(). Create a blank file in your public_html, called 'info.php' and enter this code:- Save that, and then visit www.domain.com/info.php to see information about your current PHP configuration.

That’s all folks. I hope that this article helps you solve the most common PHP errors you run into.

,