php5 is een programmeertaal waarmee je dynamische websites kunt bouwen. php5 staat voor Php is a Hypertext Preprocessor, versie 5. Dit is dus een recursieve afkorting. Omdat PHP origineel gebaseerd was op de script taal Perl, kunnen we het ook vertalen als Perl Hypertext Preprocessor.
php.net: http://www.php.net/
PHP 101: PHP For the Absolute Beginner: http://devzone.zend.com/article/627
Hier volgt een 'simpel' voorbeeld waarbij php-code wordt uitgevoerd door een apache2 server, links de php-code, en rechts de webpagina in html zoals die wordt doorgestuurd.
code.php |
doorgestuurde html: |
<html> <head></head> <body> <h2>Today is <?php echo date('l jS \of F Y h:i:s A'); ?> </h2> <br /><br /> <b>So who do you think you are, ...?</b> <br /><br /> <i> <?php // print output $hostname=gethostname(); echo "My name is $hostname but most people call me <b>The Server</b>!"; ?> </i> </body> </html> |
<html> <head></head> <body> <h2>Today is Tuesday 21st of September 2010 02:22:55 PM</h2> <br /><br /> <b>So who do you think you are, ...?</b> <br /><br /> <i> My name is lx08 but most people call me <b>The Server</b>!</i> </body> </html> |
op je webbrowser: |
Today is Tuesday 21st of September 2010 02:22:55 PMSo who do you think you are, ...? My name is lx08 but most people call me The Server! |
Dat doen we met het volgende commando:
# apache2ctl -M
ServerName
Loaded Modules:
core_module (static)
log_config_module (static)
logio_module (static)
mpm_prefork_module (static)
http_module (static)
so_module (static)
alias_module (shared)
auth_basic_module (shared)
authn_file_module (shared)
authz_default_module (shared)
authz_groupfile_module (shared)
authz_host_module (shared)
authz_user_module (shared)
autoindex_module (shared)
cgi_module (shared)
deflate_module (shared)
dir_module (shared)
env_module (shared)
mime_module (shared)
negotiation_module (shared)
php5_module (shared)
reqtimeout_module (shared)
setenvif_module (shared)
status_module (shared)
Syntax OK
En alles is hier ok
# apache2ctl -M
Loaded Modules:
core_module (static)
log_config_module (static)
logio_module (static)
mpm_prefork_module (static)
http_module (static)
so_module (static)
alias_module (shared)
auth_basic_module (shared)
authn_file_module (shared)
authz_default_module (shared)
authz_groupfile_module (shared)
authz_host_module (shared)
authz_user_module (shared)
autoindex_module (shared)
cgi_module (shared)
dir_module (shared)
env_module (shared)
mime_module (shared)
negotiation_module (shared)
setenvif_module (shared)
status_module (shared)
Syntax OK
Tot mijn niet geringe verbazing ontbreekt php5_module (shared)
Dan moeten we kijken in /usr/lib/apache2/modules of php5 aanwezig is:
# ls /usr/lib/apache2/modules/
httpd.exp mod_authz_dbm.so mod_dav.so mod_include.so mod_rewrite.so libphp5.so mod_authz_default.so mod_dbd.so mod_info.so mod_setenvif.so mod_actions.so mod_authz_groupfile.so mod_deflate.so mod_ldap.so mod_speling.so mod_alias.so mod_authz_host.so mod_dir.so mod_log_forensic.so mod_ssl.so mod_asis.so mod_authz_owner.so mod_disk_cache.so mod_mem_cache.so mod_status.so mod_auth_basic.so mod_authz_user.so mod_dumpio.so mod_mime_magic.so mod_suexec.so mod_auth_digest.so mod_autoindex.so mod_env.so mod_mime.so mod_unique_id.so mod_authn_alias.so mod_cache.so mod_expires.so mod_negotiation.so mod_userdir.so mod_authn_anon.so mod_cern_meta.so mod_ext_filter.so mod_proxy_ajp.so mod_usertrack.so
mod_authn_dbd.so mod_cgid.so mod_file_cache.so mod_proxy_balancer.so mod_version.so mod_authn_dbm.so mod_cgi.so mod_filter.so mod_proxy_connect.so mod_vhost_alias.so mod_authn_default.so mod_charset_lite.so mod_headers.so mod_proxy_ftp.so mod_authn_file.so mod_dav_fs.so mod_ident.so mod_proxy_http.so mod_authnz_ldap.so mod_dav_lock.so mod_imagemap.so mod_proxy.so
libphp5.so is beschikbaar, we moeten alleen de module toevoegen in /etc/apache2/mods-available en ze daarna linken naar
/etc/apache2/mods-enabled
Zet wat volgt in /etc/apache2/mods-available/php5.load
LoadModule php5_module /usr/lib/apache2/modules/libphp5.so |
<IfModule mod_php5.c> AddType application/x-httpd-php .php .phtml .php3 AddType application/x-httpd-php-source .phps </IfModule> |
Maak een webpagina in je apache2 webserver met de naam test.php
en met de volgende inhoud:
$ vim /home/<mywebaccount>/httpdocs/test.php
<? phpinfo(); ?> |
PHP Version 5.2.0-8+etch13
... |