• Aucun résultat trouvé

[PDF] Support de cours php et MySQL de base [Eng] | Cours php

N/A
N/A
Protected

Academic year: 2021

Partager "[PDF] Support de cours php et MySQL de base [Eng] | Cours php"

Copied!
108
0
0

Texte intégral

(1)

http://www.php.net/manual/en/tutorial.php

Chapter 1. Introduction

Table of Contents What is PHP? What can PHP do?

What is PHP?

PHP (recursive acronym for "PHP: Hypertext Preprocessor") is a widely-used Open Source general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.

Simple answer, but what does that mean? An example: Example 1-1. An introductory example

<html> <head> <title>Example</title> </head> <body> <?php

echo "Hi, I'm a PHP script!"; ?>

</body> </html>

Notice how this is different from a script written in other languages like Perl or C -- instead of writing a program with lots of commands to output HTML, you write an HTML script with some embedded code to do something (in this case, output some text). The PHP code is enclosed in special start and end tags that allow you to jump into and out of "PHP mode".

What distinguishes PHP from something like client-side JavaScript is that the code is executed on the server. If you were to have a script similar to the above on your server, the client would receive the results of running that script, with no way of determining what the underlying code may be. You can even configure your web server to process all your HTML files with PHP, and then there's really no way that users can tell what you have up your sleeve.

The best things in using PHP are that it is extremely simple for a newcomer, but offers many advanced features for a professional programmer. Don't be afraid reading the long list of PHP's features. You can jump in, in a short time, and start writing simple scripts in a few hours.

Although PHP's development is focused on server-side scripting, you can do much more with it. Read on, and see more in the What can PHP do? section, or go right to the introductory tutorial if you are only interested in web programming.

(2)

What can PHP do?

Anything. PHP is mainly focused on server-side scripting, so you can do anything any other CGI program can do, such as collect form data, generate dynamic page content, or send and receive cookies. But PHP can do much more.

There are three main areas where PHP scripts are used.

• Server-side scripting. This is the most traditional and main target field for PHP. You need three things to make this work. The PHP parser (CGI or server module), a webserver and a web browser. You need to run the webserver, with a connected PHP installation. You can access the PHP program output with a web browser, viewing the PHP page through the server. All these can run on your home machine if you are just experimenting with PHP programming. See the installation instructions section for more information.

• Command line scripting. You can make a PHP script to run it without any server or browser. You only need the PHP parser to use it this way. This type of usage is ideal for scripts regularly executed using cron (on *nix or Linux) or Task Scheduler (on Windows). These scripts can also be used for simple text processing tasks. See the section about Command line usage of PHP for more information.

• Writing desktop applications. PHP is probably not the very best language to create a desktop application with a graphical user interface, but if you know PHP very well, and would like to use some advanced PHP features in your client-side applications you can also use PHP-GTK to write such programs. You also have the ability to write cross-platform applications this way. PHP-GTK is an extension to PHP, not available in the main distribution. If you are interested in PHP-GTK, visit its own website.

PHP can be used on all major operating systems, including Linux, many Unix variants (including HP-UX, Solaris and OpenBSD), Microsoft Windows, Mac OS X, RISC OS, and probably others. PHP has also support for most of the web servers today. This includes Apache, Microsoft Internet Information Server, Personal Web Server, Netscape and iPlanet servers, Oreilly Website Pro server, Caudium, Xitami, OmniHTTPd, and many others. For the majority of the servers PHP has a module, for the others supporting the CGI standard, PHP can work as a CGI processor.

So with PHP, you have the freedom of choosing an operating system and a web server. Furthermore, you also have the choice of using procedural programming or object oriented programming, or a mixture of them. Although not every standard OOP feature is implemented in PHP 4, many code libraries and large applications (including the PEAR library) are written only using OOP code. PHP 5 fixes the OOP related weaknesses of PHP 4, and introduces a complete object model.

With PHP you are not limited to output HTML. PHP's abilities includes outputting images, PDF files and even Flash movies (using libswf and Ming) generated on the fly. You can also output easily any text, such as XHTML and any other XML file. PHP can autogenerate these files, and save them in the file system, instead of printing it out, forming a server-side cache for your dynamic content.

One of the strongest and most significant features in PHP is its support for a wide range of databases. Writing a database-enabled web page is incredibly simple. The following databases are currently supported:

Adabas D InterBase PostgreSQL

dBase FrontBase SQLite

Empress mSQL Solid

FilePro (read-only) Direct MS-SQL Sybase

Hyperwave MySQL Velocis

IBM DB2 ODBC Unix dbm

Informix Oracle (OCI7 and OCI8)

Ingres Ovrimos

We also have a DBX database abstraction extension allowing you to transparently use any database supported by that extension. Additionally PHP supports ODBC, the Open Database Connection standard, so you can connect to any other database supporting this world standard.

PHP also has support for talking to other services using protocols such as LDAP, IMAP, SNMP, NNTP, POP3, HTTP, COM (on Windows) and countless others. You can also open raw network sockets and interact using any other protocol. PHP has support for the WDDX complex data exchange between virtually all Web programming languages. Talking about interconnection, PHP has support for instantiation of Java objects and using them transparently as PHP objects. You can also use our CORBA extension to access remote objects.

PHP has extremely useful text processing features, from the POSIX Extended or Perl regular expressions to parsing XML documents. For parsing and accessing XML documents, PHP 4 supports the SAX and DOM standards, and you can also use the XSLT extension to transform XML documents. PHP 5 standardizes all

(3)

the XML extensions on the solid base of libxml2 and extends the feature set adding SimpleXML and XMLReader support.

While using PHP in the e-commerce field, you'll find the Cybercash payment, CyberMUT, VeriSign Payflow Pro and MCVE functions useful for your online payment programs.

At last but not least, we have many other interesting extensions, the mnoGoSearch search engine functions, the IRC Gateway functions, many compression utilities (gzip, bz2), calendar conversion, translation...

As you can see this page is not enough to list all the features and benefits PHP can offer. Read on in the sections about installing PHP, and see the function reference part for explanation of the extensions mentioned here.

(4)

Chapter 2. A simple tutorial

Table of Contents What do I need?

Your first PHP-enabled page Something Useful

Dealing with Forms

Using old code with new versions of PHP What's next?

Here we would like to show the very basics of PHP in a short, simple tutorial. This text only deals with dynamic webpage creation with PHP, though PHP is not only capable of creating webpages. See the section titled What can PHP do for more information.

PHP-enabled web pages are treated just like regular HTML pages and you can create and edit them the same way you normally create regular HTML pages.

What do I need?

In this tutorial we assume that your server has activated support for PHP and that all files ending in .php are handled by PHP. On most servers, this is the default extension for PHP files, but ask your server administrator to be sure. If your server supports PHP, then you do not need to do anything. Just create your .php files, put them in your web directory and the server will automatically parse them for you. There is no need to compile anything nor do you need to install any extra tools. Think of these PHP-enabled files as simple HTML files with a whole new family of magical tags that let you do all sorts of things. Most web hosts offer PHP support, but if your host does not, consider reading the PHP Links section for resources on finding PHP enabled web hosts.

Let us say you want to save precious bandwidth and develop locally. In this case, you will want to install a web server, such as Apache, and of course PHP. You will most likely want to install a database as well, such as MySQL.

You can either install these individually or choose a simpler way. Our manual has installation instructions for PHP (assuming you already have some webserver set up). In case you have problems with installing PHP yourself, we would suggest you ask your questions on our installation mailing list. If you choose to go on the simpler route, then locate a pre-configured package for your operating system, which automatically installs all of these with just a few mouse clicks. It is easy to setup a web server with PHP support on any operating system, including MacOSX, Linux and Windows. On Linux, you may find rpmfind and PBone helpful for locating RPMs. You may also want to visit apt-get to find packages for Debian.

(5)

Your first PHP-enabled page

Create a file named hello.php and put it in your web server's root directory (DOCUMENT_ROOT) with the following content:

Example 2-1. Our first PHP script: hello.php

<html> <head>

<title>PHP Test</title> </head>

<body>

<?php echo '<p>Hello World</p>'; ?> </body>

</html>

Use your browser to access the file with your web server's URL, ending with the "/hello.php" file reference. When developing locally this URL will be something like http://localhost/hello.php or

http://127.0.0.1/hello.php but this depends on the web server's configuration. If everything is configured

correctly, this file will be parsed by PHP and the following output will be sent to your browser:

<html> <head> <title>PHP Test</title> </head> <body> <p>Hello World</p> </body> </html>

This program is extremely simple and you really did not need to use PHP to create a page like this. All it does is display: Hello World using the PHP echo() statement. Note that the file does not need to be

executable or special in any way. The server finds out that this file needs to be interpreted by PHP

because you used the ".php" extension, which the server is configured to pass on to PHP. Think of this as a normal HTML file which happens to have a set of special tags available to you that do a lot of interesting things.

If you tried this example and it did not output anything, it prompted for download, or you see the whole file as text, chances are that the server you are on does not have PHP enabled, or is not configured properly. Ask your administrator to enable it for you using the Installation chapter of the manual. If you are developing locally, also read the installation chapter to make sure everything is configured properly. Make sure that you access the file via http with the server providing you the output. If you just call up the file from your file system, then it will not be parsed by PHP. If the problems persist anyway, do not hesitate to use one of the many PHP support options.

The point of the example is to show the special PHP tag format. In this example we used <?php to indicate the start of a PHP tag. Then we put the PHP statement and left PHP mode by adding the closing tag, ?>. You may jump in and out of PHP mode in an HTML file like this anywhere you want. For more details, read the manual section on the basic PHP syntax.

A Note on Line Feeds: Line feeds have little meaning in HTML, however it is still a good idea to make your HTML look nice and clean by putting line feeds in. A linefeed that follows immediately after a closing ?> will be removed by PHP. This can be extremely useful when you are putting in many blocks of PHP or include files containing PHP that aren't supposed to output anything. At the same time it can be a bit confusing. You can put a space after the closing ?> to force a space and a line feed to be output, or you can put an explicit line feed in the last echo/print from within your PHP block.

A Note on Text Editors: There are many text editors and Integrated Development Environments (IDEs) that you can use to create, edit and manage PHP files. A partial list

(6)

of these tools is maintained at PHP Editors List. If you wish to recommend an editor, please visit the above page and ask the page maintainer to add the editor to the list. Having an editor with syntax highlighting can be helpful.

A Note on Word Processors: Word processors such as StarOffice Writer, Microsoft Word and Abiword are not optimal for editing PHP files. If you wish to use one for this test script, you must ensure that you save the file as plain text or PHP will not be able to read and execute the script.

A Note on Windows Notepad: If you are writing your PHP scripts using Windows Notepad, you will need to ensure that your files are saved with the .php extension. (Notepad adds a .txt extension to files automatically unless you take one of the following steps to prevent it.) When you save the file and are prompted to provide a name for the file, place the filename in quotes (i.e. "hello.php"). Alternatively, you can click on the 'Text Documents' drop-down menu in the 'Save' dialog box and change the setting to "All Files". You can then enter your filename without quotes.

Now that you have successfully created a working PHP script, it is time to create the most famous PHP script! Make a call to the phpinfo() function and you will see a lot of useful information about your system and setup such as available predefined variables, loaded PHP modules, and configuration settings. Take some time and review this important information.

Example 2-2. Get system information from PHP

(7)

Something Useful

Let us do something more useful now. We are going to check what sort of browser the visitor is using. For that, we check the user agent string the browser sends as part of the HTTP request. This information is stored in a variable. Variables always start with a dollar-sign in PHP. The variable we are interested in right now is $_SERVER['HTTP_USER_AGENT'].

Note: $_SERVER is a special reserved PHP variable that contains all web server

information. It is known as an autoglobal (or superglobal). See the related manual page on superglobals for more information. These special variables were introduced in PHP 4.1.0. Before this time, we used the older $HTTP_*_VARS arrays instead, such as

$HTTP_SERVER_VARS. Although deprecated, these older variables still exist. (See also

the note on old code.)

To display this variable, you can simply do:

Example 2-3. Printing a variable (Array element)

<?php echo $_SERVER['HTTP_USER_AGENT']; ?>

A sample output of this script may be:

Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)

There are many types of variables available in PHP. In the above example we printed an Array element. Arrays can be very useful.

$_SERVER is just one variable that PHP automatically makes available to you. A list can be seen in the

Reserved Variables section of the manual or you can get a complete list of them by looking at the output of the phpinfo() function used in the example in the previous section.

You can put multiple PHP statements inside a PHP tag and create little blocks of code that do more than just a single echo. For example, if you want to check for Internet Explorer you can do this:

Example 2-4. Example using control structures and functions

<?php

if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) { echo 'You are using Internet Explorer.<br />';

} ?>

A sample output of this script may be:

You are using Internet Explorer.<br />

Here we introduce a couple of new concepts. We have an if statement. If you are familiar with the basic syntax used by the C language, this should look logical to you. Otherwise, you should probably pick up an introductory PHP book and read the first couple of chapters, or read the Language Reference part of the manual. You can find a list of PHP books at /books.php.

The second concept we introduced was the strpos() function call. strpos() is a function built into PHP which searches a string for another string. In this case we are looking for 'MSIE' (so-called needle) inside

$_SERVER['HTTP_USER_AGENT'] (so-called haystack). If the needle is found inside the haystack, the

function returns the position of the needle relative to the start of the haystack. Otherwise, it returns FALSE. If it does not return FALSE, the if expression evaluates to TRUE and the code within its {braces} is executed. Otherwise, the code is not run. Feel free to create similar examples, with if, else, and other functions such as strtoupper() and strlen(). Each related manual page contains examples too. If you

(8)

are unsure how to use functions, you will want to read both the manual page on how to read a function definition and the section about PHP functions.

We can take this a step further and show how you can jump in and out of PHP mode even in the middle of a PHP block:

Example 2-5. Mixing both HTML and PHP modes

<?php

if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) { ?>

<h3>strpos() must have returned non-false</h3> <p>You are using Internet Explorer</p>

<?php } else { ?>

<h3>strpos() must have returned false</h3> <p>You are not using Internet Explorer</p> <?php

} ?>

A sample output of this script may be:

<h3>strpos() must have returned non-false</h3> <p>You are using Internet Explorer</p>

Instead of using a PHP echo statement to output something, we jumped out of PHP mode and just sent straight HTML. The important and powerful point to note here is that the logical flow of the script remains intact. Only one of the HTML blocks will end up getting sent to the viewer depending on the result of strpos(). In other words, it depends on whether the string MSIE was found or not.

(9)

Dealing with Forms

One of the most powerful features of PHP is the way it handles HTML forms. The basic concept that is important to understand is that any form element will automatically be available to your PHP scripts. Please read the manual section on Variables from outside of PHP for more information and examples on using forms with PHP. Here is an example HTML form:

Example 2-6. A simple HTML form

<form action="action.php" method="post">

<p>Your name: <input type="text" name="name" /></p> <p>Your age: <input type="text" name="age" /></p> <p><input type="submit" /></p>

</form>

There is nothing special about this form. It is a straight HTML form with no special tags of any kind. When the user fills in this form and hits the submit button, the action.php page is called. In this file you would write something like this:

Example 2-7. Printing data from our form

Hi <?php echo $_POST['name']; ?>.

You are <?php echo $_POST['age']; ?> years old.

A sample output of this script may be:

Hi Joe. You are 22 years old.

It should be obvious what this does. There is nothing more to it. The $_POST['name'] and $_POST['age'] variables are automatically set for you by PHP. Earlier we used the $_SERVER autoglobal; above we just introduced the $_POST autoglobal which contains all POST data. Notice how the method of our form is POST. If we used the method GET then our form information would live in the $_GET autoglobal instead. You may also use the $_REQUEST autoglobal, if you do not care about the source of your request data. It contains the merged information of GET, POST and COOKIE data. Also see the

import_request_variables() function.

You can also deal with XForms input in PHP, although you will find yourself comfortable with the well supported HTML forms for quite some time. While working with XForms is not for beginners, you might be interested in them. We also have a short introduction to handling data received from XForms in our features section.

(10)

Using old code with new versions of PHP

Now that PHP has grown to be a popular scripting language, there are a lot of public repositories and libraries containing code you can reuse. The PHP developers have largely tried to preserve backwards compatibility, so a script written for an older version will run (ideally) without changes in a newer version of PHP. In practice, some changes will usually be needed.

Two of the most important recent changes that affect old code are:

The deprecation of the old $HTTP_*_VARS arrays (which need to be indicated as global when used inside a function or method). The following autoglobal arrays were introduced in PHP 4.1.0. They are: $_GET, $_POST, $_COOKIE,

$_SERVER, $_FILES, $_ENV, $_REQUEST, and $_SESSION. The older $HTTP_*_VARS arrays, such as

$HTTP_POST_VARS, still exist as they have since PHP 3. As of PHP 5.0.0, the long PHP predefined variable arrays may be disabled with the register_long_arrays directive.

• External variables are no longer registered in the global scope by default. In other words, as of PHP 4.2.0 the PHP directive register_globals is off by default in php.ini. The preferred method of accessing these values is via the autoglobal arrays mentioned above. Older scripts, books, and tutorials may rely on this directive being on. If it were on, for example, one could use $id from the URL http://www.example.com/foo.php?id=42. Whether on or off,

$_GET['id'] is available.

(11)

What's next?

With your new knowledge you should be able to understand most of the manual and also the various example scripts available in the example archives. You can also find other examples on the php.net websites in the links section: /links.php.

To view various slide presentations that show more of what PHP can do, see the PHP Conference Material Sites: http://conf.php.net/ and http://talks.php.net/

(12)

II. Installation and Configuration

Table of Contents

3. General Installation Considerations 4. Installation on Unix systems 5. Installation on Mac OS X

6. Installation on Windows systems 7. Installation of PECL extensions 8. Problems?

(13)

Chapter 3. General Installation Considerations

Before starting the installation, first you need to know what do you want to use PHP for. There are three main fields you can use PHP, as described in the What can PHP do? section:

• Websites and web applications (server-side scripting)

• Command line scripting

• Desktop (GUI) applications

For the first and most common form, you need three things: PHP itself, a web server and a web browser. You probably already have a web browser, and depending on your operating system setup, you may also have a web server (e.g. Apache on Linux and MacOS X; IIS on Windows). You may also rent webspace at a company. This way, you don't need to set up anything on your own, only write your PHP scripts, upload it to the server you rent, and see the results in your browser.

In case of setting up the server and PHP on your own, you have two choices for the method of connecting PHP to the server. For many servers PHP has a direct module interface (also called SAPI). These servers include Apache, Microsoft Internet Information Server, Netscape and iPlanet servers. Many other servers have support for ISAPI, the Microsoft module interface (OmniHTTPd for example). If PHP has no module support for your web server, you can always use it as a CGI or FastCGI processor. This means you set up your server to use the CGI executable of PHP to process all PHP file requests on the server.

If you are also interested to use PHP for command line scripting (e.g. write scripts autogenerating some images for you offline, or processing text files depending on some arguments you pass to them), you always need the command line executable. For more information, read the section about writing command line PHP applications. In this case, you need no server and no browser.

With PHP you can also write desktop GUI applications using the PHP-GTK extension. This is a completely different approach than writing web pages, as you do not output any HTML, but manage windows and objects within them. For more information about PHP-GTK, please visit the site dedicated to this extension. PHP-GTK is not included in the official PHP distribution.

From now on, this section deals with setting up PHP for web servers on Unix and Windows with server module interfaces and CGI executables. You will also find information on the command line executable in the following sections.

PHP source code and binary distributions for Windows can be found at /downloads.php. We recommend you to choose a mirror nearest to you for downloading the distributions.

(14)

Chapter 4. Installation on Unix systems

Table of Contents

Apache 1.3.x on Unix systems Apache 2.0 on Unix systems Caudium

fhttpd related notes

Sun, iPlanet and Netscape servers on Sun Solaris CGI and commandline setups

HP-UX specific installation notes OpenBSD installation notes Solaris specific installation tips Debian GNU/Linux installation notes

This section will guide you through the general configuration and installation of PHP on Unix systems. Be sure to investigate any sections specific to your platform or web server before you begin the process. As our manual outlines in the General Installation Considerations section, we are mainly dealing with web centric setups of PHP in this section, although we will cover setting up PHP for command line usage as well.

There are several ways to install PHP for the Unix platform, either with a compile and configure process, or through various pre-packaged methods. This documentation is mainly focused around the process of compiling and configuring PHP. Many Unix like systems have some sort of package installation system. This can assist in setting up a standard configuration, but if you need to have a different set of features (such as a secure server, or a different database driver), you may need to build PHP and/or your webserver. If you are unfamiliar with building and compiling your own software, it is worth checking to see whether somebody has already built a packaged version of PHP with the features you need. Prerequisite knowledge and software for compiling:

• Basic Unix skills (being able to operate "make" and a C compiler)

• An ANSI C compiler

• flex: Version 2.5.4

• bison: Version 1.28 (preferred), 1.35, or 1.75

• A web server

• Any module specific components (such as gd, pdf libs, etc.)

The initial PHP setup and configuration process is controlled by the use of the commandline options of the configure script. You could get a list of all available options along with short explanations running ./configure --help. Our manual documents the different options separately. You will find the core options in the appendix, while the different extension specific options are descibed on the reference pages. When PHP is configured, you are ready to build the module and/or executables. The command make should take care of this. If it fails and you can't figure out why, see the Problems section.

Apache 1.3.x on Unix systems

This section contains notes and hints specific to Apache installs of PHP on Unix platforms. We also have instructions and notes for Apache 2 on a separate page.

You can select arguments to add to the configure on line 10 below from the list of core configure options and from extension specific options described at the respective places in the manual. The version numbers have been omitted here, to ensure the instructions are not incorrect. You will need to replace the 'xxx' here with the correct values from your files.

Example 4-1. Installation Instructions (Apache Shared Module Version) for PHP

1. gunzip apache_xxx.tar.gz 2. tar -xvf apache_xxx.tar 3. gunzip php-xxx.tar.gz 4. tar -xvf php-xxx.tar

(15)

5. cd apache_xxx

6. ./configure --prefix=/www --enable-module=so 7. make

8. make install 9. cd ../php-xxx

10. Now, configure your PHP. This is where you customize your PHP with various options, like which extensions will be enabled. Do a ./configure --help for a list of available options. In our example we'll do a simple configure with Apache 1 and MySQL support. Your path to apxs may differ from our example.

./configure --with-mysql --with-apxs=/www/bin/apxs

11. make

12. make install

If you decide to change your configure options after installation, you only need to repeat the last three steps. You only need to restart apache for the new module to take effect. A recompile of Apache is not needed.

Note that unless told otherwise, 'make install' will also install PEAR, various PHP tools such as phpize, install the PHP CLI, and more.

13. Setup your php.ini file:

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

You may edit your .ini file to set PHP options. If you prefer your php.ini in another location, use --with-config-file-path=/some/path in step 10.

If you instead choose php.ini-recommended, be certain to read the list of changes within, as they affect how PHP behaves.

14. Edit your httpd.conf to load the PHP module. The path on the right hand

side of the LoadModule statement must point to the path of the PHP module on your system. The make install from above may have already added this for you, but be sure to check.

For PHP 4:

LoadModule php4_module libexec/libphp4.so

For PHP 5:

LoadModule php5_module libexec/libphp5.so

(16)

ClearModuleList, add this: For PHP 4: AddModule mod_php4.c For PHP 5: AddModule mod_php5.c

16. Tell Apache to parse certain extensions as PHP. For example, let's have Apache parse the .php extension as PHP. You could have any extension(s) parse as PHP by simply adding more, with each separated by a space. We'll add .phtml to demonstrate.

AddType application/x-httpd-php .php .phtml

It's also common to setup the .phps extension to show highlighted PHP source, this can be done with:

AddType application/x-httpd-php-source .phps

17. Use your normal procedure for starting the Apache server. (You must stop and restart the server, not just cause the server to reload by using a HUP or USR1 signal.)

Alternatively, to install PHP as a static object:

Example 4-2. Installation Instructions (Static Module Installation for Apache) for PHP

1. gunzip c apache_1.3.x.tar.gz | tar xf -2. cd apache_1.3.x

3. ./configure 4. cd ..

5. gunzip c php5.x.y.tar.gz | tar xf -6. cd php-5.x.y

7. ./configure --with-mysql --with-apache=../apache_1.3.x 8. make

9. make install

10. cd ../apache_1.3.x

11. ./configure --prefix=/www --activate-module=src/modules/php5/libphp5.a (The above line is correct! Yes, we know libphp5.a does not exist at this

stage. It isn't supposed to. It will be created.)

12. make

(you should now have an httpd binary which you can copy to your Apache bin dir if

(17)

it is your first install then you need to "make install" as well)

13. cd ../php-5.x.y

14. cp php.ini-dist /usr/local/lib/php.ini

15. You can edit /usr/local/lib/php.ini file to set PHP options. Edit your httpd.conf or srm.conf file and add:

AddType application/x-httpd-php .php

Note: Replace php-5 by php-4 and php5 by php4 in PHP 4.

Depending on your Apache install and Unix variant, there are many possible ways to stop and restart the server. Below are some typical lines used in restarting the server, for different apache/unix installations. You should replace /path/to/ with the path to these applications on your systems.

Example 4-3. Example commands for restarting Apache

1. Several Linux and SysV variants: /etc/rc.d/init.d/httpd restart

2. Using apachectl scripts: /path/to/apachectl stop /path/to/apachectl start

3. httpdctl and httpsdctl (Using OpenSSL), similar to apachectl: /path/to/httpsdctl stop

/path/to/httpsdctl start

4. Using mod_ssl, or another SSL server, you may want to manually stop and start:

/path/to/apachectl stop /path/to/apachectl startssl

The locations of the apachectl and http(s)dctl binaries often vary. If your system has locate or whereis or

which commands, these can assist you in finding your server control programs.

Different examples of compiling PHP for apache are as follows:

./configure --with-apxs --with-pgsql

This will create a libphp5.so (or libphp4.so in PHP 4) shared library that is loaded into Apache using a LoadModule line in Apache's httpd.conf file. The PostgreSQL support is embedded into this library.

./configure --with-apxs --with-pgsql=shared

This will create a libphp4.so shared library for Apache, but it will also create a pgsql.so shared library that is loaded into PHP either by using the extension directive in php.ini file or by loading it explicitly in a script using the dl() function.

(18)

This will create a libmodphp5.a library, a mod_php5.c and some accompanying files and copy this into the src/modules/php5 directory in the Apache source tree. Then you compile Apache using

--activate-module=src/modules/php5/libphp5.a and the Apache build system will create libphp5.a and link it statically into the httpd binary (replace php5 by php4 in PHP 4). The PostgreSQL support is included directly into this httpd binary, so the final result here is a single httpd binary that includes all of Apache and all of PHP.

./configure --with-apache=/path/to/apache_source --with-pgsql=shared

Same as before, except instead of including PostgreSQL support directly into the final httpd you will get a pgsql.so shared library that you can load into PHP from either the php.ini file or directly using dl().

When choosing to build PHP in different ways, you should consider the advantages and drawbacks of each method. Building as a shared object will mean that you can compile apache separately, and don't have to recompile everything as you add to, or change, PHP. Building PHP into apache (static method) means that PHP will load and run faster. For more information, see the Apache webpage on DSO support.

Note: Apache's default httpd.conf currently ships with a section that looks like this:

User nobody Group "#-1"

Unless you change that to "Group nogroup" or something like that ("Group daemon" is also very common) PHP will not be able to open files.

Note: Make sure you specify the installed version of apxs when using

--with-apxs=/path/to/apxs. You must NOT use the apxs version that is in the apache sources

but the one that is actually installed on your system.

add a noteUser Contributed Notes

Installation on Unix systems flconseil at yahoo dot fr 07-Mar-2006 06:15

Building Apache 2 and PHP 5.1.2 :

On AIX 5.2 : http://flaupretre.free.fr/redir.php?key=build_apa_aix

On HP-UX 11i (11.11) : http://flaupretre.free.fr/redir.php? key=build_apa_hpux

These documents are complete step-by-step howtos, and describe how to buid a self-sufficient package, including every software it depends on (zlib, SSL, LDAP, iconv, expat, xml, xslt, gd, png, Xpm, jpeg, freetype, bzip2, curl, MySQL, PostgreSQL, Oracle, AdoDB).

dpresley4 at yahoo dot com 06-Nov-2005 03:42

Hi,

PROBLEM: ./configure PHP --with-oci8 fails with unresolved references such as __rpc_thread_destroy@GLIBC_2_2_3_... ONE SOLUTOIN

FOR SOLVING PHP ./configure RESULTING IN __rcp_thread_destroy@GLIBC_2_2_3_... AND UNRESOLVED REFERENCES WITH ORACLE OCI8

(19)

REFERENCES

For building php-4.4.1 or later with oci8, make sure your LD_LIBARRY_PATH has at a minimum the following directories in its path for Oracle8i 8.1.5 or later, Oracle9i 9.0.2 or later, and Oracle9i Release 2: 9.2.0.4 or later, do the following:

Note: We are not using the Oracle Instant Client here. This assumes you have an actual Oracle Installation.

1. Set ORACLE_HOME

Example using Oracle 9i Relase 2 -- 9.2.0.5: ORACLE_HOME=/opt/app/oracle/product/9iR2 2. Set LD_LIBRARY_PATH with:

LD_LIBRARY_PATH=$ORACLE_HOME/lib: \ $ORACLE_HOME/rdbms/lib:\

$LD_LIBRARY_PATH

3. On Unix / Linux, don't forget to export these environment variables: export ORACLE_HOME LD_LIBRARY_PATH

4. Now, build PHP with the following:

./configure apxs2=<path to Apache 2.0/bin/apxs> --with-oci8=$ORACLE_HOME --enable-sigchild

It should now build correctly. The key with Oracle is to ensure that you pick up the libclntX.so (client librariess) where X is the Oracle version associated with the version your using for instance, in the above example, libclnt9.so

Also note that if your using Oracle 9iAS Release 2 v9.0.2, Oracle 10g iAS Release 1 v9.0.4.1, the above steps will work because ORACLE_HOME will containe all of the libraries necessary. Simply point ORACLE_HOME to the top level directory of these installations and set LD_LIBRARY_PATH as described above.

Hope this helps. phptard at gmail dot com 23-Mar-2005 04:17

after a long night of wrestling with mysql4.0 under linux compiled with the intel compiler, i've gotten php5.0.3 to compile with mysql libraries for this flavor of mysql:

1: download the mysql for linux/intel compiler and install

2: download the rpm for the intel compiler libraries and install

3: configure php with LDFLAGS="-lirc -lgcc_s" and EXTRA_LIBS="-lirc -lgcc_s" Example:

LDFLAGS="-lirc -lgcc_s" LD_LIBRARY_PATH="-L/usr/lib64"

LD_PATH="-L/usr/lib64" LDPATH="-LD_PATH="-L/usr/lib64" EXTRA_LIBS="-lirc -lgcc_s" ./configure --with-apxs2=/usr/local/apache/bin/apxs --with-ssl=/usr/local/ssl --without-sqlite --with-zlib-dir=/usr --with-mysql=/usr/local/mysql

of course this is on a xeon system that has half of its modules in the /usr/lib64 directory, so on a normal system, without the other kruft, it would look something more like this:

LDFLAGS="-lirc -lgcc_s" EXTRA_LIBS="-lirc -lgcc_s" ./configure --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql

(20)

diemuzi at gmail dot com 13-Jan-2005 10:11

In reference to van [at] webfreshener [dot] com to fix the krb5 problems. An easier fix is to do the following:

ln -s /usr/kerberos/include/krb5.h /usr/include/krb5.h

ln -s /usr/kerberos/include/profile.h /usr/include/profile.h ln -s /usr/kerberos/include/com_err.h /usr/include/com_err.h

This will help solve some deps. in the future incase a situation with another compilation occurs.

alexander justadot henry at acm dot org 22-Dec-2004 12:48

The system at my workplace has a need for apache/php with all static

compilation. In order to save time adminning our systems, I decided to make my own RPM of php/apache with mod_ssl support. I had always installed by hand with the instructions on this page, but when buiding the RPM way, came upon the following error when apache was compiling:

===> src/modules/php4

make[4]: *** No rule to make target `all'. Stop.

Ordinarily this is because one did not do a 'make install' in php before the second apache configure, or somehow the make install failed. But the way rpm's work, the make install must be in the %install portion of the spec file, after all makes are completed.

make install-sapi

This line will copy relevant files to the directory specified in --with-apache

samael99 at web dot de 24-Jun-2004 06:51

Quick hint for people using RH8: if make gives you this error FT_ENCODING_MS_SYMBOL undeclared change on line in this file

/usr/include/freetype2/freetype/freetype.h Search for ft_encoding_symbol - change it to ft_encoding_ms_symbol

Now this problem is dealt with, go ahead with make. Good Luck !

robert_sgi at yahoo dot com 08-May-2004 11:57

If you install php 4 on SGI IRIX 6.5 (in my case it was php 4.3.6 on Silicon Graphics O2 IRIX 6.5.22 machine) and you're building it with:

--with-gettext=/usr/freeware

then you need to manually edit the file named "configure" (from the php source directory) and change the line# 36739

from:

GETTEXT_LIBDIR=$GETTEXT_DIR/lib to:

GETTEXT_LIBDIR=$GETTEXT_DIR/lib32

If you have problems in locating the line, search the text for "bindtextdomain", and look several (4) lines above.

karthik (dot) k (at) extremix (dot) net 18-Jan-2004 08:28

This is regarding the post down below about the problem with openssl on RH9. Openssl on RH9 is built with kerberos. To get PHP to build correctly you need the output of these commands when you make.

(21)

[root@graf-spee local]# pkg-config --cflags openssl -I/usr/kerberos/include

[root@graf-spee local]# pkg-config --libs openssl

-L/usr/kerberos/lib -lssl -lcrypto -lresolv -lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err -ldl -lz

These could be added to your make command thus. I have not tested it out, but should work with some tweaking

make EXTRA_LDFLAGS=`pkg-config --libs openssl` EXTRA_CFLAGS=`pkg-config --cflags openssl`

thansen at terra dot com dot br 30-Dec-2003 08:36

The configure directives --with-apxs2 and --with-apxs2filter are not compatible one with other, even though the configure script will not complain about that. Each one affect the way Apache will call the php parser: If you choose the first one, you must use the traditional include: AddType application/x-httpd-php php

at httpd.conf, to call the parser. If you use the --with-apxs2filter, the include will be:

<Files *.php>

SetOutputFilter PHP SetInputFilter PHP </Files>

, and php will be called as a filter to .php files.

If you use both together, you will get compilation errors (duplicate symbols while linking libphp4).

aaronmorris at mindspring dot com 05-Dec-2003 12:47

If you have the libphp4.a instead of libphp4.so on AIX, you can extract the .so file from the .a file by running "ar -x libphp4.a".

jazee_at_bigfoot.com 26-Mar-2003 12:52

http://dan.drydog.com/apache2php.html has a nice set of instructions for

Apache2 + php

doug at NOSPAM dot techie dot net 04-Feb-2003 05:16

Users compiling under some versions of Solaris/SunOS may encounter the following error.

symbol ap_block_alarms: referenced symbol not found

To address this problem, add the following additional flag to the Apache build configure line:

--enable-rule=SHARED_CORE

So, adding this to the original instructions, you'd configure your Apache build like so:

./configure --prefix=/www --enable-module=so --enable-rule=SHARED_CORE Doug

mbabcock-php at fibrespeed dot net 20-Jul-2001 09:32

The best configuration guide I've found for Apache with PHP (and PERL, mod_ssl, etc.) is Apacompile. Its home site is

http://www.delouw.ch/linux/apache.phtml

dimaberastau at hotmail dot com 09-Jun-2001 09:33

when installing with mysql support (--with-mysql=<path/to/your/mysql>) via Apache APXS you'll probably get something like 'can't load

(22)

libmysqlclient.so' when you try to start up apache. There are 2 solutions to this problem. First, (as documented in INSTALL file of the php4

distribution) you can modify /etc/ld.so.conf to contain the directory name where libmysqlclient.so is (so if your mysql is installed in /usr/local, you want to add something like /usr/local/lib/mysql into /etc/ld.so.conf), else (and particularly if you haven't got the super-user on the system) you can modify (or create if it isn't defined already) LD_LIBRARY_PATH shell

variable to reflect the changes you would have otherwise made to /etc/ld.so.conf (again if mysql is /usr/local

LD_LIBRARY_PATH=/usr/local/lib/mysql). Either one of these methods will get the problem sorted. Just remember to run ldconfig (so that /etc/ld.so.cache is updated) if you chose to modify /etc/ld.so.conf

marshalm at ebrd dot com 17-May-2001 10:43

HP-UX 11.X PA-RISC installation with oracle (oci8). You need to install the HP-UX patch PHSS_22514 patch (updated libdld.sl), otherwise you will get errors with dlopen() and dlclose() not found during the apache integration stage.

(23)

Apache 2.0 on Unix systems

This section contains notes and hints specific to Apache 2.0 installs of PHP on Unix systems. Warning

We do not recommend using a threaded MPM in production with Apache2. Use the prefork MPM instead, or use Apache1. For information on why, read the related FAQ entry on using Apache2 with a threaded MPM

You are highly encouraged to take a look at the Apache Documentation to get a basic understanding of the Apache 2.0 Server.

PHP and Apache 2.0.x compatibility notes: The following versions of PHP are known to work with the most recent version of Apache 2.0.x:

• PHP 4.3.0 or later available at /downloads.php.

• the latest stable development version. Get the source code http://snaps.php.net/php5-latest.tar.gz or download binaries for Windows http://snaps.php.net/win32/php5-win32-latest.zip.

• a prerelease version downloadable from http://qa.php.net/.

• you have always the option to obtain PHP through anonymous CVS.

These versions of PHP are compatible to Apache 2.0.40 and later.

Apache 2.0 SAPI-support started with PHP 4.2.0. PHP 4.2.3 works with Apache 2.0.39, don't use any other version of Apache with PHP 4.2.3. However, the recommended setup is to use PHP 4.3.0 or later with the most recent version of Apache2.

All mentioned versions of PHP will work still with Apache 1.3.x.

Download the most recent version of Apache 2.0 and a fitting PHP version from the above mentioned places. This quick guide covers only the basics to get started with Apache 2.0 and PHP. For more

information read the Apache Documentation. The version numbers have been omitted here, to ensure the instructions are not incorrect. You will need to replace the 'NN' here with the correct values from your files.

Example 4-4. Installation Instructions (Apache 2 Shared Module Version)

1. gzip -d httpd-2_0_NN.tar.gz 2. tar xvf httpd-2_0_NN.tar 3. gunzip php-NN.tar.gz 4. tar -xvf php-NN.tar 5. cd httpd-2_0_NN 6. ./configure --enable-so 7. make 8. make install

Now you have Apache 2.0.NN available under /usr/local/apache2,

configured with loadable module support and the standard MPM prefork. To test the installation use your normal procedure for starting

the Apache server, e.g.:

/usr/local/apache2/bin/apachectl start

and stop the server to go on with the configuration for PHP: /usr/local/apache2/bin/apachectl stop.

9. cd ../php-NN

(24)

with various options, like which extensions will be enabled. Do a ./configure --help for a list of available options. In our example we'll do a simple configure with Apache 2 and MySQL support. Your path to apxs may differ, in fact, the binary may even be named apxs2 on your system.

./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql

11. make

12. make install

If you decide to change your configure options after installation, you only need to repeat the last three steps. You only need to restart apache for the new module to take effect. A recompile of Apache is not needed.

Note that unless told otherwise, 'make install' will also install PEAR, various PHP tools such as phpize, install the PHP CLI, and more.

13. Setup your php.ini

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

You may edit your .ini file to set PHP options. If you prefer having php.ini in another location, use --with-config-file-path=/some/path in step 10.

If you instead choose php.ini-recommended, be certain to read the list of changes within, as they affect how PHP behaves.

14. Edit your httpd.conf to load the PHP module. The path on the right hand

side of the LoadModule statement must point to the path of the PHP module on your system. The make install from above may have already added this for you, but be sure to check.

For PHP 4:

LoadModule php4_module modules/libphp4.so

For PHP 5:

LoadModule php5_module modules/libphp5.so

15. Tell Apache to parse certain extensions as PHP. For example, let's have Apache parse the .php extension as PHP. You could have any extension(s) parse as PHP by simply adding more, with each separated by a space. We'll add .phtml to demonstrate.

AddType application/x-httpd-php .php .phtml

(25)

It's also common to setup the .phps extension to show highlighted PHP source, this can be done with:

AddType application/x-httpd-php-source .phps

16. Use your normal procedure for starting the Apache server, e.g.:

/usr/local/apache2/bin/apachectl start

Following the steps above you will have a running Apache 2.0 with support for PHP as SAPI module. Of course there are many more configuration options available for both, Apache and PHP. For more information use ./configure --help in the corresponding source tree. In case you wish to build a multithreaded version of Apache 2.0 you must overwrite the standard MPM-Module prefork either with worker or perchild. To do so append to your configure line in step 6 above either the option

--with-mpm=worker or --with-mpm=perchild. Take care about the consequences and understand what you are

doing. For more information read the Apache documentation about the MPM-Modules. Note: If you want to use content negotiation, read the Apache MultiViews FAQ.

Note: To build a multithreaded version of Apache your system must support threads. This also implies to build PHP with experimental Zend Thread Safety (ZTS). Therefore not all extensions might be available. The recommended setup is to build Apache with the standard prefork MPM-Module.

add a noteUser Contributed Notes

Apache 2.0 on Unix systems jaya

05-Jul-2006 11:41

PHP 5.1.4 INSTALLATION on Solaris 9 (Sparc) Solaris9 Packages Installed:

Verify required package installation:

root# pkginfo SUNWbtool SUNWsprot SUNWtoo SUNWhea SUNWarc \ SUNWlibm SUNWlibms SUNWdfbh SUNWxglh SUNWcg6h

Uninstall Default Apache Packages: root# /etc/init.d/apache stop root# pkginfo |grep Apache

root# pkgrm SUNWaclg SUNWapchd SUNWapchr SUNWapchu Create installation Directory:

root# mkdir /phpdata/

Download Required Packages from Sunfreeware: Install libiconv-1.8 and gcc3.3.2 packages root# pkgadd -d ./libiconv-1.8-sol9-sparc-local root# pkgadd -d ./gcc-3.3.2-sol9-sparc-local set LD_LIBRARY_PATH, CC and PATH variables

root# LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib/sparcv9/:\ /usr/lib:/usr/openwin/lib:/opt/local/lib:/usr/local/ssl/lib:\ /usr/local/apr/lib:/opt/mysql/mysql/lib

root# CC=gcc

root# PATH=$PATH:/usr/ucb:/usr/local/bin/ root# export LD_LIBRARY_PATH CC PATH

Install apr-1.2.2 and aprutil-1.2.2 packages root# gzcat apr1.2.2.tar.gz |tar xvf

(26)

root# ./configure root# make

root# make install root# cd ..

root# gzcat aprutil1.2.2.tar.gz |tar xvf -root# cd apr-util-1.2.2/

root# ./configure --with-apr=/usr/local/apr/ root# make

root# make install

Install gawk-3.1.4, expat-1.95.5, db-4.2.52.NC, gdbm-1.8.3, libgcc-3.3 and libxml2-2.6.16 packages root# cd ..

root# pkgadd -d ./gawk-3.1.4-sol9-sparc-local root# pkgadd -d ./expat-1.95.5-sol9-sparc-local root# pkgadd -d ./db-4.2.52.NC-sol9-sparc-local root# pkgadd -d ./gdbm-1.8.3-sol9-sparc-local root# pkgadd -d ./libgcc-3.3-sol9-sparc-local root# pkgadd -d ./libxml2-2.6.16-sol9-sparc-local Install GNU make package

root# gzcat make3.81.tar.gz |tar xvf -root# cd make-3.81

root# ./configure root# make

root# make install root# cd ..

Install mysql-standard-5.0.22 package Search for user mysql

root# grep mysql /etc/passwd root# grep mysql /etc/group

If not found create user and group mysql root# groupadd mysql

root# useradd -G mysql mysql

root# pkgadd -d ./mysql-standard-5.0.22-solaris9-sparc.pkg.gz Install openssl-0.9.7g package

root# gzcat openssl0.9.7g.tar.gz |tar xvf -root# cd openssl-0.9.7g

root# ./config shared root# make

root# make install root# cd ..

Install Apache2 package

root# gzcat httpd2.2.0.tar.gz |tar xvf -root# cd httpd-2.2.0

root# ./configure --enable-so root# /usr/local/bin/make

root# /usr/local/bin/make install root# cd ..

Install php-5.1.4 package

root# gzcat php5.1.4.tar.gz |tar xvf -root# cd php-5.1.4

root# ./configure --with-apxs2=/usr/local/apache2/bin/apxs\ --with-ldap --with-mysql=/opt/mysql/mysql/

root# /usr/local/bin/make

root# /usr/local/bin/make install

root# cp php.ini-dist /usr/local/lib/php.ini Edit httpd.conf to load the PHP module and to parse certain extensions as PHP root# vi /usr/local/apache2/conf/httpd.conf LoadModule php5_module modules/libphp5.so AddType application/x-httpd-php .php .phtml

(27)

Start Apache

root# /usr/local/apache2/bin/apachectl start Add environmental variables below HTTPD root# vi /usr/local/apache2/bin/apachectl LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib/sparcv9/: /usr/lib:/usr/openwin/lib:/opt/local/lib:/usr/local/ssl/lib: /usr/local/apr/lib:/opt/mysql/mysql/lib PATH=/bin:/sbin:/usr/ccs/bin:/usr/sbin:/usr/openwin/bin:\ /usr/ucb:/usr/local/bin/

export LD_LIBRARY_PATH PATH Create Apache Startup Script pillepop2003 at yahoo dot de

19-Apr-2006 09:18

For unix (especially opensuse 10.0) you can find bison and flex here: ftp.gnu.org/non-gnu/flex

ftp.gnu.org/pub/gnu/bison Peace ;-)

felixcca at yahoo dot ca 29-Mar-2006 06:13

I've (painfully) discovered that installing PHP5 with "make install" under SuSe 9.2 is NOT a good idea.

http://www.aditus.nu/jpgraph/apache2suse.php

This page explains how to install it without breaking everything that's php-related in the Apache2 configuration. Its first purpose, though, is to show how to have php 4 and 5 to cohabit properly.

payne747 at yahoo dot com 14-Feb-2006 08:05

When compiling php 5.1.2 on Debian 3.1 (Sarge) with Apache 2.2.0, I ran into problems with libxml2 and libxml2-config not found errors. After checking the base install, Debian leaves out the libxml2 headers, they can be downloaded using apt-get:

apt-get install libxml2 libxml2-dev PHP should then compile fine. frank@ethisoft

28-Sep-2005 02:30

Using Apache2 & PHP5 work perfectly fine & safe together. - all core modules are safe in Zend Engine 2

- third-party-libraries should be avoided

- semaphores and shared memory enables you to ensure yourself that your application/website is thread-safe also with non-thread-safe PHP modules! happyboy at php dot org

03-Aug-2005 04:30 FILE TRUNCATED!!

during the make process should u receive an error declaring

ext/ctype/ctype.lo (or another file) is truncated then you need to 'make clean' prior to a healthy 'make' and 'make install.'

looking into your ext/ directory you may find the offensive file to be 1 byte long.

v_santhanam at nospam dot ettimadai dot amrita dot edu 12-May-2005 11:30

if you are getting the following error : "Cannot load

/usr/local/apache2/modules/libphp4.so into server: /usr/local/apache2/ modules/libphp4.so: undefined symbol: compress" , you have to add --with-zlib to php config

sukhruprai at yahoo dot com 30-Mar-2005 03:17

(28)

For good step by step instructions read Compiling PHP and Apache 2 from source on Linux OS:

http://www10.brinkster.com/ssruprai/comphp.asp

fggarcia at ice dot co dot cr 25-Mar-2005 05:26

I think that it's important says that the option

--with-apxs2=/usr/local/apache2/bin/apxs in the configure script it's necesary to build the libphp5.so (in PHP5). Then in the make install command, this .so module will be installed in the modules directory of Apache home

I see on the Web a lot of persons with the trouble of missing the libphp5.so and this is the solution.

Regards, Frank.

mihai dot sandu at gtstelecom dot ro 28-Feb-2005 05:22

For the SuSE9.2 install of PHP5. First:

If building on a x64 platform, please set LDFLAGS="-L/usr/lib64" before configure.

As for install, it suffices to go to /etc/apache2 and: ln -s sysconfig.d/loadmodule.conf httpd2-prefork.conf and then make install

neil

10-Feb-2005 02:21

To install mysql and mysqli with PHP5 do the following: after doing:

./configure mysql=/path/to/mysql_config --with-mysqli=/path/to/mysql_config

do this: "

if you want to use both the old mysql and the new mysqli interface, load the Makefile into your editor and search for the line beginning with

EXTRA_LIBS; it includes -lmysqlclient twice; remove the second instance "

then you can: make

make install ...

Pleasse note: you must have mysql-dev installed (RPM or source) or you will not have the mysql_config file at all. The standard, server, and client installations of MySQL do not include it. I read somewhere that the mysql and mysqli paths must be identical.

Quoted from Michael Kofler at the following link:

http://www.kofler.cc/forum/forumthread.php?rootID=3571

jmartinNO at SPAMcolumbiaservices dot net 24-Jan-2005 03:44

Well I was getting the following error when trying to run make (shared module for Apache 2.0.52)

*** Warning: inter-library dependencies are not known to be supported. *** All declared inter-library dependencies are being dropped.

(Then of course 'make install' would puke on itself not having what it needs.)

(29)

Soo, after some time looking I found that using: libtoolize --force

and following the instructions to add the contents of 1 file to the local file

cat /some/dir/file1 >> localfile

Would produce the desired results when you run: make clean

make

Dan Scott (dan dot scott at acm dot org) 19-Jan-2005 08:36

Building PHP 5.x with Apache2 on SuSE Professional 9.1/9.2

SuSE uses a rather fragmented set of Apache configuration files stored in /etc/apache2/. When you configure PHP 5.x with:

$ ./configure --with-apxs2=/usr/sbin/apxs2 $ make

everything builds just fine; but when you issue: $ su -c "make install"

the unconventional Apache conf file layout confuses the install-sapi section of the Makefile and the process halts with the following error:

apxs:Error: Config file /etc/apache2/httpd2-prefork.conf not found. make: *** [install-sapi] Error 1

At this point only the PHP SAPI library has been copied into place; the rest of the files (like PEAR scripts, PHP-CLI, etc) have not been installed. But never fear! You can overcome this problem with the following steps:

1. Edit Makefile and change the following line to remove "install-sapi": install_targets = install-sapi install-cli install-pear install-build install-headers install-programs

2. Issue the make install command again: $ su -c "make install"

3. Add the PHP module & type instructions to the Apache configuration. As root, create a new file, /etc/apache2/conf.d/php5.conf that contains the following lines:

LoadModule php5_module /usr/lib/apache2/libphp5.so AddType application/x-httpd-php php

--- And that's it. Everything else is just as the documentation suggests it should be.

Jon Drukman 13-Jan-2005 04:09

We have been running Apache 2 Prefork + PHP 4 (many different versions) for well over a year now, serving 10's of millions of pages per day on dozens of servers. It is completely stable and reliable.

praveen dot k at masconit dot com 15-Nov-2004 01:38

Hi too had same problem with multiview like when i execute

http://huey/admin/test.php it used to compile but when i use

http://huey/admin/test it wouldnt recognise it as php file... i worked it

out with the addhandler method and AddType in different line and setting multiview for directive

(30)

the directives u can set it to root directory so now when u type pn test it will search in precendence for test.php, test.html if any ...

its working for me with apache2.0.47 and php 4.3.9 on solaris praveen

nospam-1 at spam dot matt dot blissett dot me dot uk 30-Sep-2004 03:52

If you're trying to get PHP and Multiviews to work properly, try this page:

http://tranchant.plus.com/notes/multiviews

(In brief, a request for the URL http://example.net/thing, where there are possible matches thing.php and thing.pdf, returns a 406 with many browsers because of the application/x-httpd-php MIME type set above. The link above gives a better method for using php, instead using these directives:

AddHandler php5-script php [or php-script for php4] AddType text/html php

(31)

Caudium

PHP 4 can be built as a Pike module for the Caudium webserver. Note that this is not supported with PHP 3. Follow the simple instructions below to install PHP 4 for Caudium.

Example 4-5. Caudium Installation Instructions

1. Make sure you have Caudium installed prior to attempting to install PHP 4. For PHP 4 to work correctly, you will need Pike 7.0.268 or newer. For the sake of this example we assume that Caudium is installed in /opt/caudium/server/.

2. Change directory to php-x.y.z (where x.y.z is the version number). 3. ./configure --with-caudium=/opt/caudium/server

4. make

5. make install

6. Restart Caudium if it's currently running.

7. Log into the graphical configuration interface and go to the virtual server where you want to add PHP 4 support.

8. Click Add Module and locate and then add the PHP 4 Script Support module.

9. If the documentation says that the 'PHP 4 interpreter isn't available', make sure that you restarted the server. If you did check /opt/caudium/logs/debug/default.1 for any errors related to <filename>PHP4.so</filename>. Also make sure that

<filename>caudium/server/lib/[pike-version]/PHP4.so</filename> is present.

10. Configure the PHP Script Support module if needed.

You can of course compile your Caudium module with support for the various extensions available in PHP 4. See the reference pages for extension specific configure options.

Note: When compiling PHP 4 with MySQL support you must make sure that the normal MySQL client code is used. Otherwise there might be conflicts if your Pike already has MySQL support. You do this by specifying a MySQL install directory the --with-mysql option.

(32)

fhttpd related notes

To build PHP as an fhttpd module, answer "yes" to "Build as an fhttpd module?" (the --with-fhttpd=DIR option to configure) and specify the fhttpd source base directory. The default directory is

/usr/local/src/fhttpd. If you are running fhttpd, building PHP as a module will give better performance, more control and remote execution capability.

(33)

Sun, iPlanet and Netscape servers on Sun Solaris

This section contains notes and hints specific to Sun Java System Web Server, Sun ONE Web Server, iPlanet and Netscape server installs of PHP on Sun Solaris.

From PHP 4.3.3 on you can use PHP scripts with the NSAPI module to generate custom directory listings and error pages. Additional functions for Apache compatibility are also available. For support in current webservers read the note about subrequests.

You can find more information about setting up PHP for the Netscape Enterprise Server (NES) here: http://benoit.noss.free.fr/php/install-php4.html

To build PHP with Sun JSWS/Sun ONE WS/iPlanet/Netscape webservers, enter the proper install directory for the --with-nsapi=[DIR] option. The default directory is usually /opt/netscape/suitespot/. Please also read /php-xxx-version/sapi/nsapi/nsapi-readme.txt.

1.

Install the following packages from http://www.sunfreeware.com/ or another download site: autoconf-2.13 automake-1.4 bison-1_25-sol26-sparc-local flex-2_5_4a-sol26-sparc-local gcc-2_95_2-sol26-sparc-local gzip-1.2.4-sol26-sparc-local m4-1_4-sol26-sparc-local make-3_76_1-sol26-sparc-local

mysql-3.23.24-beta (if you want mysql support) perl-5_005_03-sol26-sparc-local

tar-1.13 (GNU tar)

2.

Make sure your path includes the proper directories

PATH=.:/usr/local/bin:/usr/sbin:/usr/bin:/usr/ccs/bin and make it available to your system

export PATH.

3.

gunzip php-x.x.x.tar.gz (if you have a .gz dist, otherwise go to 4).

4.

tar xvf php-x.x.x.tar

5.

Change to your extracted PHP directory: cd ../php-x.x.x

6.

For the following step, make sure /opt/netscape/suitespot/ is where your netscape server is installed. Otherwise, change to the correct path and run:

./configure --with-mysql=/usr/local/mysql \ --with-nsapi=/opt/netscape/suitespot/ \ --enable-libgcc

7.

Run make followed by make install.

After performing the base install and reading the appropriate readme file, you may need to perform some additional configuration steps.

Configuration Instructions for Sun/iPlanet/Netscape. Firstly you may need to add some paths to the LD_LIBRARY_PATH environment for the server to find all the shared libs. This can best done in the start script for your webserver. The start script is often located in: /path/to/server/https-servername/start. You may also need to edit the configuration files that are located in: /path/to/server/https-servername/config/.

1.

Add the following line to mime.types (you can do that by the administration server): type=magnus-internal/x-httpd-php exts=php

2.

Edit magnus.conf (for servers >= 6) or obj.conf (for servers < 6) and add the following, shlib will vary depending on your system, it will be something like

(34)

/opt/netscape/suitespot/bin/libphp4.so. You should place the following lines after

mime types init.

Init fn="load-modules" funcs="php4_init,php4_execute,php4_auth_trans" shlib="/opt/netscape/suitespot/bin/libphp4.so"

Init fn="php4_init" LateInit="yes" errorString="Failed to initialize PHP!" [php_ini="/path/to/php.ini"]

3.

(PHP >= 4.3.3) The php_ini parameter is optional but with it you can place your php.ini in your webserver config directory.

4.

Configure the default object in obj.conf (for virtual server classes [version 6.0+] in their vserver.obj.conf):

<Object name="default"> .

. .

.#NOTE this next line should happen after all 'ObjectType' and before all 'AddLog' lines

Service fn="php4_execute" type="magnus-internal/x-httpd-php" [inikey=value inikey=value ...]

. .

</Object>

5.

(PHP >= 4.3.3) As additional parameters you can add some special php.ini-values, for example you can set a docroot="/path/to/docroot" specific to the context php4_execute is called. For boolean ini-keys please use 0/1 as value, not "On","Off",... (this will not work correctly), e.g.

zlib.output_compression=1 instead of zlib.output_compression="On"

6.

This is only needed if you want to configure a directory that only consists of PHP scripts (same like a cgi-bin directory):

<Object name="x-httpd-php">

ObjectType fn="force-type" type="magnus-internal/x-httpd-php" Service fn=php4_execute [inikey=value inikey=value ...]

</Object>

7.

After that you can configure a directory in the Administration server and assign it the style

x-httpd-php. All files in it will get executed as PHP. This is nice to hide PHP usage by renaming files

to .html.

8. Setup of authentication: PHP authentication cannot be used with any other authentication. ALL AUTHENTICATION IS PASSED TO YOUR PHP SCRIPT. To configure PHP Authentication for the entire server, add the following line to your default object:

<Object name="default"> AuthTrans fn=php4_auth_trans . . . </Object>

Figure

Table 6-1. PHP Extensions

Références

Documents relatifs

Cliquez ici pour telecharger le

Le tableau $_POST contient tous les couples variable / valeur transmis en POST, c'est à dire les informations qui ne proviennent ni de l'url, ni des cookies et ni des sessions.

10 « L imp t pay par le chef d entreprise est historiquement une somme versée pour obtenir délégation d autorit dans un domaine sp cial et pour s assurer les

Ces débats publics et politiques portent sur plusieurs questions complémentaires : le degré d’ouverture aux flux migratoires, l’intégration des migrants dans la

Dans la finale du troisième évangile, il a été démontré que la mise en intrique tourne autour de l'apparition d'un nouveau personnage dans le récit: le vivant. Et si

(…) Moi- même, quand le Président du Conseil Général m’avait demandé si je soutenais la candidature de Debré, j’avais posé trois conditions, la première condition

A partir d’une perspective d’ethnographie comparative sur les cas des bovins de combat dans les tauromachies européennes et les rodéos américains, d’une part, des

industrielle et appréhendant la nature sous l’angle de la domestication et de la propriété privée (lire ce qu’écrit Roland Barthes à propos de Jules Verne dans ses