Programming in PHP can be really depressing.

Most trouble is due to version conflicts

You just set up a new web-application for a client and everything is running just dandy.

Suddenly the PHP version is being updated by the provider.

You experience that your application crashes. This is the moment that you realize that PHP hell does exist.

The PHP platform consist of a lot of dependencies to work well. If one variable has been misconfigured or is missing then your application crashes.

I will talk about the most common problems due to version conflicts.

.htaccess file

This file contains specific version information for the webserver. In my case this is Apache.

Plenty of PHP information is being contained in this file.

example:

# END WordPress
# Use PHP71 as default
# AddHandler application/x-httpd-php71 .php
# # BEGIN custom php.ini PHP71
# 
#     suPHP_ConfigPath /home4/slimpy01/immigrantadventure.com
# 
# END custom php.ini
# This tells mod_suphp the path which should be passed on to the PHP-interpreter & from which folder the php.ini file will be # # executed.

IfModule php7_module>
php_flag display_errors On
php_value max_execution_time 30
php_value max_input_time 60
php_value max_input_vars 1000
php_value memory_limit 2570M
php_value post_max_size 260M
php_value session.gc_maxlifetime 1440
php_value session.save_path “/var/cpanel/php/sessions/ea-php73”
php_value upload_max_filesize 256M
php_flag zlib.output_compression On

It is quite  important that only ONE version of PHP in this file is mentioned.

The PHP version that is mentioned should be the updated version. Old rubbish should be removed. Keeping this file clean is essential.
In this file. You see that there is also an indicator where the php.ini can be found. T

PHP.ini tells the PHP interpreter how to behave.

PHP.ini

Make sure that there are no wrong paths in this file. If the apache interpreter is using PHP version 7.3 and the php.ini file is directing to extensions of 5.3 you can bet on the fact that your app will be crashing. Extensions ( libraries) are extended with new functionality with every new version.

Operating system

PHP has been created to run on Unix. All extensions are available on Unix. Windows lacks a couple of extensions therefore an application running on Unix will not always run on windows.  An example of one of these extensions is the POSIX extension. The extension is not supported on windows.

Limitations

Running in a shared server environment means sharing the resources with other users. Your provider probably limited your available resources concerning memory. In PHP you can execute operating system commands with the PHP command exec(). This spawning of a new process can be limited and therefore your application might not work because you do not see a well descriptive error message. The error message is nevertheless available in the apache log files. Just look for a message like: “cannot allocate memory”. You might try to adjust this in your php.ini file by increasing the memory_limit variable but this will have no effect.

Monitoring Mysql

Building an application involves most of the time using a database. One of the most important tasks in building applications is performance tuning. Checking the queries that are fired at the database and decisions that the database engine makes when the engine executes complicated queries is essential. Mysql does not have a direct tool to monitor these execution plans. We are solely dependent on logfiles.

First find out where the general mysql log file is located. This can be found in the mysql.ini file , just look for general_log_file. You can also execute the query SELECT @@GLOBAL.general_log_file; Turn the logging on with the query SET GLOBAL general_log = ‘ON’; and check the output of this logfile,with  tail -f -n300 [logfile] ( replace [logfile] with the actual unix path to the logfile. This works all fine on a dedicated server but not on a shared server because that privilege is not granted.