Setting up a PHP 5 with Apache 2 and MySQL 4.1.3

Source: Internet
Author: User
Tags xml parser
Address: http://www.builderau.com.au/program/0,39024614,39130604-1,00.htm

PHP 5.0 has finally arrived. Here's a step-by-step guide to setting up a cutting-edge web development environment with PHP 5.0, Apache 2.0, and MySQL 4.1.3.

After months of anticipation, PHP 5.0 has finally arrived. this latest rewrite of what was always an extraordinarily full-featured scripting language has a bunch of changes that will endear it to both novice and experienced programmers: a built-in SQLite database, more consistent implementation of the xml api through libxml2, a redesigned object model, and a brand-new Zend engine.

You definitely want to begin using PHP 5.0 for your development activities. and since you're going to have to compile and install it anyway, why not upgrade your entire lamp (Linux, Apache, MySQL, PHP) development environment? After all, there have been a series of new releases over the past few months: MySQL 4.1.3, with support for character sets, collations, subqueries, and transaction savepoints; Apache 2.0 is stable; and your Linux vendor almost certainly has a new distro you're re dying to try out.

I'm going to run you through the process of setting up a cutting-edge development environment for Web scripting with PHP, using PHP 5.0, Apache 2.0, and MySQL 4.1.3. start your terminals and warm up the compilers. let's get going!

The basics
I'm assuming that you already have a version of Linux installed and it's operational. Make sure you have a working C compiler, or you won't be able to proceed.

You also need to make sure you have downloaded all the relevant software:

  • The latest binary version of MySQL (currently MySQL 4.1.3-beta), available from mysql.com
  • The latest version of PHP (currently PHP 5.0.0), from php.net
  • The latest version of Apache 2 (currently Apache 2.0.50), from apache.org

Important Note: As of this writing, the combination of Apache 2.0 and PHP 5.0 is not completely thread-safe and shoshould not be used together in high-volume production systems. however, the combination shoshould be fine for development systems.

You may also need the following support libraries:

  • The latest libxml2 library (currently libxml2 2.6.11), from xmlsoft.org
  • The latest zlib library (currently zlib 1.2.1), from gzip.org

Copy all of these to your/tmp directory and decompress them as follows:

$ CD/tmp
$ Tar-xzvf mysql-standard-4.1.3-beta-pc-linux-i686.tar.gz
$ Tar-xzvf php-5.0.0.tar.gz
$ Tar-xzvf httpd-2.0.50.tar.gz
$ Tar-xzvf libxml2-2.6.11.tar.gz
$ Tar-xzvf zlib-1.2.1.tar.gz

Installing the support libraries
First, check if you need to install libxml2 or zlib. PHP 5.0 requires libxml2 2.6.0 (or better) and zlib 1.0.9 (or better ). if you don't have both of these, keep reading; otherwise, skip to the next section.

To begin, compile and install the libxml2 XML parser, which provides the base for the new xml api in PHP 5.0:

$ CD/tmp/libxml2-2.6.11
$./Configure
$ Make & make install

At the end of this, libxml2 shoshould be installed under/usr/local/. If you want this installed elsewhere, you shoshould specify-- PrefixOption toConfigureScript in the previous step.

Next, do the same for zlib, which provides compression services for a number of extensions:

$ CD/tmp/zlib-1.2.1
$./Configure
$ Make & make install

At the end of this, zlib shoshould also be installed under/usr/local/. As before, you can use-- PrefixOption to install it somewhere other than the default.

With the support libraries now available, we can proceed to install MySQL. PHP 5.0 no longer comes with its own version of the mysql client library because of licencing conflicts (see the database documentation for more details), so to add MySQL support to your PHP build, you have to link it against an already-existing MySQL installation.

PHP 5.0 comes with a brand-spanking-new MySQL extension called mysqli (MySQL improved), which supports all the new features in MySQL. however, this extension is available only for MySQL 4.1.2 or better, which is still in Beta. you shoshould use it only on development systems. if you're installing PHP on a production system, you can, of course, install an older, more stable version of MySQL and use the older MySQL extension that doesn't support the new capabilities.

Detailed installation instructions for MySQL are provided in the download archive, but here's a fast recap:

  1. Move the decompressed MySQL archive to/usr/local/MySQL.
  2. $ MV/tmp/mysql-standard-4.1.3-beta-pc-linux-i686
    /Usr/local/MySQL

  3. Create a user and group for MySQL.
  4. $ Groupadd MySQL
    $ Useradd-G MySQL

  5. Initialise the MySQL grant tables with the provided mysql_install_db script.
  6. $/Usr/local/MySQL/scripts/mysql_install_db
    -- User = MySQL [/output]

  7. Give the MySQL user rights to the MySQL directory.
  8. $ Chown-r root/usr/local/MySQL
    $ Chgrp-r MySQL/usr/local/MySQL
    $ Chown-r MySQL/usr/local/MySQL/Data

  9. Start the MySQL server.
    $/Usr/local/MySQL/support-files/
    MySQL. Server start [/output]

At this point, also check to make sure that the MySQL server socket has been created in/tmp-It usually has a name likeMySQL. Sock.

Installing Apache
There are two ways of using PHP with Apache: as a dynamic module that can be loaded into the web server at run-time, or as a static module that is directly compiled into the web server code. for this tutorial, I'm going with the first option.

To enable dynamic loading of PHP as an Apache 2.0 module, the Apache server must be compiled with dynamic shared object (DSO) support. This feature can be enabled by passing-- Enable-soOption to the Apache 2.0ConfigureScript:

$ CD/tmp/httpd-2.0.50
$./Configure -- prefix =/usr/local/apache2 -- enable-So $ make
& Make install

This shoshould configure, compile, and install the server to/usr/local/apache2.

With both MySQL and Apache installed, the final step is to compile and install PHP. The most important step in this process involves providing the PHPConfigureScript with a list of extensions to activate, as well as the correct file paths for the external libraries needed.ListingContains an example:

Listing

$ CD/tmp/php-5.0.0
$./Configure -- prefix =/usr/local/PhP5
-- With-apxs2 =/usr/local/apache2/bin/apxs
-- With-libxml-Dir =/usr/local/lib
-- With-zlib-Dir =/usr/local/lib
-- With-mysql =/usr/local/MySQL
-- With-mysqli =/usr/local/MySQL/bin/mysql_config
-- With-Gd -- enable-soap -- enable-sockets

This might look gut-wrenchingly complicated, but it's really not:

  • The-- PrefixArgument sets the installation path for the PHP 5.0 binaries.
  • TheWith-apxs2Argument tells PHP where to find Apache 2.0 and itsApxsScript (used to handle extensions ).
  • The-- With-libxml-DirAnd-- With-zlib-DirArguments tell PHP where to locate the libxml2 and zlib libraries. note that you need to use these options only if you compiled and installed the libraries yourself; if you're using your distribution's default libraries, PHP shoshould be able to find them automatically.
  • The-- With-MySQLArgument activatesRegularMySQL extension. Note that in PHP 5.0, This is not active by default (as it was in PHP 4.0) and must be explicitly named inConfigureTo be activated.
  • The-- With-mysqliArgument activates the new MySQL improved extension (For MySQL 4.1.2 + only), and must point toMysql_configScript that comes with MySQL 4.x.
  • The-- With-GdArgument activates the GD extension for dynamic image creation.
  • The-- With-zlibArgument activates the zlib compression library for on-the-fly data compression.
  • The-- Enable-socketsArgument activates socket communication features.
  • The-- Enable-soapArgument activates support for soap and Web services.

A number of other options and extensions are also possible-try

$./Configure -- Help

For a complete list.

OnceConfigureScript finishes processing, you can compile and install PHP.

$ Make
$ Make install

Note that the installation process is intelligent enough to place the PHP module in the correct directory for Apache 2.0 to find it.

Login ing and testing Apache with PHP
Done? Well, not quite. the final step consists of authentication ing Apache to recognize PHP scripts (named with the extension. PHP) and then hand them over to the PHP interpreter for processing. to do this, edit the Apache configuration file,/usr/local/apache2/CONF/httpd. conf, and add the following line to it:

Addtype application/X-httpd-PHP. php

Save the file and then start the server:

$/Usr/local/apache2/bin/apachectl start [/output]

Tip: You can add the command line abve to your startup scripts:/etc/rc. Local is a good bet-so that the server starts automatically on next boot.

You can now test whether all is working as it shoshould by creating a simple test script in the server's document root:/usr/local/apache2/htdocs /.

Name the scriptTest. php, And populate it with these lines:

<? PHP
Phpinfo ();
?>

Save the file and then point your browserHttp: // localhost/test. php.

You'll see a page containing information on the PHP build, like this:

Figure

In case you don't see this, try troubleshooting with the installation guide. And if you do... Well, your cutting-edge lamp environment is now Good to go! Have fun!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.