LAMP 完整过程 apache --> mysql --> php

apache安装

[root@zheng ma]# tar zxf libxml2-2.9.0.tar.gz -C /usr/src
[root@zheng ma]# tar zxf autoconf-2.69.tar.gz -C /usr/src/
[root@zheng ma]# tar zxf libmcrypt-2.5.8.tar.gz -C /usr/src/
[root@zheng ma]# tar zxf libmcrypt-2.5.8.tar.gz -C /usr/src/
[root@zheng ma]# tar zxf mhash-0.9.9.9.tar.gz -C /usr/src/
[root@zheng ma]# tar zxf mcrypt-2.6.8.tar.gz -C /usr/src/
[root@zheng ma]# tar zxf zlib-1.2.7.tar.gz -C /usr/src/
[root@zheng ma]# tar zxf libpng-1.5.14.tar.gz -C /usr/src/
[root@zheng ma]# tar zxf jpegsrc.v8b.tar.gz -C /usr/src/
[root@zheng ma]# tar zxf freetype-2.4.10.tar.gz -C /usr/src/
[root@zheng ma]# tar zxf gd-2.0.35.tar.gz -C /usr/src/
[root@zheng ma]# tar zxf apr-1.4.6.tar.gz -C /usr/src/
[root@zheng ma]# tar zxf apr-util-1.5.1.tar.gz -C /usr/src/
[root@zheng ma]# tar zxf pcre-8.32.tar.gz -C /usr/src/
[root@zheng ma]# tar zxf httpd-2.4.4.tar.gz -C /usr/src/
[root@zheng ma]# tar zxf mysql-5.1.68.tar.gz -C /usr/src/
[root@zheng ma]# tar zxf php-5.4.13.tar.gz -C /usr/src/


libxml2-2.9.0.tar.gz

[root@zheng ma]# cd /usr/src/libxml2-2.9.0/
[root@zheng libxml2-2.9.0]# ./configure --prefix=/usr/local/libxml2 ;make ;make install

autoconf-2.69.tar.gz

[root@zheng ma]# cd /usr/src/autoconf-2.69
[root@zheng autoconf-2.69]# ./configure

libmcrypt-2.5.8.tar.gz

[root@zheng ma]# cd /usr/src/libmcrypt-2.5.8/
[root@zheng libmcrypt-2.5.8]# ./configure ;make ;make install
[root@zheng libmcrypt-2.5.8]#  ln -s /usr/local/lib/libmcrypt.*  /usr/lib/ 优化

libltdl库
[root@zheng libltdl]# cd /usr/src/libmcrypt-2.5.8/libltdl/
[root@zheng libltdl]# ./configure --enable-ltdl-install ;make ;make install

mhash-0.9.9.9.tar.gz

[root@zheng ma]# cd /usr/src/mhash-0.9.9.9/
[root@zheng mhash-0.9.9.9]# ./configure ;make ;make install
[root@zheng mhash-0.9.9.9]# ln -s /usr/local/lib/libmhash.* /usr/lib 优化

mcrypt-2.6.8.tar.gz

[root@zheng ma]# cd /usr/src/mcrypt-2.6.8/
[root@zheng mcrypt-2.6.8]# ./configure ;make ;make install

zlib-1.2.7.tar.gz

[root@zheng ma]# cd /usr/src/zlib-1.2.7/
[root@zheng zlib-1.2.7]# ./configure --prefix=/usr/local/zlib/ ;make ;make install

libpng-1.5.14.tar.gz

[root@zheng ma]# cd /usr/src/libpng-1.5.14
[root@zheng libpng-1.5.14]# ./configure --prefix=/usr/local/libpng ;make ;make install

jpegsrc.v8b.tar.gz

[root@zheng ma]# cd /usr/src/jpeg-8b
[root@zheng jpeg-8b]# mkdir -p /usr/local/jpeg8
[root@zheng jpeg-8b]# mkdir -p /usr/local/jpeg8/bin
[root@zheng jpeg-8b]# mkdir -p /usr/local/jpeg8/lib
[root@zheng jpeg-8b]# mkdir -p /usr/local/jpeg8/include
[root@zheng jpeg-8b]# mkdir -p /usr/local/jpeg8/man/man1
[root@zheng jpeg-8b]# ./configure --prefix=/usr/local/jpeg8/ --enable-share ;make ;make install

freetype-2.4.10.tar.gz

[root@zheng ma]# cd /usr/src/freetype-2.4.10
[root@zheng freetype-2.4.10]# ./configure --prefix=/usr/local/freetype ;make;make install

gd-2.0.35.tar.gz

[root@zheng ma]# cd /usr/src/gd-2.0.35
[root@zheng gd-2.0.35]# ./configure --prefix=/usr/local/gd --with-jpeg=/usr/local/jpeg8/ --with-png=/usr/local/libpng/ --with-freetype=/usr/local/freetype/ ;make ;make install

apr-1.4.6.tar.gz

[root@zheng ma]# cd /usr/src/apr-1.4.6
[root@zheng apr-1.4.6]# ./configure --prefix=/usr/local/apr ;make ;make install

apr-util-1.5.1.tar.gz

[root@zheng ma]# cd /usr/src/apr-util-1.5.1
[root@zheng apr-util-1.5.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config ;make ;make install

pcre-8.32.tar.gz

[root@zheng ma]# cd /usr/src/pcre-8.32
[root@zheng pcre-8.32]# ./configure --prefix=/usr/local/pcre ;make ;make install

httpd-2.4.4.tar.gz

[root@zheng ma]# cd /usr/src/httpd-2.4.4
[root@zheng httpd-2.4.4]# /configure \
> --prefix=/usr/local/httpd \
> --enable-mods-shared=all \
> --enable-deflate \
> --enable-speling \
> --enable-cache \
> --enable-file-cache \
> --enable-disk-cache \
> --enable-mem-cache \
> --enable-so \
> --enable-expires=shared \
> --enable-rewrite=shared \
> --enable-static-support \
>--enable-charset-lite \
>--enable-cgi \
> --sysconfdir=/etc/httpd \
> --with-z=/usr/local/zlib/ \
> --with-apr=/usr/local/apr/ \
> --with-apr-util=/usr/local/apr-util/ \
> --with-pcre=/usr/local/pcre/ \
> --disable-userdir ;make ;make install


[root@zheng httpd-2.4.4]# ln -s /usr/local/httpd/bin/* /usr/local/bin/
[root@zheng httpd-2.4.4]# cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
[root@zheng httpd-2.4.4]# vi /etc/init.d/httpd

#!/bin/bash
# chkconfig: 35 85 15
# description: This is My Apache HTTP Server!

[root@zheng httpd]# chkconfig --add httpd
[root@zheng httpd]# chkconfig --list httpd
[root@zheng httpd]# vi /usr/local/httpd/conf/httpd.conf 

需要一个泛域名解析的顶级域名,例如:zheng.com
在 httpd.conf 中打开 mod_rewrite功能选项
然后在 httpd.conf 的最后,添加以下内容:

RewriteEngine on
RewriteMap lowercase int:tolower
RewriteMap vhost txt:/usr/local/etc/apache/vhost.map
RewriteCond ${lowercase:%{SERVER_NAME}} ^(.+)$
RewriteCond ${vhost:%1} ^(/.*)$
RewriteRule ^/(.*)$ %1/$1

其中的 /usr/local/etc/apache 是你的 apache 服务器配置文件所在路径,根据实际情况更改。
  
然后,在这个所在路径的目录下创建一个文件: vhost.map
内容为:
www.zheng.com /usr/local/www/www
bbs.zheng.com /usr/local/www/bbs
photo.zheng.com /usr/local/www/photo

最后,在你的网站根目录 /usr/local/www 下,创建对应目录:www , bbs , 等等,理论上不限制的。
  
这样,通过浏览器,访问 www.zheng.com 时,实际上访问的就是 /usr/local/www/zheng目录下的文件。同理,访问 bbs.zheng.com 实际上访问的就是 /usr/local/www/bbs 目录下的文件。而且,你可以随时更改 vhost.map 来增加、删除、修改你的二级域名和所指向的实际路径。
 

安装mysql
mysql-5.1.68.tar.gz

[root@zheng htdocs]# useradd -M -u 48 -s /sbin/nologin mysql

[root@zheng ma]# tar zxf mysql-5.1.68.tar.gz -C /usr/src/
[root@zheng mysql-5.1.68]# ./configure --prefix=/usr/local/mysql --enable-thread-safe-client --with-extra-charsets=all ;make ;make install
[root@zheng mysql-5.1.68]# cp support-files/my-medium.cnf /etc/my.cnf
[root@zheng mysql]# cd /usr/local/mysql/
[root@zheng mysql]# bin/mysql_install_db --user=mysql
[root@zheng mysql]# chown -R root:mysql /usr/local/mysql/
[root@zheng mysql]# chown -R mysql /usr/local/mysql/var/
[root@zheng mysql-5.1.68]#  cp support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@zheng mysql-5.1.68]# chmod +x /etc/rc.d/init.d/mysqld
[root@zheng mysql-5.1.68]#  chkconfig --add mysqld
[root@zheng mysql-5.1.68]# service mysqld start

bin/mysqladmin version -p 查看版本号
 删除空用户
[root@localhost ~]# mysql -u root -p
Enter password:
mysql> select user,host,password from mysql.user where user='';
mysql> delete from mysql.user where user='';
mysql> select user,host,password from mysql.user where user='';
mysql> delete from mysql.user where host!='localhost';
flush privileges; 刷新授权表
set password for 'root'@'localhost'=password('123456'); 修改密码
create database dz;
use dz;
create table shop(id int, name varchar(30), price double);
show tables;

安装php

php-5.4.13.tar.gz

[root@zheng ma]# tar zxf php-5.4.13.tar.gz -C /usr/src/
[root@zheng ma]# cd /usr/src/php-5.4.13/
[root@zheng php-5.4.13]#

译之前,先处理一下mysql的库,默认查找libmysqlclient_r.so,可是mysql默认为libmysqlclient.so,内容完全一样,做个链接即可
# cd /usr/local/mysql/lib/mysql/
# ln -s libmysqlclient.so.15.0.0 libmysqlclient_r.so

还会报make: *** [ext/gd/gd.lo] error 这个错误算是php5.4的bug

解决方法:

vi /usr/local/gd/include/gd_io.h

gdIOCtx结构中增加void *data;
格式如下
typedef struct gdIOCtx
{
int (*getC) (struct gdIOCtx *);

int (*getBuf) (struct gdIOCtx *, void *, int);
 
void (*putC) (struct gdIOCtx *, int);

int (*putBuf) (struct gdIOCtx *, const void *, int);
 
/* seek must return 1 on SUCCESS, 0 on FAILURE. Unlike fseek! */

int (*seek) (struct gdIOCtx *, const int);
 
long (*tell) (struct gdIOCtx *);
 
void (*gd_free) (struct gdIOCtx *);

void (*data);   //添加

}
gdIOCtx;

make: *** [ext/phar/phar.php] Error 127
解决方法:
ln -s /usr/local/lib/libltdl.so.3 /usr/lib/libltdl.so.3
[root@localhost   ~]# cd /usr/local/libpng/lib/
[root@localhost   lib]# ls
libpng15.a   libpng15.so     libpng15.so.15.10.0  libpng.la  pkgconfig
libpng15.la  libpng15.so.15  libpng.a             libpng.so
可以看到libpng15.so.15
然后修改/etc/ld.so.conf 文件:vi /etc/ld.so.conf
在第一行下面追加/usr/local/libpng/lib这个路径。
然后重新编译安装即可。

编译安装
[root@localhost   php-5.4.11]#
./configure
--prefix=/usr/local/php5
--with-config-file-path=/usr/local/php5/etc
--with-apxs2=/usr/local/httpd/bin/apxs
--with-mysql=/usr/local/mysql/ 
--with-php-config=/usr/local/php5/bin/php-config
--with-libxml-dir=/usr/local/libxml2/
--with-png-dir=/usr/local/libpng/
--with-jpeg-dir=/usr/local/jpeg8/
--with-freetype-dir=/usr/local/freetype/
--with-gd=/usr/local/gd/ --with-zlib-dir=/usr/local/zlib/
--with-mcrypt=/usr/local/libmcrypt/
--with-mysqli=/usr/local/mysql/bin/mysql_config
--with-mhash=/usr/local/lib/
--enable-soap
--enable-xml
--enable-fpm
--enable-fastcgi
--enable-zip=shared
--enable-mbstring=all
--enable-zend-multibyte
--enable-sockets
--enable-ftp
;make;make install

修改参数
[root@zheng php-5.4.13]# cp php.ini-development /usr/local/php5/etc/php.ini
[root@zheng www]# vi /usr/local/php5/etc/php.ini

修改php.ini 把;date.timezone 前面的分号去掉,改成date.timezone ="PRC"

[root@zheng php-5.4.13]# vi /etc/httpd/httpd.conf

修改264行   DirectoryIndex index.html
            DirectoryIndex index.php index.html
在392行下添加
AddType application/x-httpd-php .php .phtml
phpMyAdmin修改
[root@zheng mysql]# cp config.sample.inc.php config.inc.php

PDO_Mysql 错误
====================================================================================
假设你的php是安装在/usr/local/php5里的。
1。解压 PDO_MYSQL-1.0.2.tgz  到/usr/local/php5/bin 下
2.执行/usr/local/php5/bin/phpize
3.然后进行编译安装
./configure --with-php-config=/usr/local/php5/bin/php-config --with-pdo-mysql=/usr/local/mysql ;make ;make install (假设你的mysql是安装在/usr/local/mysql)
4.到了第3步的时候。在/usr/local/php5/lib/php/extensions里就会多了个no-debug-non-zts-20050922文件夹,它里面就生成了一个pdo_mysql.so
5.修改php.ini,在最后 加入扩展语句

extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20050922/pdo_mysql.so"

6.重启apache。OK扩展完成

==========================================================================

今天用phpmyadmin做数据库管理时,偶然发现偶的phpmyadmin竟然没看到权限一栏,平常都没出过此类现象,这个难道与数据库版本有关系?以前用的数据库版本是mysql 5.0的,这次是mysql5.1的,这个可能有影响吧!想想应该改phpmyadmin的配置文件,以下是解决方法:
登陆phpmyadmin后,会在底部显示“链接表的附加功能尚未激活。要查出原因,请点击此处。”

第一步:使用Mysql管理员帐号通过phpmyadmin登陆,然后点击“导进”,然后点击“浏览”按钮,找到phpmyadmin文件夹下的scripts文件夹里的一个名为create_tables.sql的文件。把它导进就OK了。

第二步:打开phpmyadmin文件夹下的config.inc.php,去掉以下代码前面的注释(// )
$cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';
$cfg['Servers'][$i]['bookmarktable'] = 'pma_bookmark';
$cfg['Servers'][$i]['relation'] = 'pma_relation';
$cfg['Servers'][$i]['table_info'] = 'pma_table_info';
$cfg['Servers'][$i]['table_coords'] = 'pma_table_coords';
$cfg['Servers'][$i]['pdf_pages'] = 'pma_pdf_pages';
$cfg['Servers'][$i]['column_info'] = 'pma_column_info';
$cfg['Servers'][$i]['history'] = 'pma_history';
$cfg['Servers'][$i]['tracking'] = 'pma_tracking';
$cfg['Servers'][$i]['designer_coords'] = 'pma_designer_coords';

第三步:注销phpmyadmin之后并重新登录

相关软件包打包下载 http://pan.baidu.com/share/link?shareid=354480&uk=2516956362