apache、php、mysql源码安装
这里,我选择了CentOS来作为我的安装系统,当然也可以选择其它的发行版。
最小化安装系统
需要额外软件包
libjpeg-devel-6b-33
freetype-devel-2.1.9-6.el4
zlib-devel-1.2.1.2-1.2
libpng-devel-1.2.7-3.el4_5.1
gd-devel-2.0.28-5.4E
gd-2.0.28-5.4E
glibc-devel-2.3.4-2.39
gcc-3.4.6-9
glibc-kernheaders-2.4-9.1.100.EL
glibc-headers-2.3.4-2.39
以前软件最好去linux镜像中去找,这样就不需要为版本的不兼容麻烦了。
首先下载我们所需要的安装包
3. mysql-5.1.23-rc.tar.gz
将其放在/etc/local/src目录中。
1.安装apache服务器。
[root@localhost ~]# cd /usr/local/src
[root@localhost ~]# tar zxvf httpd-2.2.8.tar.gz
[root@localhost ~]# cd httpd-2.2.8
[root@localhost ~]# ./configure \
--prefix=/usr/local/apache \
--enable-mpm-worker \
--enable-so \
--enable-rewrite \
--enable-cache \
--enable-disk-cache \
--enable-mem-cache \
--enable-file-cache
[root@localhost ~]# make
[root@localhost ~]# make install
选项说明
–prefix=/usr/local/apache
将apache安装到/usr/local/apache,方便管理
–enable-mpm-worker
设置apache多任务处理,默认为–enable-mpm-prefork
其中prefork为,每建立一个连接,就建立一个进程,即,多进程并行处理,
而worker则为多线程并行处理,对于高流量的服务器来说,worker将比prefork节省更多的内存
更多请参见手册 http://httpd.apache.org/docs/2.0/mpm.html
–enable-so
so模块用来提供DSO支持的apache核心模块。
–enable-rewrite
打开URL重写模块
–enable-cache
–enable-disk-cache
–enable-mem-cache
–enable-file-cache
详细说明请参见 http://httpd.apache.org/docs/2.2/caching.html
2. mysql安装
[root@localhost ~]# cd /usr/local/src
[root@localhost ~]# tar mysql-5.1.23-rc.tar.gz
[root@localhost ~]# cd mysql-5.1.23-rc
[root@localhost ~]# ./configure \
--prefix=/usr/local/mysql \
--localstatedir=/usr/local/mysql/data \
--disable-maintainer-mode \
--with-mysqld-user=mysql \
--with-unix-socket-path=/tmp/mysql.sock \
--without-comment \
--without-debug \
--with-bench
[root@localhost ~]# make
[root@localhost ~]# make install
接下来为专门为MYSQL创建一个用户和一个用户组
[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd mysql -g mysql
mysql的用户在上面的配置中已经指定。
接下来安装系统数据库。
[root@localhost ~]# cd scripts/
[root@localhost ~]# ./mysql_install_db
设置相应目录权限
[root@localhost ~]# chown -R mysql:mysql /usr/local/mysql
[root@localhost ~]# chown -R mysql:mysql /usr/local/mysql/data
拷贝配置文件到/etc目录下
[root@localhost ~]# cd support-files/
[root@localhost ~]# cp my-medium.cnf /etc/my.cnf
后台启动mysql
[root@localhost ~]# cd /usr/local/mysql/bin
[root@localhost ~]# ./mysqld_safe &
如果要查看当前状态,启动服务器,可以通过如下方法
[root@localhost ~]# cd /usr/local/mysql/share/mysql
[root@localhost ~]# ./mysql.server [status|stop|start|restart]
3. php安装
[root@localhost ~]# cd /usr/local/src
[root@localhost ~]# tar zxvf php-5.2.5.tar.gz
[root@localhost ~]# cd php-5.2.5
[root@localhost ~]# ./configure \
--prefix=/usr/local/php \
--with-apxs2=/usr/local/apache/bin/apxs \
--enable-safe-mode \
--with-mysql=/usr/local/mysql \
--with-pdo-mysql=/usr/local/mysql/ \
--with-gd \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--without-pear
[root@localhost ~]# make
[root@localhost ~]# make install
我的php5.2.16配置選項為
./configure --prefix=/usr/local/php --with-gd=/usr/local/gd2 --with-apxs2=/usr/local/apache/bin/apxs --enable-mbregex --enable-bcmath --with-mysql=/usr/local/mysql --with-zlib-dir --enable-mbstring=all --with-pdo-mysql=/usr/local/mysql --with-freetype-dir=/usr/local/freetype --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/libpng
在64位系統編譯安裝時會報錯誤
chmod 644 /usr/local/apache/modules/libphp5.a
ranlib /usr/local/apache/modules/libphp5.a
libtool: install: warning: remember to run `libtool --finish /home/oracle/mysql/php5/php-5.2.6/libs'
Warning! dlname not found in /usr/local/apache/modules/libphp5.la.
Assuming installing a .so rather than a libtool archive.
chmod 755 /usr/local/apache/modules/libphp5.so
chmod: cannot access `/usr/local/apache/modules/libphp5.so': No such file or directory
apxs:Error: Command failed with rc=65536
baidu得知,為64位系統有個文件需要修改。
First make clean in php directory.
If you machine is X86_64. maybe the infomation as follow can help you.
For x86_64 users, many linux distributions are using a lib64 directory
as well as the standard lib directory so both 32 and 64 bit versions are
available to your system. If your libtool doesn't know about this, which
the one shipped with php doesn't, you will get this error. A lot.
The solution is *in this order*:
-run ./configure with your favorite options
-edit ./libtool: add /usr/lib64 (or wherever yours is) to
sys_lib_search_path_spec AND sys_lib_dlsearch_path_spec
then make and make install will run. (although I'm still having issues
with mysql's prebuilt binary dist. of libmysqlclient for the x86_64)
make clean
vim./libtool //確認這個文件沒有問題
make
make install
還是一樣,再檢查編譯選項中--with-zlib-dir并沒有指定路徑,在安裝時是默認安裝的,
并沒有指到一個具體目錄(因為指定就會在安裝libpng時報錯),將此項刪除。重新編譯。
OK,完成了。看來,編譯時的參數也是一個關鍵。。
拷贝php配置文件
cp php-ini-dest /usr/local/php/lib/php.ini
打开apache配置文件
vi /usr/loca/apache/conf/httpd.conf
查看libphp5.so
如果能找到,则说明php编译没有总是,否则重新编译
添加php文件后缀支持
AddType application/x-httpd-php .php
4.后续工作
把apache和mysql加到启动启动文件中
[root@localhost ~] vi /etc/rc.d/rc.local
/usr/local/apache/bin/apachectl start
/usr/local/mysql/bin/mysqld_safe --user=mysql &
5.安装时可能出现的总是及解决方法
Q. checking for termcap functions library… configure: error: No curses/termcap library
A. Fid it by doing: yum install ncurses-devel
Q. error: redeclaration of C++ built-in type ‘bool’
A.make clean make distclean 清空编译缓存,重新编译
安装MYSQL时出现总是
Q :Error: Unknown character set: ‘gbk’ Errno.: 1115
A:这个是由于在编译MSYQL的时候没有 –with-xcharset=all –with-extra-charsets=gb2312,gbk
安装PHP再现的总是
Q:configure: error: Cannot find MySQL header files under yes.
A:编译的时候指定mysql的路径 /usr/local/mysql
//重新编译
Q If configure fails try –with-jpeg-dir=configure: error: libpng.(a|so) not found.
If configure fails try –with-jpeg-dir=configure: error: libpng.(a|so) not found.
A 。安装libjpeg库
rpm -ivh libjpeg-devel-1.2.10-7.0.2.i386.rpm
Q. If configure fails try –with-jpeg-dir=configure: error: libpng.(a|so) not found.
A. 安装 libpng库
rpm -ivh libpng-devel-1.2.10-7.0.2.i386.rpm
Q. libtool: link: `ext/pdo_mysql/mysql_driver.lo’ is not a valid libtool object
A. 重新编译便可解决
Q. The mysql driver is not currently installed
A. 解决是没有安装pdo-mysql这个扩展了,重新配置,加上–with-pdo-mysql=/usr/local/mysql/