Troubleshooting PHP

A look at how to resolve common problems that occur when scripting with PHP

Articles / Hosting / Troubleshooting PHP


PHP is a wonderful scripting language that helps make short work of building powerful web applications.

Just like any other programming environment however, problems can occur. These can be simple things like a missing character in the code, or an issue with the version of the PHP run-time itself.
  1. Blank Browser Output
  2. Common Error Messages
  3. PHP Version Compatibility
  4. Web Server Errors
  5. Other Problems

Blank Browser Output

After uploading your PHP script and attempting to load it in your browser, you may find you are present with nothing but a blank white page.

This normally means one of two things:
  • either the PHP script doesn't output anything in it's code,
  • or the PHP script interpreter has encountered an error from which it cannot recover.
It's usually the latter, since most PHP scripts will (or at the very least, should) try to tell the user what's happening.

Even though the browser output is completely blank, PHP (or the script) may be trying to tell you something through it's error reporting system. The problem is: PHP tends to output things that could be a security risk if they fall into the wrong hands.

Database functions, for example, will output the location, username and plain-text password of the database server - handy for debugging code, but also very handy for hackers to gain access.

If you are running the code in isolation (perhaps you haven't opened the site up to visitors yet, or are working on a separate development server) you may want to temporarily enable PHP error reporting. This will ensure that, if an error occurs, the description and some useful information will be rendered to the browser.

Common Error Messages

Now that you can see the error messages, you'll be able to check to see exactly why the script won't execute. These are the most common types of PHP errors and are generally the result of a typo in the PHP code.

String Concatenation Errors
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in /var/www/html/script.php on line 3
In PHP, strings a "joined" (concatenated) together using a single fullstop character.
If the line of code is missing the join between two strings, this error will occur.

PHP helps us out be specifying which line the error occurred on, so all we need to do is open up our favorite PHP editor, head to the line (3 in this example) and make sure all of the strings are concatenated correctly.

echo 'String one' 'String two';

Becomes: echo 'String one' . 'String two';

Missing Line Terminations
Parse error: syntax error, unexpected T_{VARIABLE}, expecting ',' or ';' in /var/www/html/script.php on line 4
This error normally occurs when a line isn't properly terminated.
PHP is a free form language, so "lines" of code are determined by which line they are on in the script. In PHP (and most other free form languages, such as C/C++, Javascript or the ObjectPascal behind Delphi and FreePascal) the line of code ends at the ; (semi-colon) character. All statement and assignment lines MUST end with a semi-colon. Flow control blocks, loop declarations and special sections of code may follow other rules, so you should properly read through the PHP documentation to see which lines should be terminated by a semi-colon and which are 'blocks'.

Fixing this type of error is fairly easy. As before, open up the script in your editor and go to the offending line (4 in this example). The line preceeding it is where the problem lies most of the time, PHP reaches the end of the previous statement and then runs into another immediately after. Because two statements in successive order form incorrect syntax, the PHP interpreter doesn't know how to handle the line (which appears as one line, when it should really be two)

Appending a semi-colon on the end of the previous line will fix the issue and make PHP see the two lines as individual, separate lines.

PHP Version Compatibility

For the most part, PHP Version 5 should be the version of choice - but some older scripts may not be compatible and might require PHP4. Newer scripts may require PHP version 7, but since it is an emerging platform, it may not be 100% backwards compatible.

Conspire Web Services customers can select the version of PHP that loads when running scripts in the hosting control panel. (PHP4, PHP5 and experimental support for PHP6 PHP7 is available)

It pays to check with the script developer to ensure the scripts are compatible with your hosting plan. Some major changes occur between different versions of PHP, so while some features of PHP4 may work in PHP5, it's usually best to stick with the version your script was designed for.

Some scripts may also require additional 'plugins' to the PHP build which may not come standard. We include many popular plugins on our hosting plans, but, to be safe: always read through the system requirements in the script documentation (where available) to make sure it's compatible with your hosting account.

Web Server Errors & PHP

Web Servers typically have a program that controls sending output to the visitors browser called the HTTP server. The HTTP server must talk to the PHP interpreter and get the result and state of the script before combining it with any other files before sending the output the visitors browser.

Linux servers typically have Apache installed, and a common term for these types of servers is 'L.A.M.P. servers' (Linux, Apache, MySQL and PHP servers) although other database engines (such as PostGRE SQL, Oracle or others) may be used - as well as other HTTP Servers (Cherokee, an off-shoot of the open-source Apache or Abyss Web Server for example)

Windows servers will generally use IIS, but other web servers can be installed here too (Apache is cross-platform and can run on WIndows, Linux and other operating systems)

Conspire Web Services hosting customers normally have the LAMP setup as Linux and Apache are the most prevalent type of server used in web hosting and has become a de-facto industry standard.

Occasionally, the HTTP server you might receive an 'Internal Server Error (Code 500)' or PHP will sometimes display a fatal error relating to file permissions. Typically this can be fixed by changing the file permissions of the PHP script and any files or folders it may need to access to 755 (allowing Reading and Execution to general users and Read, Write and Execute for the file owner and the system)

File permissions can be changed in the file browser of the Web Hosting control panel or in most FTP clients (some, such as Windows Explorer will handle permissions differently, so just be sure all users can at least read and execute the script)

Other times the HTTP server may not be able to access PHP properly or in some cases, PHP may not even be installed on the web server. Most Windows based hosting setups will prefer .NET scripting such as ASP .NET instead of PHP. Some other hosts prefer not to deal with the complexities of scripted hosting and only allow simple HTML files to be uploaded to their servers. In these extreme cases, it's probably best to leave configuration to the system administrator or even switch to another hosting provider if you require PHP scripting support.

Please note
All Conspire Web Services hosting plans and servers are PHP capable and our dedicated support staff are ready to help you with any issues you may come across.

Other Problems

If you require more information on troublshooting PHP scripts, be sure to checkout the Hosting forum, the Hosting FAQ and Video Tutorials (available from inside the control panel) and the Official PHP Documentation.