• 12005阅读
  • 0回复

PHP+GD库在LINUX上的安装[转] [复制链接]

上一主题 下一主题
离线XChinux
 

只看楼主 倒序阅读 楼主  发表于: 2005-07-30
原文见:http://www.gzicp.com/tech/dev/php/108252721639.shtml

Installing PHP, Apache, MySQL and GD on Linux
A Tank Software guide.

Target Audience
Intro
Installing
Downloading and Unpacking
Installing MySQL
Installing Apache with statically linked PHP (with GD) components
Configuring PHP/Apache
Installing PHP as a module
Conclusion

Target Audience
If you have installed linux on your system and are capable of compiling and installing programs from source (aka most linux users) then you will hopefully be able to understand and follow this tutorial.

Introduction
This tutorial has been written for people who wish to develop web pages using the dynamic scripting language PHP with the MySQL DBMS and GD Graphics libraries in a *NIX environment. Most likly the reader will have a professional server to which they are developing a web page for and wish to have a local development environment to avoid the hassle of constantly uploading files (not to mention perminent internet connection). <plug> If you don’t have a server - feel free to consider Delta IT</plug>. With the combination of PHP, Apache, MySQL and GD - you will have the tools to be able to develop dynamic database driven web sites with dynamic imageing capabilities to a fully professional level. Why PHP/Apache/MySQL/GD?? Well they are all open source, free and installed on just about all *NIX servers (which are the bulk of servers).

This work is derived from the web.blazonry : Server-side : Install Apache PHP MySQL It differs by including the GD library and more updated versions of the software. If you don’t want the GD library, then simply don’t download or install the "gd", "zlib", "libpng" "libjpeg" libraries nor include those lines in any configure statements.

Installing
Downloading and Unpacking
Download the Apache, PHP and MySQL packages. If you wish also to use the GD graphics library with PHP, download the zlib, libpng and libjpeg packages.

Apache download
PHP Source download
MySQL Download
Unpack the sources.

# tar -zxvf apache_1.3.27.tar.gz
# tar -jxvf php-4.3.0.tar.bz2
# tar -jxvf zlib-1.1.4.tar.bz2
# tar -jxvf libpng-1.2.5.tar.bz2
# tar -zxvf jpegsrc.v6b.tar.gz

Installing MySQL
Installing MySQL is a breeze on red hat - just install the rpm’s, and it installs the program. There are no links to the other programs so it usually works like a charm.

# rpm -Uvh MySQL*.rpm

Note: You most likely need to do this as the root user. Either log in or su to root.
After MySQL is installed you need to set the root password. To do this use the following commanding changing my_password to the password you want for the root user to access MySQL.


# mysqladmin -u root password ’my_password’

Note: If the MySQL service is not running, you may have to start it by hand before trying to set the password. It should start automatically when the computer boots. The command to start MySQL is:


# /etc/rc.d/init.d/mysqld start

You can test the MySQL installation by doing the following:
# mysql mysql (connect to mysql database)
Enter Password:
mysql> SELECT * FROM user; (grab some data out of user table)
This should return the data in the user table. Type exit to leave.

Installing Apache with statically linked PHP (with GD) components
Apache with PHP can be installed a few different ways. One way is to statically embed the PHP binary into the Apache binary. This is probably the fastest and best way to run PHP. You can also install PHP as a DSO module (see below)

Here are the step by step directions to install Apache and PHP in the directory /usr/local/apache

In the apache source directory (apache_1.3.27/)

# ./configure --prefix=/usr/local/apache


In the zlib source directory (zlib-1.1.4/)

# ./configure --prefix=/usr/local
# make
# make install



In the libpng source directory (libpng-1.2.5/)

# cp scripts/makefile.linux .
# mv makefile.linux makefile # make
# make install

You may want to open that file to ensure that the prefix is set to /usr/local ("prefix=/usr/local", line 15 for version 1.2.5)

In the libjpeg source directory (jpegsrc-v6b/)

# ./configure --prefix=/usr/local
# make
# make install
# cp libjpeg.* /usr/lib/



In PHP src directory (php-4.3.0/)

# ./configure --with-mysql \
--with-xml \
--enable-track-vars \
--with-apache=../apache_1.3.27 \
--with-gd \
--with-jpeg-dir=/usr/lib \
--with-zlib-dir=/usr/local/lib \
--with-png-dir=/usr/local/lib

# make
# make install


In Apache src directory (apache_1.3.27/)

# ./configure --prefix=/usr/local/apache \
--enable-module=rewrite \
--activate-module=src/modules/php4/libphp4.a

# make
# make install

Configuring PHP/Apache
To configure PHP copy php.ini-dist which is in the PHP src directory to /usr/local/lib/php.ini Edit this file setting the options you wish, generally nothing needs to be edited. However, you can set various options such as a default MySQL username and password.

To configure Apache edit /usr/local/apache/conf/httpd.conf and set the your document directory and any other Apache settings you may want. To enable Apache and PHP to work together the following line needs to be added:


AddType application/x-httpd-php .php

Look for this line or something similar already in the httpd.conf file and replace it with the above. Make sure to remove the # comment mark.

After editing the config file you need to restart Apache The command to restart Apache is:


/etc/rc.d/init.d/httpd restart

To test Apache and PHP work together create the following PHP file:
test.php


<?
echo("<h1>PHP and Apache Works!</h1>");
?>



Copy this file to the document directory, if you did not change the document directory in the config file (httpd.conf) then the default document directory is /usr/local/apache/htdocs/ Load this page in your browser using the following URL: http://localhost/test.php

You should now have Apache, PHP and MySQL all installed and working nicely together. To see how to write a web application using this setup check out the Web Database Tutorial on web.blazonry.

Installing PHP as a module
Apache PHP (DSO Module)
Another way to install Apache and PHP is by using Apache’s DSO module. Apache supports adding modules on instead of embedding them in the httpd binary. This works well when you don’t want to re-compile Apache each time a module is updated, or if you want to add on numerous modules for development purposes.

Compile Apache with DSO support
In Apache src directory (apache_1.3.14) (add the --with-gd etc flags for gd support)


# ./configure --prefix=/usr/local/apache \
--enable-module=so
--enable-module=rewrite

$ make
$ make install


Install PHP as a Module
In PHP src directory (php_4.0.3pl1)


# ./configure --with-mysql \
--with-xml \
--enable-track-vars \
--with-apxs=/usr/local/apache/bin/apxs

# make
# make install


This will install Apache and then install the PHP module into the appropiate Apache directories. The only difference in configuration from above is the module needs to be added in the Apache httpd.conf file. To add a module in Apache add the following line in the httpd.conf file (if it is not already there, sometimes the install script adds it for you)


LoadModule php4_module libexec/libphp4.so
Be sure to following the rest of the configuration instructions above.




Conclusion
I hope by now you have a good linux development platform. If you have any questions or comments, I direct you to the Tank Ammo programming forums http://tankammo.net/forums/.
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
快速回复
限100 字节
 
上一个 下一个