1
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
<html xmlns="http://www.w3.org/1999/xhtml">
4
<head xmlns="http://www.w3.org/1999/xhtml">
5
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6
<title xmlns="">PHP5 - Scripting Language</title>
7
<link rel="stylesheet" href="../../libs/ubuntu-book.css" type="text/css" />
8
<link rel="home" href="index.html" title="Ubuntu Server Guide" />
9
<link rel="up" href="web-servers.html" title="Chapter 10. Web Servers" />
10
<link rel="prev" href="httpd.html" title="HTTPD - Apache2 Web Server" />
11
<link rel="next" href="squid.html" title="Squid - Proxy Server" />
12
<link rel="copyright" href="legal.html" title="Credits and License" />
16
<img id="topcap" alt="" src="https://help.ubuntu.com/htdocs/ubuntunew/img/cap-top.png" />
17
<div id="layout" class="container clear-block">
18
<script xmlns="" src="https://ssl.google-analytics.com/urchin.js" type="text/javascript"></script>
19
<script xmlns="" type="text/javascript">
20
_uacct = "UA-1018242-8";
24
<div id="logo-floater">
26
<a href="https://help.ubuntu.com" title="Ubuntu Documentation">
27
<img alt="Ubuntu" id="logo" src="https://help.ubuntu.com/htdocs/ubuntunew/img/logo.png" />
32
<form action="http://www.google.com/cse" id="cse-search-box">
34
<input type="hidden" name="cx" value="003883529982892832976:e2vwumte3fq" />
35
<input type="hidden" name="ie" value="UTF-8" />
36
<input type="text" name="q" size="27" />
37
<input type="submit" name="sa" value="Search" />
42
document.write('<form action="https://help.ubuntu.com/search.html" id="cse-search-box">');
43
document.write(' <div>');
44
document.write(' <input type="hidden" name="cof" value="FORID:9" />');
45
document.write(' <input type="hidden" name="cx" value="003883529982892832976:e2vwumte3fq" />');
46
document.write(' <input type="hidden" name="ie" value="UTF-8" />');
47
document.write(' <input type="text" name="q" size="27" />');
48
document.write(' <input type="submit" name="sa" value="Search" />');
49
document.write(' </div>');
50
document.write('</form>');
53
<a href="https://help.ubuntu.com/">
54
<img alt="Official Documentation" src="https://help.ubuntu.com/htdocs/ubuntunew/img/help-about.png" />
55
<span>Official Documentation</span>
61
<div class="breadcrumbs"><a href="https://help.ubuntu.com/">Ubuntu Documentation</a> > <a href="https://help.ubuntu.com/11.04">Ubuntu 11.04</a> > <span class="breadcrumb-link"><a href="index.html">Ubuntu Server Guide</a></span> > <span class="breadcrumb-link"><a href="web-servers.html">Web Servers</a></span> > <span class="breadcrumb-node">PHP5 - Scripting Language</span></div>
62
<div xmlns="http://www.w3.org/1999/xhtml" class="sect1" title="PHP5 - Scripting Language">
63
<div class="titlepage">
66
<h2 class="title" style="clear: both"><a id="php5"></a>PHP5 - Scripting Language</h2>
70
<p>PHP is a general-purpose scripting language suited for Web
71
development. The PHP script can be embedded into HTML. This
72
section explains how to install and configure PHP5 in Ubuntu
73
System with Apache2 and MySQL.</p>
74
<p> This section assumes you have installed and configured
75
Apache2 Web Server and MySQL Database Server. You can refer to
76
Apache2 section and MySQL sections in this document to install and
77
configure Apache2 and MySQL respectively.</p>
78
<div class="sect2" title="Installation">
79
<div class="titlepage">
82
<h3 class="title"><a id="php5-installation"></a>Installation</h3>
86
<p>The PHP5 is available in Ubuntu Linux. </p>
87
<div class="procedure">
88
<ul class="procedure">
89
<li class="step" title="Step 1">
92
can enter the following command in the terminal prompt:
96
<span class="command"><strong>sudo apt-get install php5 libapache2-mod-php5</strong></span>
100
<p>You can run PHP5 scripts from command line. To run PHP5 scripts
101
from command line you should install
102
<span class="application"><strong>php5-cli</strong></span> package. To install
103
<span class="application"><strong>php5-cli</strong></span> you can enter the following
104
command in the terminal prompt:
107
<span class="command"><strong>sudo apt-get install php5-cli</strong></span>
112
You can also execute PHP5 scripts without installing PHP5 Apache
113
module. To accomplish this, you should install
114
<span class="application"><strong>php5-cgi</strong></span> package. You can run the
115
following command in a terminal prompt to install
116
<span class="application"><strong>php5-cgi</strong></span> package:
119
<span class="command"><strong>sudo apt-get install php5-cgi</strong></span>
123
<p>To use <span class="application"><strong>MySQL</strong></span> with PHP5 you should install
124
<span class="application"><strong>php5-mysql</strong></span> package. To install
125
<span class="application"><strong>php5-mysql</strong></span> you can enter the following
126
command in the terminal prompt:
129
<span class="command"><strong>sudo apt-get install php5-mysql</strong></span>
133
<p>Similarly, to use <span class="application"><strong>PostgreSQL</strong></span> with PHP5 you should install
134
<span class="application"><strong>php5-pgsql</strong></span> package. To install
135
<span class="application"><strong>php5-pgsql</strong></span> you can enter the following
136
command in the terminal prompt:
139
<span class="command"><strong>sudo apt-get install php5-pgsql</strong></span>
147
<div class="sect2" title="Configuration">
148
<div class="titlepage">
151
<h3 class="title"><a id="php5-configuration"></a>Configuration</h3>
156
Once you install PHP5, you can run PHP5 scripts from your web
157
browser. If you have installed
158
<span class="application"><strong>php5-cli</strong></span> package, you can run PHP5
159
scripts from your command prompt.
162
By default, the Apache 2 Web server is configured to run PHP5
163
scripts. In other words, the PHP5 module is enabled in Apache2
164
Web server automatically when you install the module. Please
166
<code class="filename">/etc/apache2/mods-enabled/php5.conf</code> and
167
<code class="filename">/etc/apache2/mods-enabled/php5.load</code>
168
exist. If they do not exists, you can enable the module using
169
<span class="command"><strong>a2enmod</strong></span> command.
171
<p>Once you install PHP5 related packages and enabled PHP5
172
Apache 2 module, you should restart Apache2 Web server to run
173
PHP5 scripts. You can run the following command at a terminal
174
prompt to restart your web server:
176
<pre class="screen"><span class="command"><strong>sudo /etc/init.d/apache2 restart</strong></span> </pre>
180
<div class="sect2" title="Testing">
181
<div class="titlepage">
184
<h3 class="title"><a id="php5-testing"></a>Testing</h3>
188
<p>To verify your installation, you can run following PHP5
191
<pre class="programlisting">
197
You can save the content in a file
198
<code class="filename">phpinfo.php</code> and place it
199
under <span class="command"><strong>DocumentRoot</strong></span> directory of Apache2 Web
200
server. When point your browser to
201
<code class="filename">http://hostname/phpinfo.php</code>, it would
202
display values of various PHP5 configuration parameters.
205
<div class="sect2" title="References">
206
<div class="titlepage">
209
<h3 class="title"><a id="php5-references"></a>References</h3>
213
<div class="itemizedlist">
214
<ul class="itemizedlist" type="disc">
215
<li class="listitem">
217
For more in depth information see <a class="ulink" href="http://www.php.net/docs.php" target="_top">php.net</a> documentation.
220
<li class="listitem">
222
There are a plethora of books on PHP. Two good books from O'Reilly are
223
<a class="ulink" href="http://oreilly.com/catalog/9780596005603/" target="_top">Learning PHP 5</a> and the
224
<a class="ulink" href="http://oreilly.com/catalog/9781565926813/" target="_top">PHP Cook Book</a>.
227
<li class="listitem">
229
Also, see the <a class="ulink" href="https://help.ubuntu.com/community/ApacheMySQLPHP" target="_top">Apache MySQL PHP Ubuntu Wiki</a> page
230
for more information.
238
<div xmlns="http://www.w3.org/1999/xhtml" class="navfooter">
240
<table width="100%" summary="Navigation footer">
242
<td width="40%" align="left"><a accesskey="p" href="httpd.html"><img src="../../libs/navig/prev.png" alt="Prev" /></a> </td>
243
<td width="20%" align="center">
244
<a accesskey="u" href="web-servers.html">
245
<img src="../../libs/navig/up.png" alt="Up" />
248
<td width="40%" align="right"> <a accesskey="n" href="squid.html"><img src="../../libs/navig/next.png" alt="Next" /></a></td>
251
<td width="40%" align="left" valign="top">HTTPD - Apache2 Web Server </td>
252
<td width="20%" align="center">
253
<a accesskey="h" href="index.html">
254
<img src="../../libs/navig/home.png" alt="Home" />
257
<td width="40%" align="right" valign="top"> Squid - Proxy Server</td>
263
<div id="ubuntulinks">
264
<p>The material in this document is available under a free license, see <a href="/legal.html">Legal</a> for details<br />
265
For information on contributing see the <a href="https://wiki.ubuntu.com/DocumentationTeam">Ubuntu Documentation Team wiki page</a>. To report a problem, visit the <a href="https://bugs.launchpad.net/ubuntu/+source/ubuntu-docs">bug page for Ubuntu Documentation</a></p>
269
<img src="https://help.ubuntu.com/htdocs/ubuntunew/img/cap-bottom.png" alt="" />