Order VPS Hosting
Order a VPS, Semi- dedicated or Dedicated server in Dallas, London or Australia.

Get Assistance
Ask our support team about your hosting requirements.


Host where the staff takes pride in making customers happy

I am extremely happy with your service. Sure beats keeping a linux box running off a cable modem, remotely... Walking my mother through rebooting... Its ugly.

- Mike (an ex-cable modem + server refugee) (#273/309)
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:


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

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

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

PHP and MySQL

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


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

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;

Resolving: File For Download

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 ExecCGI.

e.g. 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

You can use the third party, "remi" repository.  Run the commands under the "Enterprise Linux 5" section on this page to add the repos.  There are also Centos 4 packages available, if you needed those.  Remi has php 5.3 packages available now for Centos 5, this also requires upgrading MySQL to 5.1.  To run this upgrade after installing the repos, run this command:


# yum --enablerepo=remi* update php mysql

Alternatively if you wanted php 5.2 and not have to upgrade MySQL, you can install the php packages from the Centos testing repository.  This is described on this page.

Also if you wanted to to upgrade php to 5.2 (latest) you might want to use Jason Litka's yum repository. More information on that can be found on his site: http://www.jasonlitka.com/yum-repository/
The repository is well maintained so far and it's easy to set it up:


rpm --import http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka
echo "[utterramblings]
name=Jason's Utter Ramblings Repo
baseurl=http://www.jasonlitka.com/media/EL\$releasever/\$basearch/
enabled=0
gpgcheck=1
gpgkey=http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka
" > /etc/yum.repos.d/utterramblings.repo
yum --enablerepo=utterramblings update
yum --enablerepo=utterramblings install php

NOTE: If the above URL returns a 404 then try hard-coding $releasever to your EL version ('EL4' or 'EL5') and the $basearch to whatever is appropriate ('i386' or 'x86_64').

If you already have PHP 5.3 installed and you want to get down to PHP 5.2from this repository, you will have to issue:


yum --enablerepo=utterramblings update yum
yum --enablerepo=utterramblings downgrade php php-cli php-common