Install AMP from source under Linux(Ubuntu)

Install AMP from source under Linux(Ubuntu)

2011-02-05 星期六 晴朗

Install AMP from source under Linux(Ubuntu)

安装Apache2.2.17

Follow the instruction in the offical website, it should work:
Overview for the impatient

Download $ lynx http://httpd.apache.org/download.cgi
Extract $ gzip -d httpd-2_0_NN.tar.gz 
$ tar xvf httpd-2_0_NN.tar
Configure $ ./configure --prefix=PREFIX
Compile $ make
Install $ make install
Customize $ vi PREFIX/conf/httpd.conf
Test $ PREFIX/bin/apachectl start

说明:上面的./configure只指定了安装目录,这种编译方式是静态编译方式,并且只包含最核型的模块,如下:

forrest@forrest-laptop:~/Install/apache2/modules$ ls
httpd.exp  libphp5.so

说明:libphp5.so是我后来编译php才进入的。可以用httpd -l选项查看静态编译进入的模块(注意查看不到动态加载的模块的,如mod_php5.so)

forrest@forrest-laptop:~/Install/apache2$ bin/httpd -l
Compiled in modules:
  core.c
  mod_authn_file.c
  mod_authn_default.c
  mod_authz_host.c
  mod_authz_groupfile.c
  mod_authz_user.c
  mod_authz_default.c
  mod_auth_basic.c
  mod_include.c
  mod_filter.c
  mod_log_config.c
  mod_env.c
  mod_setenvif.c
  mod_version.c
  prefork.c
  http_core.c
  mod_mime.c
  mod_status.c
  mod_autoindex.c
  mod_asis.c
  mod_cgi.c
  mod_negotiation.c
  mod_dir.c
  mod_actions.c
  mod_userdir.c
  mod_alias.c
  mod_so.c

这样的编译方式往往只能满足最小化的需求,对于一个比较大型的网站,往往需要更多的module,比如mod_rewrite,比如mod_ssl,比如mod_jk,etc. 主要有两种解决方案:
第一种方式是重新安装,这就是静态编译模块的坏处,一旦需要新增或者修改删除模块,需要重新编译整个apache。所以建议下次如果是重新编译的话,务必改成动态链接。如果要支持ssl,那么需要在编译的时候增加编译选项:--enable-ssl=shared。第二种方式是,编译成动态链接库(so),配置httpd.conf,让apache启动时加载(LoadModules)。
官方文档写的很详细,也很精彩:http://httpd.apache.org/docs/2.0/dso.html

使用如下编译方式,也不会生成很多modules:

forrest@forrest-laptop:~/Sources/httpd-2.2.17$ ./configure --prefix=/home/forrest/Install/apache2_dynamic --enable-modules=all --enable-so 
forrest@forrest-laptop:~/Install/apache2_dynamic/modules$ ls
httpd.exp

加上 --enable-mods-shared=all之后,就有很多modules了:

forrest@forrest-laptop:~/Sources/httpd-2.2.17$ ./configure --prefix=/home/forrest/Install/apache2_dynamic3 --enable-modules=all --enable-so --enable-mods-shared=all

forrest@forrest-laptop:~/Install/apache2_dynamic3/modules$ ls
httpd.exp           mod_authn_default.so    mod_cern_meta.so  mod_expires.so     mod_log_forensic.so  mod_status.so
mod_actions.so      mod_authn_file.so       mod_cgi.so        mod_ext_filter.so  mod_logio.so         mod_substitute.so
mod_alias.so        mod_authz_dbm.so        mod_dav_fs.so     mod_filter.so      mod_mime_magic.so    mod_unique_id.so
mod_asis.so         mod_authz_default.so    mod_dav.so        mod_headers.so     mod_mime.so          mod_userdir.so
mod_auth_basic.so   mod_authz_groupfile.so  mod_dbd.so        mod_ident.so       mod_negotiation.so   mod_usertrack.so
mod_auth_digest.so  mod_authz_host.so       mod_deflate.so    mod_imagemap.so    mod_reqtimeout.so    mod_version.so
mod_authn_anon.so   mod_authz_owner.so      mod_dir.so        mod_include.so     mod_rewrite.so       mod_vhost_alias.so
mod_authn_dbd.so    mod_authz_user.so       mod_dumpio.so     mod_info.so        mod_setenvif.so
mod_authn_dbm.so    mod_autoindex.so        mod_env.so        mod_log_config.so  mod_speling.so

forrest@forrest-laptop:~/Install/apache2_dynamic3/modules$ ls | wc -l
52

即使设置为all,仍然是有些模块有,有些模块没有:

forrest@forrest-laptop:~/Install/apache2_dynamic3/modules$ ls | grep ssl
forrest@forrest-laptop:~/Install/apache2_dynamic3/modules$ ls | grep rewrite
mod_rewrite.so

对于ssl模块,需要在编译的时候再加上--enable-ssl编译选项。但是需要注意的是ssl需要openssl的头文件,所以需要先安装openssl。

改成most,变成47个。

forrest@forrest-laptop:~/Sources/httpd-2.2.17$ ./configure --prefix=/home/forrest/Install/apache2_dynamic --enable-modules=all --enable-so --enable-mods-shared=most
forrest@forrest-laptop:~/Install/apache2_dynamic/modules$ ls
httpd.exp           mod_authn_dbm.so        mod_authz_user.so  mod_dumpio.so      mod_include.so      mod_setenvif.so
mod_actions.so      mod_authn_default.so    mod_autoindex.so   mod_env.so         mod_info.so         mod_speling.so
mod_alias.so        mod_authn_file.so       mod_cgi.so         mod_expires.so     mod_log_config.so   mod_status.so
mod_asis.so         mod_authz_dbm.so        mod_dav_fs.so      mod_ext_filter.so  mod_logio.so        mod_substitute.so
mod_auth_basic.so   mod_authz_default.so    mod_dav.so         mod_filter.so      mod_mime.so         mod_userdir.so
mod_auth_digest.so  mod_authz_groupfile.so  mod_dbd.so         mod_headers.so     mod_negotiation.so  mod_version.so
mod_authn_anon.so   mod_authz_host.so       mod_deflate.so     mod_ident.so       mod_reqtimeout.so   mod_vhost_alias.so
mod_authn_dbd.so    mod_authz_owner.so      mod_dir.so         mod_imagemap.so    mod_rewrite.so
forrest@forrest-laptop:~/Install/apache2_dynamic/modules$ ls | wc -l
47

发现其实其关键作用的只是这个编译选项: --enable-mods-shared=most

forrest@forrest-laptop:~/Sources/httpd-2.2.17$ ./configure --prefix=/home/forrest/Install/apache2_dynamic --enable-mods-shared=most
forrest@forrest-laptop:~/Install/apache2_dynamic/modules$ ls | wc -l
47

安装mod_ssl,这个module在apache的源码中,只需要增加--enable-ssl编译选项,就可以了。不像mod_jk和mod_php,需要另外下载代码,用apxs安装。
不过需要注意的是ssl需要openssl的头文件,所以需要先安装openssl。

checking whether to enable mod_ssl... checking dependencies
checking for SSL/TLS toolkit base... none
checking for OpenSSL version... checking openssl/opensslv.h usability... no
checking openssl/opensslv.h presence... no
checking for openssl/opensslv.h... no
checking openssl/ssl.h usability... no
checking openssl/ssl.h presence... no
checking for openssl/ssl.h... no
no OpenSSL headers found
checking for SSL-C version... checking sslc.h usability... no
checking sslc.h presence... no
checking for sslc.h... no
no SSL-C headers found
configure: error: ...No recognized SSL/TLS toolkit detected

forrest@forrest-laptop:~/Sources/httpd-2.2.17$ sudo apt-get install openssl libssl-dev

forrest@forrest-laptop:~/Sources/httpd-2.2.17$ ./configure --prefix=/home/forrest/Install/apache2_dynamic --enable-mods-shared=most --enable-ssl 
forrest@forrest-laptop:~/Install/apache2_dynamic/modules$ ls
httpd.exp           mod_authn_dbm.so        mod_authz_user.so  mod_dumpio.so      mod_include.so      mod_setenvif.so
mod_actions.so      mod_authn_default.so    mod_autoindex.so   mod_env.so         mod_info.so         mod_speling.so
mod_alias.so        mod_authn_file.so       mod_cgi.so         mod_expires.so     mod_log_config.so   mod_ssl.so
mod_asis.so         mod_authz_dbm.so        mod_dav_fs.so      mod_ext_filter.so  mod_logio.so        mod_status.so
mod_auth_basic.so   mod_authz_default.so    mod_dav.so         mod_filter.so      mod_mime.so         mod_substitute.so
mod_auth_digest.so  mod_authz_groupfile.so  mod_dbd.so         mod_headers.so     mod_negotiation.so  mod_userdir.so
mod_authn_anon.so   mod_authz_host.so       mod_deflate.so     mod_ident.so       mod_reqtimeout.so   mod_version.so
mod_authn_dbd.so    mod_authz_owner.so      mod_dir.so         mod_imagemap.so    mod_rewrite.so      mod_vhost_alias.so
forrest@forrest-laptop:~/Install/apache2_dynamic/modules$ ls |wc -l
48

2. 安装MySQL5.1.7

参考文档:http://dev.mysql.com/doc/refman/5.1/en/installing-source-distribution.html

# Preconfiguration setup
shell> groupadd mysql
shell> useradd -g mysql mysql
# Beginning of source-build specific instructions
shell> tar zxvf mysql-VERSION.tar.gz
shell> cd mysql-VERSION
shell> ./configure --prefix=/home/forrest/Install/mysql
shell> make
shell> make install
# End of source-build specific instructions
# Postinstallation setup
shell> cd /usr/local/mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> bin/mysql_install_db --user=mysql --with-datadir=/home/forrest/Install/mysql/data
shell> chown -R root .
shell> chown -R mysql var
# Next command is optional
shell> cp support-files/my-medium.cnf /etc/my.cnf
shell> add basedir and datadir to [mysqld]
shell> bin/mysqld_safe --user=mysql &
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server
forrest@forrest-laptop:~/Install/mysql$ bin/mysql_install_db --user=mysql --basedir=/home/forrest/Install/mysql --datadir=/home/forrest/Install/mysql/data
Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/home/forrest/Install/mysql/bin/mysqladmin -u root password 'new-password'
/home/forrest/Install/mysql/bin/mysqladmin -u root -h forrest-laptop password 'new-password'

Alternatively you can run:
/home/forrest/Install/mysql/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /home/forrest/Install/mysql ; /home/forrest/Install/mysql/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /home/forrest/Install/mysql/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /home/forrest/Install/mysql/scripts/mysqlbug script!

forrest@forrest-laptop:~/Install/mysql$ 

set the root password:
/home/forrest/Install/mysql/bin/mysqladmin -u root password 'new-password'
update the root password:
mysql> update user set password=PASSWORD("NEWPASSWORD") where User='root';
mysql> flush privileges;
mysql> quit

3. PHP5.2.7

forrest@forrest-laptop:~/Sources/php-5.2.17$ ./configure --with-apxs2=/home/forrest/Install/apache2/bin/apxs --with-mysql=/home/forrest/Install/mysql/
forrest@forrest-laptop:~/Sources/php-5.2.17$ make
forrest@forrest-laptop:~/Sources/php-5.2.17$ sudo make install
[sudo] password for forrest: 
Installing PHP SAPI module:       apache2handler
/home/forrest/Install/apache2/build/instdso.sh SH_LIBTOOL='/home/forrest/Install/apache2/build/libtool' libphp5.la /home/forrest/Install/apache2/modules
/home/forrest/Install/apache2/build/libtool --mode=install cp libphp5.la /home/forrest/Install/apache2/modules/
cp .libs/libphp5.so /home/forrest/Install/apache2/modules/libphp5.so
cp .libs/libphp5.lai /home/forrest/Install/apache2/modules/libphp5.la
libtool: install: warning: remember to run `libtool --finish /home/forrest/Sources/php-5.2.17/libs'
chmod 755 /home/forrest/Install/apache2/modules/libphp5.so
[activating module `php5' in /home/forrest/Install/apache2/conf/httpd.conf]
Installing PHP CLI binary:        /usr/local/bin/
Installing PHP CLI man page:      /usr/local/man/man1/
Installing build environment:     /usr/local/lib/php/build/
Installing header files:          /usr/local/include/php/
Installing helper programs:       /usr/local/bin/
  program: phpize
  program: php-config
Installing man pages:             /usr/local/man/man1/
  page: phpize.1
  page: php-config.1
Installing PEAR environment:      /usr/local/lib/php/
[PEAR] Archive_Tar    - installed: 1.3.7
[PEAR] Console_Getopt - installed: 1.2.3
[PEAR] Structures_Graph- installed: 1.0.3
[PEAR] XML_Util       - installed: 1.2.1
[PEAR] PEAR           - installed: 1.9.1
Wrote PEAR system config file at: /usr/local/etc/pear.conf
You may want to add: /usr/local/lib/php to your php.ini include_path
Installing PDO headers:          /usr/local/include/php/ext/pdo/
forrest@forrest-laptop:~/Sources/php-5.2.17$
Enabling the mysqli Extension on Linux/Unix
Enabling the mysqli extension on the Linux/Unix platform is accomplished by configuring PHP using the --with-mysqli flag. This flag should point to the location of the mysql_config program available to MySQL 4.1 and greater.

关于PHP的配置文件——php.ini
与MySQL一样,PHP也有自己的配置文件,叫做php.ini,与MySQL一样,这个配置文件需要用户自己cp到某个特定的目录(配置目录,编译选项--with-config-file-path 指定)。
如果没有指定,默认是/usr/local/lib/目录下。可以使用phpinfo()查看:

 

Configuration File (php.ini) Path /usr/local/lib
Configuration File (php.ini) Path /usr/local/lib

PHP comes bundled with a configuration file that controls many aspects of PHP's behavior. This file is known as php.ini, but it was originally named php.ini-dist. You need to copy this file to its appropriate location and rename it php.ini. The later section "Configuring PHP" examines php.ini's purpose and contents in detail. Note that you can place this configuration file anywhere you please, but if you choose a nondefault location, you also need to configure PHP using the --with-config-file-path option. Also note that there is another
default configuration file at your disposal, php.ini-recommended. This file sets various nonstandard settings and is intended to better secure and optimize your installation, although this configuration may not be fully compatible with some of the legacy applications. Consider using this file in lieu of php.ini-dist. To use this file, execute the following command:
%>cp php.ini-recommended /usr/local/lib/php.ini

在Unix上,php.ini文件缺省放在/usr/local/lib上面,因为缺省的存放路径是<install-path> /lib,但是可以在编译的时候使用--wthi-config-file-path参数来修改php.ini的存放位置,例如你可以使用--with-config-file-path=/etc把它存放到/etc下面,然后可以从源码包中拷贝php.ini-dist到/etc/php.ini并修改使之满足需要。

4. phpMyAdmin

http://www.phpmyadmin.net/documentation/

5. Testing Your Installation

The best way to verify your PHP installation is by attempting to execute a PHP script. Open a text editor and add the following lines to a new file:

<?php
phpinfo();
?>

Save this file as phpinfo.php. If you're running Apache, save it to the htdocs directory. If you're
running IIS, save the file to C:\inetpub\wwwroot.


关于PEAR:

PEAR (the acronym for PHP Extension and Application Repository) is one of the most effective means for finding and reusing great PHP code. Inspired by Perl's wildly popular CPAN (Comprehensive Perl Archive Network), the PEAR project was started in 1999 by noted PHP developer Stig Bakken, with the first stable release bundled with PHP version 4.3.0.

可以使用pear管理(安装卸载、升降级)packages。然后应用程序只需要将需要使用的packages Including进来。
Including a Package within Your Scripts

Using an installed PEAR package is simple. All you need to do is make the package contents available to
your script with include or preferably require. Keep in mind that you need to add the PEAR base
directory to your include_path directive; otherwise, an error similar to the following will occur:
Fatal error: Class 'MDB2' not found in /home/www/htdocs/book/11/database.php
on line 3
Those of you with particularly keen eyes might have noticed that in the earlier example involving
the Numbers_Roman package, a directory was also referenced:
require_once("Numbers/Roman.php");

像mysql和gd这样的库没有在PEAR中,只能重新编译PHP模块。

猜你喜欢

转载自arganzheng.iteye.com/blog/999448
今日推荐