PHP

From Site5Wiki

Jump to: navigation, search

Subpages:


PHP, a scripting language, is described best by this blurb from php.net:
PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.


PHP has enjoyed a great deal of success over the years, and is one of the most requested offerings across the web hosting industry. So of course, Site5 offers PHP. In fact, Site5 offers versions 4 and 5, which are available on all our hosting plans automatically.

Contents

PHP Versions

By default on new Site5 hosting accounts, files ending in the extension .php will be parsed using PHP version 5. Files ending in .php4 will be parsed using PHP version 4. If you wish to override this default and have all files be parsed using PHP4, a .htaccess file can be placed in the directory you wish to use version 4 for .php files (if you want it site wide, just put the .htaccess file in your public_html directory). This .htaccess file needs to contain the following line somewhere in it (if this is all you're using this .htaccess file for, this would be the only line in the file):

AddHandler application/x-httpd-php4 .php

This will cause Apache to parse .php files as PHP4. As nothing has been specified to the contrary, .php4 files will also still be parsed by PHP4.

Command line (SSH) Parsing

To use PHP you can use:

php script.php

or for PHP4, you would use: /usr/bin/php4 script.php

Current Installations

Image:Info.png Yes, we do have both versions installed and available to every single customer.

last updated: --Tom 12:35, 25 January 2008 (EDT)

Version 4.x: 4.4.7
Version 5.x: 5.2.8

PHP for Beginners

PHP Configuration (php.ini)

Site5 has the default configuration for PHP located at /usr/local/lib/php.ini (http://wiki.site5.com/Php.ini), although you can override these default settings by utilizing a customized local config in the directory that the given php script will be executed from. For example, a custom php.ini for the script http://yourdomin.com/something/somethingelse/index.php will be located at (document_root)/something/somethingelse/php.ini - while http://yourdomain.com/script.php will be located at (document root)/php.ini. Note that the 'document root' for the main domain will always be public_html/ (/home/<username>/public_html).

Customized php.ini

You can copy the default php.ini from http://wiki.site5.com/Php.ini or you can use this fancy one-liner from your shell access.

$ php -i | grep php.ini | grep -i path | sed 's/.* \///' | awk '{ printf("cp /%s/php.ini .",$1) | "sh" }'

This will place a new php.ini file in your current directory. You can download this file, edit it in any text editor, save and re-upload the file to the desired location and the scripts will start using it immediately. Make sure you set the permissions on the file to be 644 so the server has access to read it.

Enabling ffmpeg-php Support

Site5 now has the ffmpeg-php extension pre-installed on all servers (both shared and reseller). Although the extension is installed, it is not enabled on your account by default. You must follow the directions below to enable this specific extension for your site. We do not enable it by default for performance reasons. The instructions below are fairly straightforward, but if you run into any problems, please do not hesitate to contact support for assistance in getting this configured on your account.

First, you will need to get a copy of the default php.ini file. There are several ways to do this depending on your skill level, but this tutorial will show you two common methods.

Using FTP/sFTP

Open your favorite text editor on your computer and create a new document called "php.ini"

Next, you need to get a copy of the php.ini file. Please go to the URL below:

http://wiki.site5.com/Php.ini

You need to copy the contents of that page starting with [PHP] and ending at the last "zend_extension_ts" line. Paste the contents of that page into your new document.

Once you have done that, look for the following lines at the end of the file:

extension=pdo.so
extension=pdo_sqlite.so
extension=sqlite.so
extension=pdo_mysql.so

You need to append the line below to that list of extensions:

extension=ffmpeg.so

Save and close the file once you have made that change.

Now open your favorite FTP client and upload that php.ini file to the directory on your Site5 account that contains the PHP script which requires ffmpeg-php. If the site in question is located at /home/username/public_html/videosite, you must upload it to that directory. Once you have done that, ffmpeg-php will begin working immediately.

NOTICE: Some text editors, without your knowledge, will automatically add a ".txt" or ".rtf" file extension to documents you save. When you upload the document to your Site5 account, make sure the file name is only "php.ini" and not "php.ini.txt" or else ffmpeg will not work.


Using SSH

People familiar with SSH will find this method easier. If you are logged in to SSH already, first check which directory you are in:

pwd

It might output something like this:

/home/username

You need to change to the directory that contains the PHP script you have that requires FFMPEG-PHP support. In this example, let's say the directory is /home/username/public_html/videosite. I'll change to that directory with the following:

cd ~/public_html/videosite

(notice the ~ which represents your current home directory -- /home/username)

Now that you are in the correct directory, let's copy over the php.ini file with the following command:

cp /usr/local/lib/php.ini .

You can then open up the php.ini file in your favorite text editor (vim, nano, etc.) and look for the following lines (it will be towards the end of the file):

extension=pdo.so
extension=pdo_sqlite.so
extension=sqlite.so
extension=pdo_mysql.so

You need to append the following line to that list of extensions:

extension=ffmpeg.so

Save the file and you're all done!


IMPORTANT: Remember, if you have PHP scripts in multiple different sub-directories, you need to upload the php.ini file to each sub-directory. The php.ini file will only be recognized in the current directory the script runs from. Scripts running in sub-directories will not see the php.ini file in your public_html directory, for example.

Adding the ability for PHP to 'include' remote files

Edit your php.ini as described above, and either find or add the system variable 'allow_url_include' and set it to read '=on'.

...
;;;;;;;;;;;;;;;;;;
; Fopen wrappers ;
;;;;;;;;;;;;;;;;;;

; Whether to allow the treatment of URLs (like http:// or ftp://) as files.
allow_url_fopen = On
allow_url_include = On

; Define the anonymous ftp password (your email address)
;from="john@doe.com"
...

PHP Modules

Site5 compiles in a slew of commonly requested modules for PHP, enabling the scripting language to make use of various features not found in its core installation. Here is a list of the default modules we offer on PHP4:

bcmath
calendar
ctype
curl
domxml
EXIF
FTP
gd
gettext
IMAP
mbstring
mcrypt
mhash
MySQL
openssl
overload
pcre
POSIX
pspell
session
sockets
standard
tokenizer
wddx
XML
XMLRPC
XSLT
Zend Optimizer
zip
zlib

The list of modules available by default on PHP5 differs slightly. Here is the default list for version 5:

bcmath
calendar
ctype
curl
date
DOM
EXIF
FTP
gd
gettext
hash
iconv
IMAP
LIBXML
mbstring
mcrypt
mhash
MySQL
openssl
pcre
PDO
pdo_sqlite
POSIX
Reflection
session
SimpleXML
sockets
SPL
SQLite
standard
tokenizer
wddx
XML
xmlreader
XMLRPC
xmlwriter
Zend Optimizer
zlib

PHP Resources

PHP is a widely used language, and as such there are a wide variety of resources available on the internet. While we couldn't possibly hope to provide you with a full list, here are a few of the sites that Site5 staff have found useful in the past:

  • php.net -- The home of PHP
    • Image:Feed.png daily news feed
    • Image:Report.png Introductory tutorial
      • Available in the following languages via pull-down menu:
        • Image:CPLP_flag.png Image:BR_flag.png Brazilian Portuguese;
        • Chinese (Simplified); Chinese (Hong Kong Cantonese); Chinese (Traditional);
        • Czech;
        • Danish;
        • Image:Sr_flag.png Dutch;
        • Finnish;
        • French;
        • German;
        • Greek;
        • Hebrew;
        • Hungarian;
        • Italian;
        • Japanese;
        • Korean;
        • Polish,
        • Romanian;
        • Russian;
        • Slovak;
        • Image:Ar_flag.png Image:Bo_flag.png Image:BR_flag.png Image:Cl_flag.png Image:Co-flag.png Image:Ec_flag.png Image:Gf_flag.png Image:Gy_flag.png Image:Py_flag.png Image:Pe_flag.png Image:Sr_flag.png Image:Uy_flag.png Image:Ve_flag.png Spanish; and
        • Swedish.



  • codegrrl.com -- help with PHP and MySQL
    taking the grr out of coding!






Books We Recommend

Core Web Application Development with PHP and MySQL, by Marc Wandschneider ISBN 9780131867161 Image:Page_find.png:



No Nonsense XML Web Development With PHP by Thomas Myer ISBN 9780975240205 Image:Page_find.png:


A practical and concise book that teaches XML from the ground up. This tutorial style presents various XML methodologies and techniques in an easy to understand way, whilst building a fully functional Content Management System by the end of the book.

Building Tag Clouds in Perl and PHP, by Jim Bumgardner ISBN 9780596527945 Image:Page_find.png:




* Image:Tag_red.png: a list of Image:Page_white_php.png specific code snippets, tips and tricks




Image:Answers.png answers/Code Image:Technorati.png technorati/tag/Code; technorati/posts/tag/Code
Image:Magnolia.png ma.gnolia.com/tags/Code Image:Tag_blue.png del.icio.us/popular/Code
Image:Tag_pink.png flickr/tags/Code: most interesting; tag clusters for Code; Flickr groups related to Code Image:Google.png Google/Code; GoogleBlogs search for Code; Google CodeSearch for Code
Image:OReilly.png O'Reilly/Code
Image:Reddit.png reddedit/Code Image:Digg.png digg/Code
Image:Bookmark_add.png furl/Code Image:Chart_organisation.png items tagged Code at SWIK
Image:Crowd.png jaiku/Code Image:Twitter.gif twitter/Code





Image:Tag_red.png Related wiki pages: .htaccess, PEAR, Scripting and Development Guide, Smarty, Installed software and their versions

Retrieved from "http://wiki.site5.com/PHP"
Personal tools