linux+apache+php+mysql源代码安装

安装的过程整体要分为三大过程:
安装apache 和 mysql
安装PHP
安装 memcached  php-memcache

安装apache 和 mysql
第一步  下载apache mysql;并且为二者建立对应的安装目录
#mkdir –p /opt/soft
#cd /opt/soft
#wget http://download.chyangwa.com/linux/apache/httpd-2.2.4.tar.gz
#wget http://download.chyangwa.com/linux/MySQL/mysql-5.0.19.tar.gz
#mkdir –p /usr/local/apache
#mkdir –p /usr/local/mysql

第二步   解压以及安装apache
#tar –zxvf httpd-2.2.4.tar.gz
#tar –zxvf mysql-5.0.19.tar.gz
#cd httpd-2.2.4
#./configure –prefix=/usr/local/apache –enable-so –enable-rewrite –enable-deflate –with-mpm=worker
#make && make install
#make clean
#cd

启动服务:
#/usr/local/apache/bin/apachectl –k start
然后在地址栏里面输入:本机IP/index.html 如果可以看到“It works!”就说明apache已经安装成功了

第三步 解压以及安装mysql
//建立数据库的用户和用户组:
# groupadd mysql
# useradd -g mysql mysql
//编译安装数据库:
#cd mysql-5.0.19
#./configure –prefix=/usr/local/mysql –with-extra-charsets=complex –enable-thread-safe-client –enable-local-infile –enable-assembler –disable-shared –with-client-ldflags=-all-static –with-mysqld-ldflags=-all-staticm –with-embedded-server –with-innodb –with-extra-charsets=gbk,gb2312,big5 –without-debug CFLAGS=-O3 -mcpu=pentium4 CXXFLAGS=-O3 -march=pentium4 -felide-constructors -fno-exceptions -fno-rtti CXX=gcc
# make && make install
# make clean
# cp -r mysql-5.0.19 /usr/local/mysql
# cp support-files/mysql.server /etc/rc.d/init.d/mysql
# cp support-files/my-medium.cnf /etc/my.cnf
修改mysql目录权限
# chown -R root /usr/local/mysql
# chgrp -R mysql /usr/local/mysql
# chown -R mysql /usr/local/mysql/data
生成mysql系统数据库
# /usr/local/mysql/bin/mysql_install_db –user=mysql&
# /usr/local/mysql/bin/mysqld_safe –user=mysql&
**如出现 Starting mysqld daemon with databases from /usr/local/mysql/data 代表正常启动mysql服务了.
make install结束后,新安装的需要执行bin/mysql_install_db文件来安装授权表,然后运行bin/mysqld_safe启动mysql服务。用mysql命令看是否则连接到服务器。在./configure的时候通常都会出现 checking for termcap functions library… configure: error: No curses/termcap library found这个错误!安装上libncurses5-dev (不同的系统可能名字也有所差异)这个包就好了

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
安装PHP
第一步 下载需要的组件(可以根据工作需要定制)
# cd /opt/soft
# wget http://download.chyangwa.com/linux/freetype/freetype-2.2.1.tar.gz
# wget http://download.chyangwa.com/linux/GD/gd-2.0.33.tar.gz
# wget http://download.chyangwa.com/linux/zlib/zlib-1.2.3.tar.gz
# wget http://download.chyangwa.com/linux/jpegsrc/jpegsrc.v6b.tar.gz
# wget ftp://ftp.gnu.org/gnu/gdbm/gdbm-1.8.2.tar.gz
# wget http://download.chyangwa.com/linux/gettext/gettext-0.14.5.tar.gz
# wget http://download.chyangwa.com/linux/libiconv/libiconv-1.10.tar.gz
# wget http://download.chyangwa.com/linux/libxml/libxml-1.8.17.tar.gz
# wget http://download.chyangwa.com/linux/PHP/php-5.0.5.tar.gz
# wget http://www.libpng.org/pub/png/libpng.html/libpng-1.2.25.tar.gz
为以上的安装包建立目录
# mkdir –p /usr/local/libxml
# mkdir –p /usr/local/freetype
# mkdir –p /usr/local/gd2
# mkdir –p /usr/local/zlib
# mkdir –p /usr/local/jpeg
# mkdir –p /usr/local/gdbm
# mkdir –p /usr/local/gettext
# mkdir –p /usr/local/libiconv
# mkdir –p /usr/local/libxml
# mkdir –p /usr/local/php
# mkdir –p /usr/local/libpng
第二步  安装PHP相关连的包
a.安装 jpeg6 建立目录:如果选择默认安装,可能很顺利,指定路径后,请先创建以下文件夹
# mkdir –p /usr/local/jpeg6
# mkdir –p /usr/local/jpeg6/bin
# mkdir –p /usr/local/jpeg6/lib
# mkdir –p /usr/local/jpeg6/include
# mkdir –p /usr/local/jpeg6/man
# mkdir –p /usr/local/jpeg6/man1
# mkdir –p /usr/local/jpeg6/man/man1
# cd /opt/soft/
# tar –zvxf jpegsrc.v6b.tar.gz
# cd jpeg6
# ./configure –prefix=/usr/local/jpeg6/ –enable-shared –enable-static
# make
# make install
# make install-lib
# make clean

b.libpng包(支持PNG)
# cd /opt/soft/
# tar –zvxf libpng-(version).tar.gz
# cd libpng-(version)
# ./configure –prefix=/usr/local/libpng
# make
# make install
# make clean

c.安装 freetype
# cd /opt/soft/
# tar –zvxf freetype-2.2.1.tar.gz
# cd freetype-2.2.1
# ./configure –prefix=/usr/local/freetype
# make
# make install
# make clean

d.安装zlib
# cd /root/Software/
# tar –zxvf zlib-1.2.3.tar.gz
# cd zlib.1.2.3
# mkdir /usr/local/zlib
# ./configure –prefix=/usr/local/zlib
# make
# make install
# make clean

e.安装gettext
# cd /opt/soft /
# tar –zxvf gettext-0.14.5.tar.gz
# cd gettext-0.14.5
# ./configure –prefix=/usr/local/gettext
# make
# make install
# make clean

f.安装libxml
# cd /opt/soft /
# tar –zxvf libxml-1.8.17.tar.gz
# cd libxml-1.8.17
# ./configure –prefix=/usr/local/libxml
# make
# make install
# make clean

g.安装gdbm
# cd /opt/soft /
# tar –zxvf gdbm-1.8.2.tar.gz
# cd gdbm-1.8.2
# ./configure –prefix=/usr/local/gdbm
# make
# make install
# make clean

h.安装libiconv
# cd /opt/soft /
# tar –zxvf libiconv-1.10.tar.gz
# cd libiconv-1.10
# ./configure –prefix=/usr/local/libiconv
# make
# make install
# make clean

i.安装gd2
# cd /opt/soft /
# tar –zxvf gd-2.0.33.tar.gz
# cd gd-2.0.33
# ./configure –prefix=/usr/local/gd2 –with-zlib=/usr/local/zlib/ –with-png=/usr/local/libpng/ –with-jpeg=/usr/local/jpeg/ –with-freetype=/usr/local/freetype
# make
# make install
# make clean
第三步 安装PHP
# cd /opt/soft /
# tar –zxvf php-5.0.5.tar.gz
# cd php-5.0.5.tar.gz
# ./configure –prefix=/usr/local/php –with-apxs2=/usr/local/apache/bin/apxs –with-jpeg-dir=/usr/local/jpeg/ –with-gettext –enable-mbstring –with-libxml-dir=/usr/local/libxml –with-png-dir=/usr/local/libpng/ –with-gd=/usr/local/gd2/ –with-freetype-dir=/usr/local/freetype –enable-trace-vars –with-zlib-dir=/usr/local/zlib/ –with-mysql=/usr/local/mysql –with-gdbm-dir=/usr/local/gdbm/ –enable-wddx  –with-iconv –enable-sockets –disable-ipv6
# make
# make install
# make clean
# cp php.ini-dist /usr/local/php/lib/php.ini

第四步 修改httpd.conf文件
编辑apache配置文件httpd.conf
#vi /usr/local/apache2/conf/httpd.conf

要改的有如下几处:
1一般都在
#AddType application/x-tar .tgz
下加一行
#LoadModule php5_module modules/libphp5.so
AddType application/x-httpd-php .php
如果搜索其它地方没有以下这行
LoadModule php5_module modules/libphp5.so 把上面的#号去掉
2 找到 DirectoryIndex index.html index.html.var 在后面加 index.php 让它把index.php做为默认页
3 #ServerName      把#去掉,后面的IP改成本机的IP.

第五步 测试
在apache的根目录下面(/usr/local/apache/htdocs)建立一个文件内容为:
<?php
phpinfo();
?>
保存为test.php文件
然后重启apache服务器,进行如下操作
#/usr/local/apache/bin/apachectl –k stop
#/usr/local/apache/bin/apachectl –k start
然后在地址栏里面输入:本机IP/test.php 如果可以看到php的版本以及其他相关信息就说明PHP已经安装成功了
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
安装 memcached  php-memcache
第一步  下载相关组件
#wget http://www.danga.com/memcached/dist/memcached-1.2.2.tar.gz
#wget http://pecl.php.net/package/memcache/memcache-1.2.0.tgz
#wget http://www.monkey.org/~provos/libevent-1.2.tar.gz
第二步 安装组件
libevent-1.2 安装:
默认安装:
# tar –zxvf libevent-1.2.tar.gz
# cd libevent-1.2
# ./configure
# make
# make install
# make clean
建立一个符号连接:
# ls -s /usr/local/lib/libevent-1.2.so.1 /usr/lib     否则memcached无法运行。
memcached-1.2.2 安装,
# tar –zxvf memcached-1.2.2.tar.gz
# cd memcached-1.2.2
# ./configure –prefix=/usr/local/memcached
# make
# make install
# make clean
第三步 安装Memcache的PHP扩展
1.在http://pecl.php.net/package/memcache 选择相应想要下载的memcache版本。

2.安装PHP的memcache扩展
tar vxzf memcache-2.2.1.tgz
cd memcache-2.2.1
/usr/local/php/bin/phpize
./configure –enable-memcache –with-php-config=/usr/local/php/bin/php-config –with-zlib-dir
make
make install

3.上述安装完后会有类似这样的提示:
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20041030/

4.把php.ini中的extension_dir = “./”修改为
extension_dir = “/usr/local/php/lib/php/extensions/no-debug-zts-20041030/”

5.添加一行来载入memcache扩展:extension=memcache.so

memcached的基本设置:

启动Memcache的服务器端:
# /usr/local/bin/memcached -d -m 10 -u root -l 192.168.1.55 -p 12000 -c 256 -P /tmp/memcached.pid

-d选项是启动一个守护进程,
-m是分配给Memcache使用的内存数量,单位是MB;
-u是运行Memcache的用户;
-l是监听的服务器IP地址;
-p是设置Memcache监听的端口,最好是1024以上的端口;
-c选项是最大运行的并发连接数,默认是1024;
-P是设置保存Memcache的pid文件,这里是保存在 /tmp/memcached.pid;

2.如果要结束Memcache进程,执行:
# kill `cat /tmp/memcached.pid`
也可以启动多个守护进程,不过端口不能重复。

3. 然后重启apache服务器,进行如下操作
#/usr/local/apache/bin/apachectl –k stop
#/usr/local/apache/bin/apachectl –k start

Memcache环境测试:
建立一个文件为pptest.php内容如下:
<?php
$mem = new Memcache;
$mem->connect(“127.0.0.1”,11211);
$mem->set(‘key’,’this is a test!’,0,60);
$val = $mem->get(‘key’);
echo $val;
?>
然后在地址栏里面输入:本机IP/pptest.php 如果可以看到this is a test!就说明已经安装成功了

发表评论

邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据