Linux+Apache+Mysql+Perl/PHP/Python一组常用来搭建动态网站或者服务器的开源软件,本身都是各自独立的程序,但是因为常被放在一起使用,拥有了越来越高的兼容度,共同组成了一个强大的Web应用程序平台。我采用 Linux+Apache+Mysql+PHP来进行编译安装。
以下是编译安装的过程:
首先下载此次过程中需要的部分rpm包 http://down.51cto.com/data/371324
一、编译安装apache
1、解决依赖关系
要用到的rpm包
apr-1.4.6-1.i386.rpm
apr-devel-1.4.6-1.i386.rpm
apr-util-1.4.1-1.i386.rpm
apr-util-devel-1.4.1-1.i386.rpm
下载完成之后,使用
- #rpm -Uvh ***.rpm
进行升级
httpd-2.4.1编译过程也要依赖于pcre-devel软件包,通过安装光盘安装。
2、编译安装httpd-2.4.1
- # tar xf httpd-2.4.1.tar.bz2
- # cd httpd-2.4.1
- # ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib
# make && make install
3、修改httpd的主配置文件,设置其Pid文件的路径
编辑/etc/httpd/httpd.conf,添加如下行即可:
PidFile "/var/run/httpd.pid"
4、提供SysV服务脚本/etc/rc.d/init.d/httpd,内容如下:
- #!/bin/bash
- #
- # httpd Startup script for the Apache HTTP Server
- #
- # chkconfig: - 85 15
- # description: Apache is a World Wide Web server. It is used to serve \
- # HTML files and CGI.
- # processname: httpd
- # config: /etc/httpd/conf/httpd.conf
- # config: /etc/sysconfig/httpd
- # pidfile: /var/run/httpd.pid
- # Source function library.
- . /etc/rc.d/init.d/functions
- if [ -f /etc/sysconfig/httpd ]; then
- . /etc/sysconfig/httpd
- fi
- # Start httpd in the C locale by default.
- HTTPD_LANG=${HTTPD_LANG-"C"}
- # This will prevent initlog from swallowing up a pass-phrase prompt if
- # mod_ssl needs a pass-phrase from the user.
- INITLOG_ARGS=""
- # Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
- # with the thread-based "worker" MPM; BE WARNED that some modules may not
- # work correctly with a thread-based MPM; notably PHP will refuse to start.
- # Path to the apachectl script, server binary, and short-form for messages.
- apachectl=/usr/local/apache/bin/apachectl
- httpd=${HTTPD-/usr/local/apache/bin/httpd}
- prog=httpd
- pidfile=${PIDFILE-/var/run/httpd.pid}
- lockfile=${LOCKFILE-/var/lock/subsys/httpd}
- RETVAL=0
- start() {
- echo -n $"Starting $prog: "
- LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
- RETVAL=$?
- echo
- [ $RETVAL = 0 ] && touch ${lockfile}
- return $RETVAL
- }
- stop() {
- echo -n $"Stopping $prog: "
- killproc -p ${pidfile} -d 10 $httpd
- RETVAL=$?
- echo
- [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
- }
- reload() {
- echo -n $"Reloading $prog: "
- if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
- RETVAL=$?
- echo $"not reloading due to configuration syntax error"
- failure $"not reloading $httpd due to configuration syntax error"
- else
- killproc -p ${pidfile} $httpd -HUP
- RETVAL=$?
- fi
- echo
- }
- # See how we were called.
- case "$1" in
- start)
- start
- ;;
- stop)
- stop
- ;;
- status)
- status -p ${pidfile} $httpd
- RETVAL=$?
- ;;
- restart)
- stop
- start
- ;;
- condrestart)
- if [ -f ${pidfile} ] ; then
- stop
- start
- fi
- ;;
- reload)
- reload
- ;;
- graceful|help|configtest|fullstatus)
- $apachectl $@
- RETVAL=$?
- ;;
- *)
- echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
- exit 1
- esac
- exit $RETVAL
而后为此脚本赋予执行权限:
# chmod +x /etc/rc.d/init.d/httpd
加入服务列表:
# chkconfig --add httpd
接下来就可以启动服务进行测试。
二、安装mysql-5.5.19
1、准备数据存放的文件系统
新建一个逻辑卷:
- #fdisk /dev/sda
假设我们的物理卷组为sda5
创建物理卷:
- #pvcreate /dev/sda5
创建卷组:
- #vgcreate myvg /dev/sda5
创建逻辑卷:
- #lvcreate -L 4G -n mydata myvg
格式化:
- #mkfs -t ext3 /dev/myvg/mydata
并将其挂载至/mydata/data 目录,此目录作为mysql数据的存放路径
- #mkdir -pv /mydata/data
- #mount /dev/sda5 /mydata/data
实现开机启动
vim /etc/fstab添加如下行:
- /dev/myvg/mydata /mydata ext3 defaults 0 0
2、新建用户以安全方式运行进程:
- # groupadd -r mysql
- # useradd -g mysql -r -s /sbin/nologin -M -d /mydata/data mysql
- # chown -R mysql:mysql /mydata/data
3、安装并初始化mysql-5.5.19
- # tar xf mysql-5.5.19-linux2.6-i686.tar.gz -C /usr/local
- # cd /usr/local/
- # ln -sv mysql-5.5.19-linux2.6-i686 mysql
- # cd mysql
- # chown -R mysql:mysql .
- # scripts/mysql_install_db --user=mysql --datadir=/mydata/data
- # chown -R root .
4、为mysql提供主配置文件:
- # cd /usr/local/mysql
- # cp support-files/my-large.cnf /etc/my.cnf
并修改此文件中thread_concurrency的值为你的CPU个数乘以2,比如这里使用如下行:
- thread_concurrency = 2
添加如下行来指定mysql数据文件的存放位置:
- datadir = /mydata/data
5、为mysql提供sysv服务脚本:
- # cd /usr/local/mysql
- # cp support-files/mysql.server /etc/rc.d/init.d/mysqld
添加至服务列表:
- # chkconfig --add mysqld
- # chkconfig mysqld on
启动服务测试使用了。
为了使用mysql的安装符合系统使用规范,并将其开发组件导出给系统使用,这里还需要进行如下步骤:
6、输出mysql的man手册至man命令的查找路径:
编辑/etc/man.config,添加如下行即可:
MANPATH /usr/local/mysql/man
7、输出mysql的头文件至系统头文件路径/usr/include:
这可以通过简单的创建链接实现:
- # ln -sv /usr/local/mysql/include /usr/include/mysql
8、输出mysql的库文件给系统库查找路径:
- # echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
而后让系统重新载入系统库:
- # ldconfig
9、定义环境变量,定义过后直接使用命令#mysql进入数据库
编辑 #vim /etc/profile 添加如下行
- PATH=$PATH:/usr/local/mysql/bin
重读配置文件:
- #source /etc/profile
三、编译安装php-5.3.10
1、解决依赖关系:
请配置好yum源(可以是本地系统光盘)后执行如下命令:
- # yum -y groupinstall "X Software Development"
安装下列rpm包:
libmcrypt-2.5.7-5.el5.i386.rpm
libmcrypt-devel-2.5.7-5.el5.i386.rpm
2、编译安装php-5.3.10
- # tar xf php-5.3.10.tar.bz2
- # cd php-5.3.10
- # ./configure --prefix=/usr/local/php --with-mcrypt --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --with-apxs2=/usr/local/apache/bin/apxs
**--with-mcrypt选项以让php支持mycrpt扩展。**
- # make
- # make test
- # make intall
为php提供配置文件:
- # cp php.ini-production /usr/local/php/lib/php.ini
3、 编辑apache配置文件httpd.conf,以apache支持php
- # vim /etc/httpd/httpd.conf
1、添加如下二行
- AddType application/x-httpd-php .php
- AddType application/x-httpd-php-source .phps
2、定位至DirectoryIndex index.html
修改为:
- DirectoryIndex index.php index.html
重新启动httpd服务,或让其重新载入配置文件即可测试php是否已经可以正常使用。
转载于:https://blog.51cto.com/liuyabing/831907