Home > Support > HOWTO List > Web > PHP

Web howtos

Using PHP: PHP Hello World, Common Problems and Solutions

PHP is a popular language used to create dynamic web pages.  Using PHP can be as simple as putting the following code in a /var/www/html/helloworld.php file.  The presumes your Apache DocumentRoot is /var/www/html.  The code:

	<title>PHP Test</title>
	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>

	<h1>PHP Test</h1>
		<p><b>An Example of PHP in Action</b></p>
		<?php echo "The Current Date and Time is: <br />"; 
		echo date("g:i A l, F j Y.");?> </p>
	<h2>PHP Information</h2> 
		<p> <?php phpinfo(); ?> </p> 

If you then browse to http://yourserver/hellowworld.php it will output information about your Apache and PHP setup.


The following code snippet demonstrates how to get a MySQL connection:

    $link = mysql_connect("localhost", "mysql_user", "mysql_password")
        or die("Could not connect: " . mysql_error());
    print ("Connected successfully");

Resolving: mysql_connect Problem

Are you getting an error like: Problem: mysql_connect(): Client does not support authentication protocol requested by server?

This can happen, for example, when connecting to a MySQL 4.1 database server.  Try the 'old' password format:

update user set password=old_password('yourpasswordhere') where User='yourusernamehere';
flush privileges;

<h2 ="resolve2">Resolving: File For Download</h2>
If instead of executing the PHP your web browser offers you the file for download, check you haven't got a 'IncludesNoExec' directive in play in your httpd.conf file.  E.g.

<Directory /home/*/public_html>
AllowOverride FileInfo AuthConfig Limit
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec

(If you do, just remove the IncludesNoExec option, or override it on the virtual host)

Resolving: PHP Doesn't Execute

Is your test PHP script not working?  E.g. if you view the source of the page do you see the <?php ... > tags?

Make sure your <Directory> has an Options line that includes



Options Indexes FollowSymLinks ExecCGI

Also, make sure that your Apache httpd.conf file has the following in it:

LoadModule php4_module modules/libphp4.so
AddType application/x-httpd-php .php

If PHP code works for your 'main' server but not for a virtual host on the same server, check the relevant Directory and VirtualHost directives.  And make sure they also have the ExecCGI directive.

Resolving: URL/Form Parameters Not Present

Are your PHP scripts failing to see URL or Form parameters when you refer to the parameters like $VariableName?

/etc/php.ini will be set with register_globals = Off ($VariableName is how you'd reference a global variable).  You could turn on globals, but the prefered way of referencing the variables is by using syntax such as $HTTP_POST_VARS['VariableName'] - for form POSTs - or $HTTP_GET_VARS['VariableName'] - for URL parameters.

For more information see: http://www.pscode.com/vb/scripts/ShowCode.asp?txtCodeId=500&lngWId=8

Resolving: "the document contains no data" on file upload

This error can occur when a user submits a form with more data than PHP is configured to allow.  For example, when uploading a file.

To resolve the problem change the LimitRequestBody (the default is usually about 500KB) in /etc/httpd/conf.d/php.conf and restart apache.

Upgrade Centos 5 to php 5.2/5.3

If you wanted php 5.2 and not have to upgrade MySQL, you can install the php packages from the Centos testing repository or possibly CentosPlus.  This repository is described on this page and you can find upgrade instructions here.

As of Centos 5.6, there are php 5.3 packages available.  See the release notes here:


Just use your favorite package manager to install those.  In the past there have been many third party repositories that offered these packages.  The only ones we would recommend using are mentioned in the Centos page here: