源码搭建LAMP环境的优势:
1、能够使用更新的软件版本
2、大大提高软件的性能
3、自定义参数,根据自己的需求进行自定义设置
实验环境:
Red Hat Enterprise Linux 5.4 httpd-2.4.4 mysql-5.6.10 php-5.4.13
将实验用到的源码包上传到rhel-5.4根目录下
[root@localhost~]# ll
total 57844
drwxr-xr-x 2 rootroot 4096 Jul 10 17:24 Desktop
-rw-r--r-- 1 rootroot 42184 Aug 30 16:16 INSTALL-SOURCE
-rw-r--r-- 1 rootroot 982243 Aug 30 16:14apr-1.4.6.tar.gz
-rw-r--r-- 1 rootroot 829779 Aug 30 16:14apr-util-1.5.1.tar.gz
-rw-r--r-- 1 rootroot 5768373 Aug 30 16:375pxake-2.8.10.2.tar.gz
-rw-r--r-- 1 rootroot 4780289 Aug 30 16:14httpd-2.4.4.tar.bz2
-rw-r--r-- 1 rootroot 35174149 Aug 30 16:15 mysql-5.6.10.tar.gz
-rw-r--r-- 1 rootroot 11545777 Aug 30 16:15 php-5.4.13.tar.bz2
源码包安装顺序
Httpdàmysqlàphp
挂载光盘并修改yum安装的配置文件
[root@localhost~]# mkdir /mnt/cdrom #创建光盘挂载点
[root@localhost~]# mount /dev/cdrom /mnt/cdrom #挂载光盘到光盘挂载点
mount: blockdevice /dev/cdrom is write-protected, mounting read-only
[root@localhost~]# vim /etc/yum.repos.d/rhel-debuginfo.repo #编辑yum的配置文件
[rhel-Server]
name=Red HatEnterprise Linux Serverbaseurl=file:///mnt/cdrom/Server
enabled=1
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release
检验源码安装编译开发环境
[root@localhost~]# yum grouplist |less
DevelopmentLibraries
Development Tools
Legacy SoftwareDevelopment
X SoftwareDevelopment
系统安装这四个编译开发环境能够应对所有的源码安装
Apache的源码安装:
Httpd安装需要有apr-1.4.6(可移植性库文件)以及apr-util-1.5.1(工具)的支持。
我们在安装httpd服务的软件包之前,首先需要把apr-1.4.6和apr-util-1.5.1安装,否则安装httpd会出现错误。
[root@localhost~]# tar -zxvf apr-1.4.6.tar.gz -C /usr/local/src/
[root@localhost~]# tar -zxvf apr-util-1.5.1.tar.gz -C /usr/local/src/
[root@localhostsrc]# cd /usr/local/src/apr-1.4.6/
[[email protected]]# less README #通过查看帮助文件了解安装步骤
Configuring andBuilding APR on Unix
====================================
Simply;
./configure --prefix=/desired/path/of/apr
make
make test
make install
[[email protected]]# ./configure --prefix=/usr/local/apr #指明配置文件的存放目录
[[email protected]]# make &&make install #执行编译后执行安装
[[email protected]]# cd /usr/local/apr/ #切换到apr安装目录查看安装产生的文件及目录
[root@localhostapr]# ll
total 16
drwxr-xr-x 2 rootroot 4096 Sep 6 19:00 bin
drwxr-xr-x 2 rootroot 4096 Sep 6 19:00 build-1
drwxr-xr-x 3 rootroot 4096 Sep 6 19:00 include
drwxr-xr-x 3 rootroot 4096 Sep 6 19:00 lib
[root@localhost/]# vim /etc/ld.so.conf.d/apr.conf #创建一个配置文件添加apr安装产生的库文件的路径为了系统其他软件能够调用这些库文件
[root@localhost/]# ll /etc/ld.so.cache #查看系统库的缓存
-rw-r--r-- 1 rootroot 56723 Jul 11 01:18 /etc/ld.so.cache
[root@localhost/]# ldconfig #刷新系统库的缓存
[root@localhost/]# ll /etc/ld.so.cache #再次查看系统库的缓
-rw-r--r-- 1 rootroot 56885 Sep 6 19:06 /etc/ld.so.cache 存,发现缓存变大了
[root@localhost/]# ldconfig -pv |grep apr #查看有关apr的库文件
libgstdataprotocol-0.10.so.0 (libc6)=> /usr/lib/libgstdataprotocol-0.10.so.0
libaprutil-1.so.0 (libc6) =>/usr/lib/libaprutil-1.so.0
libapr-1.so.0 (libc6) =>/usr/local/apr/lib/libapr-1.so.0
libapr-1.so.0 (libc6) =>/usr/lib/libapr-1.so.0
libapr-1.so (libc6) =>/usr/local/apr/lib/libapr-1.so
[root@localhost/]# ln -s /usr/local/apr/include /usr/include/apr #给安装产生的头文件添加链接到系统能够调用的库文件目录
[[email protected]]#./configure--prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config #配置apr-util并设置安装路径以及apr的可执行文件的路径
[[email protected]]# make && make install #编译并安装
[[email protected]]# cd /usr/local/apr-util/ #切换到apr-util安装目录查看产生的文件及目录
[root@localhostapr-util]# ll
total 12
drwxr-xr-x 2 rootroot 4096 Sep 6 20:04 bin
drwxr-xr-x 3 rootroot 4096 Sep 6 20:04 include
drwxr-xr-x 4 rootroot 4096 Sep 6 20:04 lib
同样需要编写配置文件将安装产生的库文件加载到系统,为了系统其他软件能够调用这些库文件,通过链接的方式将产生的头文件链接到系统能够调用的库文件目录
[root@localhostapr-util]# vim /etc/ld.so.conf.d/apr-util.conf #编写加载库文件的配置文件(写入apr-util库文件所在路径)并命名为apr-util.conf
[root@localhostapr-util]# ldconfig #刷新系统库文件缓存
[root@localhostapr-util]# ll /etc/ld.so.cache #查看系统库文件缓存文件
-rw-r--r-- 1 rootroot 57073 Sep 6 20:12 /etc/ld.so.cache
[root@localhostapr-util]# ldconfig -pv |grep apr-util #查看库文文件是否已
libaprutil-1.so.0 (libc6) =>/usr/local/apr-util/lib/libaprutil-1.so.0 加载到系统中
libaprutil-1.so (libc6) =>/usr/local/apr-util/lib/libaprutil-1.so
[root@localhostapr-util]# ln -s /usr/local/apr-util /usr/include/apr-util#产生的头文件链接到系统能够调用的路径
为了能够系统在任何位置能够调用安装目录bin下的可执行文件,我们可以将bin目录的路径添加到系统中的PATH环境变量中就可以实现任意调用。
[root@localhostapr-util]# ll bin/
total 8
-rwxr-xr-x 1 rootroot 6453 Sep 6 20:04 apu-1-config
[root@localhostapr-util]# vim /etc/profile #系统变量配置文件中追加可执行文件(apr和apr-util)的bin目录路径
44PATH=$PATH:/usr/local/apr-util/bin:/usr/local/apr/bin #44行追加的内容
45 export PATHUSER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC
Apache依赖的共享库以及工具包已经安装好了,接下来安装apache。
[root@localhost~]# tar -jxvf httpd-2.4.4.tar.bz2 -C /usr/local/src/ #源码拆解
[root@localhost httpd-2.4.4]#less INSTALL #查看源码安装的说明文件INSTALL
For completeinstallation documentation, see [ht]docs/manual/install.html or
http://httpd.apache.org/docs/2.4/install.html #指出安装的主要步骤
$ ./configure --prefix=PREFIX
$ make
$ make install
$ PREFIX/bin/apachectl start
[root@localhost httpd-2.4.4]#./configure �Chelp #查看帮助可以添加自定义的参数
[[email protected]]# ./configure \
>--prefix=/usr/local/apache \ #自定义安装路径
>--sysconfdir=/etc/httpd \ #自定义配置文件存放路径
> --enable-so \ #启用模块化
>--enable-mods-shared=most \ #启用大部分共享模块
> --enable-ssl\ #启用ssl加密访问
>--enable-mpms-shared=all \ #启用所有的mpms
>--enable-rewrite \ #启用地址重写功能
>--with-apr=/usr/local/apr/bin/apr-1-config \ #指明apr可执行文件路径
>--with-apr-util=/usr/local/apr-util/bin/apu-1-config \ #指明apr-util的执行文件路径
> --with-z \ #使用特殊的zlib库
>--with-pcre #使用扩展的PCRE库,系统首先已安装pcre和pcre-devel两个软件包,否则会报错。
[[email protected]]# make && make install #编译并安装
[root@localhostapache]# ll
total 52
drwxr-xr-x 2 root root 4096 Sep 7 09:26 bin
drwxr-xr-x 2 root root 4096 Sep 7 09:27 build
drwxr-xr-x 2 root root 4096 Sep 7 09:26 cgi-bin
drwxr-xr-x 3 root root 4096 Sep 7 09:26 error
drwxr-xr-x 2 root root 4096 Sep 6 20:38 htdocs
drwxr-xr-x 3 root root 4096 Sep 7 09:26 icons
drwxr-xr-x 2 root root 4096 Sep 7 09:27 include
drwxr-xr-x 2 root root 4096 Sep 7 09:26 logs
drwxr-xr-x 4 root root 4096 Sep 7 09:27 man
drwxr-xr-x 14 rootroot 12288 Feb 19 2013 manual
drwxr-xr-x 2 root root 4096 Sep 7 09:26 modules
将产生的bin目录下的系统服务文件路径添加到系统环境变量文件中,红色字体是44行追加内容
44PATH=$PATH:/usr/local/apr-util/bin:/usr/local/apr/bin:/usr/local/apache/bin
45 export PATHUSER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC
安装产生的头文件使用链接的方式添加到系统能够调用的头文件目录
[root@localhostapache]# ln -s /usr/local/apache/include/ /usr/include/apache
[root@localhostapache]# vim /etc/man.config #编辑系统man手册的配置文件,添加httpd产生的man手册所在目录的路径,在系统下能够查看有关httpd的man手册
43 MANPATH/usr/man
44 MANPATH/usr/share/man
45 MANPATH/usr/local/man
46 MANPATH/usr/local/share/man
47 MANPATH/usr/X11R6/man
48 MANPATH/usr/local/apache/man #47行下边追加apache的man目录的路径
[root@localhostapache]# cd /etc/init.d/ #系统服务控制脚本存放目录
[[email protected]]# vim httpd #编写httpd的服务控制脚本
#!/bin/sh
#set -x
HTTPD='/usr/local/apache/bin/httpd' #变量httpd执行文件的路径
CONFFILE='/etc/httpd/httpd.conf' #变量conffile配置文件的路径
#description: httpserver #chkconfig说明文字,可以
#chkconfig: 234588 60 #使用chkconfig控制开机自启动
start(){
[ -f /var/lock/subsys/httpd ]&&echo "apache is started" && exit
echo -n "starting apache......"
sleep 1
$HTTPD -f $CONFFILE && RETVAL=0 ||RETVAL=1
[ $RETVAL -eq 0 ]&& touch/var/lock/subsys/httpd && echo "ok" || echo"fail"
}
stop(){
[ ! -f /var/lock/subsys/httpd ] && echo "httpd is stoped..."&& exit
echo -n "stoping httpd........"
sleep 1
/bin/rm -rf /var/lock/subsys/httpd
$HTTPD -k stop && RETVAL=0||RETVAL=1
[ $RETVAL -eq 0 ] && rm -rf/var/lock/subsys/httpd && echo "ok" || echo "fail"
}
case $1 in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo "start|stop|restart"
;;
esac
[[email protected]]# chmod a+x httpd #添加可执行权限
[[email protected]]# service httpd start #打开httpd服务
startingapache......ok
[[email protected]]# netstat -tupln |grep httpd #查看有关httpd的端口
tcp 0 0:::80 :::* LISTEN 21780/httpd
能够看到下面这个网页页面说明我们的apache搭建已经ok。
[[email protected]]# service httpd stop #停止httpd服务
stopinghttpd........ok
[[email protected]]# netstat -tupln |grep httpd #查看有关httpd服务的端口
Httpd服务一旦停止,我们就无法访问我们的站点网页。
[[email protected]]# chkconfig --add httpd #添加chkconfig管理httpd
[[email protected]]# chkconfig --list |grep httpd #httpd服务在运行级别下的默认状态
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[[email protected]]# ll /etc/rc3.d/ |grep httpd #查看httpd在运行级别3下的状态信息
lrwxrwxrwx 1 rootroot 15 Sep 7 10:46 S88httpd ->../init.d/httpd
mysql的二进制安装:
我们的httpd服务已经搭建好了,接下来我们就需要安装mysql,因为安装mysql的源码包太浪费时间,少则二十分钟,根据PC机硬件的不同,具体时间不确定。为了节约时间,这里就是用绿色免安装的二进制mysql代替。
[root@localhost~]# tar -zxcf mysql-5.5.15-linux2.6-i686.tar.gz -C /usr/local/ #拆解mysql到用户本地目录
[root@localhost~]# cd /usr/local #切换到软件包拆解目录并查看目录及文件
[root@localhostlocal]# ll
total 88
drwxr-xr-x 13 rootroot 4096 Sep 7 09:39 apache
drwxr-xr-x 6 root root 4096 Sep 6 19:00 apr
drwxr-xr-x 5 root root 4096 Sep 6 20:04 apr-util
drwxr-xr-x 2 root root 4096 Aug 8 2008bin
drwxr-xr-x 2 root root 4096 Aug 8 2008etc
drwxr-xr-x 2 root root 4096 Aug 8 2008games
drwxr-xr-x 2 root root 4096 Aug 8 2008include
drwxr-xr-x 2 root root 4096 Aug 8 2008lib
drwxr-xr-x 2 root root 4096 Aug 8 2008libexec
drwxr-xr-x 13 rootroot 4096 Sep 7 11:13mysql-5.5.15-linux2.6-i686
drwxr-xr-x 2 root root 4096 Aug 8 2008sbin
drwxr-xr-x 4 root root 4096 Jul 11 01:02 share
drwxr-xr-x 5 root root 4096 Sep 6 20:38 src
[root@localhostlocal]# ln -s mysql-5.5.15-linux2.6-i686 mysql #为访问目录的方便,创建目录的链接
[root@localhostlocal]# cd mysql #切换到mysql目录
[root@localhostmysql]# ll
total 76
-rw-r--r-- 1 7161 wheel 17987 Jul 14 2011 COPYING
-rw-r--r-- 1 7161 wheel 7604 Jul 14 2011 INSTALL-BINARY
-rw-r--r-- 1 7161 wheel 2552 Jul 14 2011 README
drwxr-xr-x 2 root root 4096 Sep 7 11:13 bin
drwxr-xr-x 4 root root 4096 Sep 7 11:13 data
drwxr-xr-x 2 root root 4096 Sep 7 11:13 docs
drwxr-xr-x 3 root root 4096 Sep 7 11:13 include
drwxr-xr-x 3 root root 4096 Sep 7 11:13 lib
drwxr-xr-x 4 root root 4096 Sep 7 11:13 man
drwxr-xr-x 10 rootroot 4096 Sep 7 11:13 mysql-test
drwxr-xr-x 2 root root 4096 Sep 7 11:13 scripts
drwxr-xr-x 27 rootroot 4096 Sep 7 11:13 share
drwxr-xr-x 4 root root 4096 Sep 7 11:13 sql-bench
drwxr-xr-x 2 root root 4096 Sep 7 11:13 support-files
[root@localhostmysql]# vim INSTALL-BINARY #查看安装说明文件,可以根据这些步骤顺利的安装mysql软件包。
76 To install and use a MySQL binarydistribution, the basic command
77 sequence looks like this:
78 shell>groupadd mysql
79 shell>useradd -r -g mysql mysql
80 shell> cd/usr/local
81 shell> tarzxvf /path/to/mysql-VERSION-OS.tar.gz
82 shell> ln -sfull-path-to-mysql-VERSION-OS mysql
83 shell> cdmysql
84 shell> chown-R mysql .
85 shell> chgrp-R mysql .
86 shell>scripts/mysql_install_db --user=mysql
87 shell> chown-R root .
88 shell> chown-R mysql data
89 # Next commandis optional
90 shell> cpsupport-files/my-medium.cnf /etc/my.cnf
91 shell>bin/mysqld_safe --user=mysql &
92 # Next commandis optional
93 shell> cpsupport-files/mysql.server /etc/init.d/mysql.server
[root@localhostmysql]# groupadd -r mysql #创建mysql组
[root@localhostmysql]# useradd -r -g mysql mysql -s /sbin/nologin #在mysql组创建mysql用户并指定shell的存放路径
[root@localhostmysql]# chown -R mysql:mysql . #目录下所有文件改变所属用户以及所属组为mysql,为了mysql数据库初始化
[root@localhostmysql]# ll
total 76
-rw-r--r-- 1 mysql mysql 17987 Jul 14 2011 COPYING
-rw-r--r-- 1 mysql mysql 7604 Jul 14 2011 INSTALL-BINARY
-rw-r--r-- 1 mysql mysql 2552 Jul 14 2011 README
drwxr-xr-x 2 mysql mysql 4096 Sep 7 11:13 bin
drwxr-xr-x 4 mysql mysql 4096 Sep 7 11:13 data
drwxr-xr-x 2 mysql mysql 4096 Sep 7 11:13 docs
drwxr-xr-x 3 mysql mysql 4096 Sep 7 11:13 include
drwxr-xr-x 3 mysql mysql 4096 Sep 7 11:13 lib
drwxr-xr-x 4 mysql mysql 4096 Sep 7 11:13 man
drwxr-xr-x 10mysql mysql 4096 Sep 7 11:13 mysql-test
drwxr-xr-x 2 mysql mysql 4096 Sep 7 11:13 scripts
drwxr-xr-x 27mysql mysql 4096 Sep 7 11:13 share
drwxr-xr-x 4 mysql mysql 4096 Sep 7 11:13 sql-bench
drwxr-xr-x 2 mysql mysql 4096 Sep 7 11:13 support-files
[root@localhostmysql]# scripts/mysql_install_db --user=mysql #初始化数据库
Installing MySQLsystem tables...
OK
Filling helptables...
OK
To start mysqld atboot time you have to copy
support-files/mysql.serverto the right place for your system
PLEASE REMEMBER TOSET A PASSWORD FOR THE MySQL root USER !
To do so, startthe server, then issue the following commands:
./bin/mysqladmin-u root password 'new-password'
./bin/mysqladmin-u root -h localhost.localdomain password 'new-password'
Alternatively youcan run:
./bin/mysql_secure_installation
which will alsogive you the option of removing the test
databases andanonymous user created by default. Thisis
stronglyrecommended for production servers.
See the manual formore instructions.
You can start theMySQL daemon with:
cd . ;./bin/mysqld_safe &
You can test theMySQL daemon with mysql-test-run.pl
cd ./mysql-test ;perl mysql-test-run.pl
Please report anyproblems with the ./bin/mysqlbug script!
[root@localhostmysql]# chown -R root . #将目录下所有文件所属用户改为root
[root@localhostmysql]# chown -R mysql data/ #因为data目录的特殊性,需要使用mysql用户写入数据,改变所属用户为mysql
[root@localhostmysql]# ll #改变所属用户后的目录信息
total 76
-rw-r--r-- 1 root mysql 17987 Jul 14 2011 COPYING
-rw-r--r-- 1 root mysql 7604 Jul 14 2011 INSTALL-BINARY
-rw-r--r-- 1 root mysql 2552 Jul 14 2011 README
drwxr-xr-x 2 root mysql 4096 Sep 7 11:13 bin
drwxr-xr-x 5 mysql mysql 4096 Sep 7 11:28 data
drwxr-xr-x 2 root mysql 4096 Sep 7 11:13 docs
drwxr-xr-x 3 root mysql 4096 Sep 7 11:13 include
drwxr-xr-x 3 root mysql 4096 Sep 7 11:13 lib
drwxr-xr-x 4 root mysql 4096 Sep 7 11:13 man
drwxr-xr-x 10root mysql 4096 Sep 7 11:13 mysql-test
drwxr-xr-x 2 root mysql 4096 Sep 7 11:13 scripts
drwxr-xr-x 27root mysql 4096 Sep 7 11:13 share
drwxr-xr-x 4 root mysql 4096 Sep 7 11:13 sql-bench
drwxr-xr-x 2 root mysql 4096 Sep 7 11:13 support-files
[root@localhostmysql]# cp support-files/my-medium.cnf /etc/my.cnf #拷贝样例配置文件到系统etc目录下并命名为my.cnf
[root@localhostmysql]# cp support-files/mysql.server /etc/init.d/mysqld #拷贝样例控制脚本到系统服务目录并命名为mysqld
root@localhostmysql]# ll /etc/init.d/mysqld #查看mysql的控制脚本的权限
-rwxr-xr-x 1 rootroot 10650 Sep 7 11:30/etc/init.d/mysqld
[root@localhostmysql]# service mysqld start #启动mysqld服务
StartingMySQL... [ OK ]
[root@localhostmysql]# netstat -tupln |grep mysqld #查看到mysqld的3306端口打开
tcp 0 0 :::3306 :::* LISTEN 22512/mysqld
[root@localhostmysql]# service mysqld stop #停止mysqld服务
Shutting downMySQL. [ OK ]
[root@localhostmysql]# netstat -tupln |grep mysqld #再次查看mysqld的服务端口
[root@localhostmysql]# service mysqld restart #重启mysqld服务
Shutting downMySQL. [ OK ]
StartingMySQL.. [ OK ]
[root@localhostmysql]# cd bin/
[root@localhostbin]# ls #可以看到很多的执行文件
innochecksum mysql_secure_installation mysqld_multi
msql2mysql mysql_setpermission mysqld_safe
my_print_defaults mysql_tzinfo_to_sql mysqldump
myisam_ftdump mysql_upgrade mysqldumpslow
myisamchk mysql_waitpid mysqlhotcopy
myisamlog mysql_zap mysqlimport
myisampack mysqlaccess mysqlshow
mysql mysqlaccess.conf mysqlslap
mysql_client_test mysqladmin mysqltest
mysql_client_test_embedded mysqlbinlog mysqltest_embedded
mysql_config mysqlbug perror
mysql_convert_table_format mysqlcheck replace
mysql_find_rows mysqld resolve_stack_dump
mysql_fix_extensions mysqld-debug resolveip
[root@localhostmysql]# vim /etc/profile #为了能够在任意地方使用这些执行文件,我们需要把bin目录的路径添加到系统变量文件中
44PATH=$PATH:/usr/local/apr-util/bin:/usr/local/apr/bin:/usr/local/apache/bin:/usr/local/mysql/bin #红色字体为44行追加内容
45 export PATHUSER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC
[root@localhostbin]# . /etc/profile #可以选择重启系统或者使用此命令刷新系统环境变量
[root@localhostbin]# echo $PATH #输出系统环境变量
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/apr-util/bin:/usr/local/apr/bin:/usr/local/apache/bin:/usr/local/mysql/bin:/root/bin:/usr/local/apr-util/bin:/usr/local/apr/bin:/usr/local/apache/bin:/usr/local/mysql/bin
[root@localhostmysql]# ls lib/
libmysqlclient.a libmysqlclient_r.so libmysqlservices.a
libmysqlclient.so libmysqlclient_r.so.18 libtcmalloc_minimal.so
libmysqlclient.so.18 libmysqlclient_r.so.18.0.0 libtcmalloc_minimal.so.0
libmysqlclient.so.18.0.0 libmysqld-debug.a plugin
libmysqlclient_r.a libmysqld.a
[root@localhostmysql]# vim /etc/ld.so.conf.d/mysql.conf #在系统下编辑一个库文件配置文件
/usr/local/mysql/lib #配置文件内容为库文件路径
[root@localhost mysql]# ldconfig #刷新系统库文件缓存
[root@localhost mysql]# ldconfig -pv |grep mysql #检查mysql库文件是否加载到系统库
libtcmalloc_minimal.so.0 (libc6) =>/usr/local/mysql/lib/libtcmalloc_minimal.so.0
libmysqlclient.so.18 (libc6) =>/usr/local/mysql/lib/libmysqlclient.so.18
libmysqlclient.so (libc6) =>/usr/local/mysql/lib/libmysqlclient.so
[root@localhost mysql]# ln -s /usr/local/mysql/include//usr/include/mysql #链接头文件到系统能够识别的头文件目录下
[root@localhost mysql]# mysql #进入mysql数据库
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.15-log MySQL Community Server (GPL)
Copyright (c) 2000, 2010, Oracle and/or its affiliates.All rights reserved.
Oracle is a registered trademark of Oracle Corporationand/or its
affiliates. Other names may be trademarks of theirrespective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear thecurrent input statement.
mysql> show database; #查看mysql默认数据库
ERROR 1064 (42000): You have an error in your SQL syntax;check the manual that corresponds to your MySQL server version for the rightsyntax to use near 'database' at line 1
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
mysql> q
-> \q
Bye
[root@localhost mysql]# mysqladmin -u root -p password'123' #为了数据库的安全性,为mysql数据库账户添加密码
Enter password:
[root@localhost support-files]# vim /etc/init.d/mysqld #查看mysqld的控制脚本,可以看到chkconfig的声明文件已存在
# chkconfig: 2345 64 36
# description: A very fast and reliable SQL databaseengine.
[root@localhost support-files]# chkconfig --add mysqld #为mysqld添加到系统默认级别开启的chkconfig
[root@localhost support-files]# chkconfig --list |grepmysqld #mysqld在2、3、4、5运行级别都是默认开启的服务
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
php的源码安装:
[root@localhost ~]# tar -jxvf php-5.4.13.tar.bz2 -C /usr/local/src/ #拆解php源码包
[root@localhost ~]# cd /usr/local/src/php-5.4.13/ #切换到拆解的源码包目录
[root@localhost php-5.4.13]# vim INSTALL #通过查看目录下的安装说明文件,根据步骤安装php
368 Apache 2.x on Unix systems
370 This section contains notes and hints specific to Apache 2.x installs
371 of PHP onUnix systems.
396 1. Obtain the Apache HTTP server from the location listed above, and
397 unpackit:
398 gzip -d httpd-2_x_NN.tar.gz
399 tar -xf httpd-2_x_NN.tar
401 2. Likewise, obtain and unpack the PHP source:
402 gunzip php-NN.tar.gz
403 tar -xf php-NN.tar
405 3.Build and install Apache. Consult theApache install documentation
406 for moredetails on building Apache.
407 cd httpd-2_x_NN
408 ./configure --enable-so
409 make
410 make install
411
412 4. Now you have Apache 2.x.NN available under /usr/local/apache2,
413 configured with loadable module support and the standard MPM
414 prefork. To test the installation use your normal procedure for
415 startingthe Apache server, e.g.:
416 /usr/local/apache2/bin/apachectl start
418 and stopthe server to go on with the configuration for PHP:
419 /usr/local/apache2/bin/apachectl stop
420
421 5. Now, configure and build PHP. This is where youcustomize PHP with
422 various options, like which extensions will be enabled. Run
423 ./configure --help for a list of available options. In our example
424 we'll do asimple configure with Apache 2 and MySQL support.
425 If you built Apache from source, as described above,the below
426 example will match your path for apxs, but if youinstalled Apache
427 someother way, you'll need to adjust the path to apxs accordingly.
428 Note thatsome distros may rename apxs to apxs2.
429 cd ../php-NN
430 ./configure --with-apxs2=/usr/local/apache2/bin/apxs--with-mysql
431 make
432 make install
441 6. Setupyour php.ini
442 cp php.ini-development /usr/local/lib/php.ini
449 7.Edit your httpd.conf to load the PHPmodule. The path on the right
450 hand sideof the LoadModule statement must point to the path of the
451 PHP module on your system. The make install from above may have
452 already added this for you, but be sure tocheck.
453 LoadModule php5_module modules/libphp5.so
通过以上说明文件及步骤能够顺利的安装php。
[root@localhost php-5.4.13]# ./configure \
> --prefix=/usr/local/php \ #指定安装路径
> --sysconfdir=/etc/php \ #指定配置文件路径
> --with-apxs2=/usr/local/apache/bin/apxs \ #共享使用apache的模块工具
> --with-gd \ #图形的支持
> --with-jpeg-dir \ #jpeg图片支持
> --with-png-dir \ #png图片支持
> --with-zlib-dir \ #压缩文件的支持
> --enable-mbstring \ #字符串的支持
> --with-mysql=/usr/local/mysql \ #结合使用mysql数据库
> --with-mysqli=/usr/local/mysql/bin/mysql_config #php与mysql结合文件
[root@localhost php-5.4.13]# make && make install #执行编译并安装
[root@localhost php-5.4.13]# cd /usr/local/php #切换到php安装目录查看产生文件及目录
[root@localhost php]# ll
total 16
drwxr-xr-x 2 root root 4096 Sep 7 16:33 bin
drwxr-xr-x 3 root root 4096 Sep 7 16:33 include
drwxr-xr-x 3 root root 4096 Sep 7 16:32 lib
drwxr-xr-x 3 root root 4096 Sep 7 16:32 php
[root@localhost php]# bin/php �Cm #查看php支持的模块
[PHP Modules]
Core
ctype
date
dom
ereg
fileinfo
filter
gd
hash
iconv
json
libxml
mbstring
mysql
mysqli
pcre
PDO
pdo_sqlite
Phar
posix
Reflection
session
SimpleXML
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zlib
[Zend Modules]
[root@localhost php]# vim /etc/profile #php产生的执行文件目录bin添加到系统环境变量
44PATH=$PATH:/usr/local/apr-util/bin:/usr/local/apr/bin:/usr/local/apache/bin:/usr/local/mysql/bin:/usr/local/php/bin
45 export PATH USER LOGNAME MAIL HOSTNAME HISTSIZEINPUTRC
[root@localhost php]# . /etc/profile #刷新系统环境变量
[root@localhost php]# vim /etc/httpd/httpd.conf #查看httpd的配置文件
147 LoadModule php5_module modules/libphp5.so #在配置文件中已添加php的模块
[root@localhost ~]# vim /etc/httpd/httpd.conf #编辑httpd的配置文件
246 AddType application/x-httpd-php .php .html #添加对php网页的支持,在246行追加的内容
247 <IfModule dir_module>
248 DirectoryIndex index.php index.html #红色字体是追加的内容,能够处理类似index.php网页
249 </IfModule>
[root@localhost ~]# service httpd restart
stoping httpd........ok
starting apache......ok
测试环境:
做到这里,我们的源码搭建LAMP环境已经ok了,我们就做个测试。
[root@localhost htdocs]# mv index.html index.php
[root@localhost htdocs]# vim index.php #编辑httpd默认主页
<html><body><h1>Itworks!</h1></body></html>
<?php #追加php语法,测试
phpinfo(); apache与php的结合
?>
[root@localhosthtdocs]# vim index.php
<html><body><h1>Itworks!</h1></body></html>
<?php #追加内容测试php与mysql的结合
$link=mysql_connect('127.0.0.1','root','123'); #输入mysql数据库的地址及账号密码
if($link)
echo"ok"; #连接mysql数据库成功输出显示“ok”
else
echo"error"; #连接mysql数据库不成功输出显示“error”
?>
[root@localhost htdocs]# service mysqld stop #停止mysqld服务再次测试php与mysql的结合
Shutting down MySQL. [ OK ]
经过测试,apache、mysql与php三者能够很好的结合在一起,我们的LAMP环境已经搭建好了。
案例1:discuz论坛安装
[root@localhost ~]# ll
total 10328
drwxr-xr-x 2 root root 4096 Jul 10 17:24Desktop
-rw-r--r-- 1 root root 10485407 Aug 26 16:38 Discuz_X3.0_SC_GBK.zip
-rw------- 1 root root 1176 Jul 11 01:19anaconda-ks.cfg
-rw-r--r-- 1 root root 35236 Jul 11 01:19 install.log
-rw-r--r-- 1 root root 3995 Jul 11 01:17install.log.syslog
drwxr-xr-x 2 root root 4096 Aug 2 14:17 readme
drwxr-xr-x 12 root root 4096 Aug 2 14:17 upload
drwxr-xr-x 4 root root 4096 Aug 2 14:17 utility
[root@localhost ~]# mv ./upload//var/www/html/discus #将网站目录上传到站点默认主目录
[root@localhost html]# service httpdrestart #重启httpd服务再次查看安装页面
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[root@localhost discuz]# ls -a
. archiver data index.php portal.php template
.. config favicon.ico install robots.txt uc_client
admin.php connect.php forum.php member.php search.php uc_server
api cp.php group.php misc.php source userapp.php
api.php crossdomain.xml home.php plugin.php static
[root@localhostdiscuz]# chmod -R a+w config data uc_client uc_server #这些目录要求可写入,为了目录安全性,我们只需将安装环境需要可写入的目录设置为可写,由于我们是做实验,我们就简化这些操作,不再一一修改权限。
安装数据库需要我们添加相关信息,如果某些参数填写与实际不符,必将产生错误
安装数据库
安装完成
论坛主页
登录论坛后台(管理中心)
在论坛的后台可以任意添加修改板块以及其他众多设置
[root@localhost ~]# mysql -u root �Cp #使用root账户及密码登录mysql数据库
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 5.0.77 Source distribution
Type 'help;' or '\h' for help. Type '\c' toclear the buffer.
mysql> show databases; #查看安装discuz论坛产生的数据库
+--------------------+
| Database |
+--------------------+
| information_schema |
| discuz |
| mysql |
| test |
+--------------------+
4 rows in set (0.00 sec)
mysql> use discuz;
Reading table information for completion oftable and column names
You can turn off this feature to get aquicker startup with -A
Database changed
mysql> show tables; #论坛数据库建立了286张表
+-----------------------------------+
| Tables_in_discuz |
+-----------------------------------+
| pre_common_admincp_cmenu |
| pre_ucenter_notelist |
| pre_ucenter_pm_indexes |
| pre_ucenter_pm_lists |
| pre_ucenter_pm_members |
| pre_ucenter_pm_messages_0 |
| pre_ucenter_pm_messages_1 |
| pre_ucenter_pm_messages_2 |
| pre_ucenter_pm_messages_3 |
| pre_ucenter_pm_messages_4 |
| pre_ucenter_pm_messages_5 |
| pre_ucenter_pm_messages_6 |
| pre_ucenter_pm_messages_7 |
| pre_ucenter_pm_messages_8 |
| pre_ucenter_pm_messages_9 |
| pre_ucenter_protectedmembers |
| pre_ucenter_settings |
| pre_ucenter_sqlcache |
| pre_ucenter_tags |
| pre_ucenter_vars |
+-----------------------------------+
286 rows in set (0.01 sec)
由于字符界面的管理数据库有些麻烦,我们可以借助phpmyadmin在网页上管理我们的数据库。
[root@localhost ~]# mvphpMyAdmin-2.11.10.1-all-languages /var/www/html/phpmyadmin #将解压后的phpmyadmin目录移动到网站主目录
[root@localhost ~]# cd/var/www/html/phpmyadmin/
[root@localhost phpmyadmin]# cp -p config.sample.inc.php config.inc.php # 拷贝样例配置文件进行修改,解决遇到的无法登录数据库的错误登录页面出现“无法加载mcrypt扩展”,只需将mcrypt的软件包安装即可
[root@localhost ~]# ls
libmcrypt-2.5.7-5.el5.i386.rpm php-mcrypt-5.1.6-5.el5.i386.rpm Discuz_X3.0_SC_GBK.zip readme wordpress_v3.0.5-zh_CN.zip
[root@localhost ~]# rpm -ivh php-mcrypt-5.1.6-5.el5.i386.rpm
warning: php-mcrypt-5.1.6-5.el5.i386.rpm:Header V3 DSA signature: NOKEY, key ID 217521f6
error: Failed dependencies:
libmcrypt.so.4is needed by php-mcrypt-5.1.6-5.el5.i386
安装出现依赖关系,先安装依赖共享库的软件包
[root@localhost ~]# rpm -ivh libmcrypt-2.5.7-5.el5.i386.rpm
warning: libmcrypt-2.5.7-5.el5.i386.rpm: Header V3 DSAsignature: NOKEY, key ID 217521f6
Preparing... ###########################################[100%]
1:libmcrypt ########################################### [100%]
[root@localhost ~]# rpm -ivh php-mcrypt-5.1.6-5.el5.i386.rpm
warning: php-mcrypt-5.1.6-5.el5.i386.rpm:Header V3 DSA signature: NOKEY, key ID 217521f6
Preparing... ########################################### [100%]
1:php-mcrypt ########################################### [100%]
解决mcrypt扩展,我们可以登录我们的数据库进行数据库管理了
案例2:wordpress博客网站
[root@localhost ~]#unzip wordpress_v3.0.5-zh_CN.zip
[root@localhost wordpress-3.0.5-zh_CN]# mvwordpress/ /var/www/html/wordpress #解压网站文件并上传网站主目录
[root@localhost wordpress-3.0.5-zh_CN]# cd/var/www/html/wordpress/
[root@localhost wordpress]# ls -a
. wp-atom.php wp-includes wp-rss.php
.. wp-blog-header.php wp-links-opml.php wp-rss2.php
index.php wp-comments-post.php wp-load.php wp-settings.php
license.txt wp-commentsrss2.php wp-login.php wp-signup.php
readme.html wp-config-sample.php wp-mail.php wp-trackback.php
wp-activate.php wp-content wp-pass.php xmlrpc.php
wp-admin wp-cron.php wp-rdf.php
wp-app.php wp-feed.php wp-register.php
安装出现错误,需要实现配置wp-config.php配置文件,可以通过本页面建立,处于安全的考虑,最好是手动创建。
[root@localhost ~]# mysql -u root �Cp #使用root账户及密码登录数据库
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 87
Server version: 5.0.77 Source distribution
Type 'help;' or '\h' for help. Type '\c' toclear the buffer.
mysql> create database wordpress; #先创建我们博客网站的数据库
Query OK, 1 row affected (0.00 sec) 再拷贝样例配置文件进行修改
首次访问博客网站,进行网站配置
mysql> show databases; #查看博客网站的数据库
+--------------------+
| Database |
+--------------------+
| information_schema |
| discuz |
| mysql |
| test |
| wordpress |
+--------------------+
5 rows in set (0.00 sec)
使用管理员身份进入博客网站后台
查看我们的博客网站前台页面
这个页面看着有点没个性,那么我们可以在下载一些博客主题,将主题解压缩移动到博客网站的主题目录,再次访问即可实现更换主题的效果。
[root@localhost wordpress]# llwp-content/themes/ #查看网站的主题存放目录
total 8
-rw-r--r-- 1 root root 30 Feb 8 2011 index.php
drwxr-xr-x 4 root root 4096 Feb 8 2011twentyten