分享
 
 
 

Setting up a PHP 5 with Apache 2 and MySQL 4.1.3

王朝mysql·作者佚名  2006-04-07
窄屏简体版  字體: |||超大  

原文地址: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 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 should not be used together in high-volume production systems. However, the combination should 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 should be installed under /usr/local/. If you want this installed elsewhere, you should specify the --prefix option to the configure script 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 should also be installed under /usr/local/. As before, you can use the --prefix option 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 should 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:

Move the decompressed MySQL archive to /usr/local/mysql.

$ mv /tmp/mysql-standard-4.1.3-beta-pc-linux-i686

/usr/local/mysql

Create a user and group for MySQL.

$ groupadd mysql

$ useradd -g mysql mysql

Initialise the MySQL grant tables with the provided mysql_install_db script.

$ /usr/local/mysql/scripts/mysql_install_db

--user=mysql [/output]

Give the MySQL user rights to the MySQL directory.

$ chown -R root /usr/local/mysql

$ chgrp -R mysql /usr/local/mysql

$ chown -R mysql /usr/local/mysql/data

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 like mysql.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 the --enable-so option to the Apache 2.0 configure script:

$ cd /tmp/httpd-2.0.50

$ ./configure --prefix=/usr/local/apache2 --enable-so $ make

&& make install

This should 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 PHP configure script with a list of extensions to activate, as well as the correct file paths for the external libraries needed. Listing A contains an example:

Listing A

$ 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 --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 --prefix argument sets the installation path for the PHP 5.0 binaries.

The --with-apxs2 argument tells PHP where to find Apache 2.0 and its apxs script (used to handle extensions).

The --with-libxml-dir and --with-zlib-dir arguments 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 should be able to find them automatically.

The --with-mysql argument activates the regular MySQL 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 in configure to be activated.

The --with-mysqli argument activates the new MySQL Improved extension (for MySQL 4.1.2+ only), and must point to the mysql_config script that comes with MySQL 4.x.

The --with-gd argument activates the GD extension for dynamic image creation.

The --with-zlib argument activates the ZLIB compression library for on-the-fly data compression.

The --enable-sockets argument activates socket communication features.

The --enable-soap argument activates support for SOAP and Web services.

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

$ ./configure --help

for a complete list.

Once the configure script 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.

Configuring and testing Apache with PHP

Done? Well, not quite. The final step consists of configuring Apache to recognise 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 above 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 should by creating a simple test script in the server's document root: /usr/local/apache2/htdocs/.

Name the script test.php, and populate it with these lines:

<?php

phpinfo();

?>

Save the file and then point your browser to http://localhost/test.php.

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

Figure A

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!

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有