Using PHP
PHP is a development language which you can use to generate dynamic content on your website. PHP is a server-side, HTML embedded scripting language. If you are completely new to PHP and want to get some idea on how it works, there is a tutorial available on www.php.net. There is also a list of sites which provide sample code and PHP resources on the www.php.net Links page (under the "Getting Started" section). PHP support is an "add-on" option for Magma's UNIX-based VWS packages. To have PHP support enabled on your VWS, please contact businesssupport@primus.ca.
Once Primus enables PHP for your website, you will have a precompiled php.cgi binary in your cgi-bin directory. That binary will contain the latest stable build of PHP. When you are creating new PHP enabled pages, your webpages should be created with an extension of .php.
What versions of PHP do you support?
Primus supports both PHP 4 and PHP 5.
Is there a PHP reference manual available?
Yes - there is a manual available online at www.php.net/manual/en/
How do I find out what version of PHP I am using or if a certain option is on?
You can find out everything about your instance of PHP by creating a small PHP script containing the following text then pointing your browser to it:
<? phpinfo(); ?>
What features are compiled into the Primus provided php.cgi binary?
Many features included in the base PHP package have been compiled into the binary. These include DBM, image manipulation (JPEG/PNG), FTP, Calendar conversion, and XML with WDDX. PHP5 now supports the SQLite feature by default.
I need support for one or more additional features compiled into my PHP binary. What should I do?
You can always recompile the PHP binary with the additional features you require and upload it. Please note that Primus cannot provide in-depth technical support for clients compiling their own PHP binary. The default PHP binary we supply is sufficient for 99.9% of our customers.
Can I control my own PHP environment with my own custom php.ini file?
Yes. You can place your own php.ini file in your cgi-bin directory. For information on what this file should contain, please review the documentation on the www.php.net website.
When I override PHP variables such as the file_uploads setting in the php.ini file in my cgi-bin directory, other parts of my site no longer function properly.
From time to time, the developers of PHP may change the default values for the variables that govern how PHP functions. To provide a consistent PHP environment through upgrades, Primus provides a standard set of variable settings in the /usr/local/lib/php.ini file. When you override this file with your own php.ini file none of its values will apply to your PHP environment. If you need a copy of this file please open a ticket with us.
Is the Zend Optimizer available to speed up my PHP pages? How do I configure my instance of PHP to use it?
Yes, the Zend Optimizer is available on Primus' Unix hosting servers. To enable it, add the following lines to the php.ini file in your cgi-bin directory:
On our unix servers:
[Zend]
zend_extension=/magma/software/tools/Zend-3.2.0/lib/Optimizer-3.2.0/php-5.2.x/ZendOptimizer.so
On our hybrid servers:
[Zend]
zend_extension=/magma/hosting/magma/software/tools/Zend_Optimizer_3.3.9/lib/Optimizer-3.3.9/php-5.2.x/ZendOptimizer.so
Will my website break if I upgrade to PHP 5?
PHP 5 is, for the most part, backwards compatible with PHP 4, see the following page for a list of non-backwards compatible changes:
http://www.php.net/manual/en/migration5.incompatible.php
How to I upgrade to PHP 5?
You can upgrade your existing version of PHP through Magma's MyAccount portal:
- Login into https://myaccount.magma.ca
- Click on Advanced Records
- Click on your VWS
- Click on CGI
- Click on PHP upgrade utility
How can I test PHP 5 before actually upgrading?
We can add a separate "Handler" for .php5 files to be parsed by PHP 5 (without affecting .php files). You can then create some php scripts with the .php5 extension which will be parsed by PHP 5. Please contact our technical support department to have this set up.
I have a new website and PHP 5 was setup by default. How can I switch to PHP 4?
The easiest way to switch to PHP4 is to use the php upgrade utility via the MyAccount portal to downgrade your php.cgi file to PHP 4. If you log into your VWS with SSH, you can also manually delete (or rename) "php.cgi" file in your ~/public_html/cgi-bin directory and rename the "php4.cgi" file to "php.cgi".
PHP 5 now includes support for the SQLite. Where can I get more information on this feature?
Please visit the sqlite site for further information:
http://www.sqlite.org/docs.html
Can I create multiple Sqlite databases?
Yes, you can specify the location and filename of any databases that you create.
EXAMPLE: "Hello World!"
</span><HTML> | |
<BODY BGCOLOR="#FFFFFF"> | |
<? | |
echo "Hello World"; | |
?> | |
</BODY> <span class="style12"> | |
</HTML></span><span class="style12"> |
As you can see, the PHP code is embedded directly into your HTML content. All PHP code must be surrounded by "<?" and "?>".
EXAMPLE: Detecting If Cookies Are On
</span><span class="style12"><? | |
if ($MODE!="test") { | |
SetCookie("COOKIE", "VALUE"); | |
Header("Location: ".$SCRIPT_NAME."?MODE=test"); | |
exit; | |
} else if ($COOKIE=="VALUE") { | |
echo "You've got cookies!"; | |
} else { | |
echo "Turn on cookies, Mr. Paranoid."; | |
} | |
?></span><span class="style12"> |
The $COOKIE variable is a variable provided by PHP. The SetCookie and Header functions are functions included in the PHP language.
EXAMPLE: Perform a Simple Search on a MySQL Database
</span><span class="style12"><? | |
$hostname = "127.0.0.1"; // Usually localhost. | |
$username = "username_for_mysql"; // If you have no username, leave this space empty. | |
$password = "your_password"; // The same applies here. | |
$usertable = "table_name"; // This is the name of the mysql table you made. | |
$dbName = "database_name"; // This is the main database you connect to. | |
MYSQL_CONNECT($hostname, $username, $password) OR DIE("Unable to connect to database"); | |
@mysql_select_db( "$dbName") or die( "Unable to select database"); | |
</span><span class="style12"> | |
//error message (not found message) | |
$ERROR_MESSAGE = "No Record Found"; | |
$query = mysql_query("SELECT * FROM $usertable WHERE $metode LIKE '%$search%' LIMIT 0, 30 "); | |
while ($row = mysql_fetch_array($query)) { | |
$variable1=$row["row_name1"]; | |
$variable2=$row["row_name2"]; | |
$variable3=$row["row_name3"]; | |
print ("this is for $variable1, and this prints the variable2 and so on..."); | |
} | |
//below this is the function for no record!! | |
if (!$variable1) { | |
print ("$ERROR_MESSAGE"); | |
} | |
//end | |
?> </span><span class="style12"> |
Troubleshooting
Primus cannot provide general technical support for PHP development, but we will support you if the problem is potentially with how Primus has set up PHP on the server. Send all problem reports to businesssupport@primus.ca.