RimuHosting: Mighty Linux Servers.  Support Worth Raving About
Plans & Pricing
Server Recommendation Tool
Server Types
  VPS
  Semi-dedicated Server
  Dedicated Server
Server Locations
  Dallas
  London
  Australia
VPS Technology
Hardware
Data Centers
Linux Distributions
Applications
Maintenance Notices
Support Ticket
Control Panel
HOWTO Articles
Forums
VPS control panel
Billing details
Receipts
Contact details
DNS
Reverse DNS
Console-over-SSH
FTP backup space
Backup mail server
About
Staff
News
Customer Testimonials
Sales Inquiry
Link To Us
Terms and Conditions
Site Map

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

Thanks for all the tips. I checked out all the HowTo pages -- very nice. Sure saved me alot of time -- researching all the packaging I need to know. Wished I'd come here for my other website development a couple of years ago.

- Tina (#141/269)
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</title> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> </head>
<body> <h1>PHP Test</h1> <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.");?> </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.