安装环境组包不然后面编译会出现少这个那个包
注意自己的Yum源 用163 或者aliyun或者本地都可以
yum groupinstall "Compatibility libraries" "Desktop Platform" "Desktop Platform Development" "Development tools"
解压apr和apr-utils这是httpd依赖的程序包 注意高版本的httpd必须依赖1.5版本以上的apr和apr-utils
[root@kcw1 ~]# tar xf apr-1.5.1 [root@kcw1 ~]# cd apr-1.5.1 [root@kcw1 apr-1.5.1]# ./configure --prefix=/usr/local/apr [root@kcw1 apr-1.5.1]# make && make install [root@kcw1 ~]# tar xf apr-util-1.5.3.tar.gz [root@kcw1 ~]# cd apr-util-1.5.3 [root@kcw1 apr-util-1.5.3]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr [root@kcw1 apr-util-1.5.3]# make && make install [root@kcw1 ~]# tar xf httpd-2.4.9.tar.bz2 [root@kcw1 ~]# cd httpd-2.4.9 [root@kcw1 httpd-2.4.9]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl \ > --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr \ > --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpms-shared=all --with-mpm=event 报错:configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/ [root@kcw1 httpd-2.4.9]# yum install pcre-devel 在执行又报错:checking whether to enable mod_ssl... configure: error: mod_ssl has been requested but can not be built due to prerequisite failures [root@kcw1 httpd-2.4.9]# yum install openssl-devel OK [root@kcw1 httpd-2.4.9]# make && make install
编辑/etc/httpd/httpd.conf添加
PidFile "/var/run/httpd.pid"
提供服务启动脚本
vim /etc/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/init.d/httpd
chkconfig --add httpd
chkcofig httpd on
启动测试/etc/init.d/httpd start
注意关掉防火墙!
http://IP
看到
表示OK了
2、安装mysql
[root@kcw1 ~]# tar xf mysql-5.5.37-linux2.6-x86_64.tar.gz -C /usr/local/ [root@kcw1 ~]# cd /usr/local/ [root@kcw1 local]# ln -sv mysql-5.5.37-linux2.6-x86_64 mysql `mysql' -> `mysql-5.5.37-linux2.6-x86_64'
[root@kcw1 local]# mkdir /mydata/data -pv
[root@kcw1 local]#groupadd mysql
[root@kcw1 local]# useradd -g mysql -r -s /sbin/nologin -M -d /mydata/data mysql
[root@kcw1 local]# chown mysql.mysql /mydata/data/ 初始化mysql [root@kcw1 local]#cd mysql root@kcw1 mysql]# chown -R mysql.mysql ./ [root@kcw1 mysql]# scripts/mysql_install_db --user=mysql --datadir=/mydata/data/ 报错./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory [root@kcw1 mysql]# yum install libaio Installing MySQL system tables... OK Filling help tables... OK 初始化成功! 复制mysql配置文件 [root@kcw1 mysql]# cp support-files/my-large.cnf /etc/my.cnf cp: overwrite `/etc/my.cnf'? y 并修改此文件中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 # chmod +x /etc/rc.d/init.d/mysqld [root@kcw1 mysql]# chkconfig --add mysqld [root@kcw1 mysql]# chkconfig mysql on [root@kcw1 mysql]# chkconfig mysqld on [root@kcw1 mysql]# /etc/init.d/mysqld start Starting MySQL... [ OK ] 输出mysql的头文件和库文件
输出mysql的man手册至man命令的查找路径: 编辑/etc/man.config,添加如下行即可 MANPATH /usr/local/mysql/man 输出mysql的头文件至系统头文件路径/usr/include: 这可以通过简单的创建链接实现: ln -sv /usr/local/mysql/include /usr/include/mysql 输出mysql的库文件给系统库查找路径: echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf 而后让系统重新载入系统库: ldconfig 修改PATH环境变量,让系统可以直接使用mysql的相关命令 vim /etc/profile.d/mysql.sh export PATH=$PATH:/usr/local/mysql/bin chmod o+x /etc/profile.d/mysql.sh 设置数据库密码 mysqladmin -u root password redhat
php安装
如果想让编译的php支持mcrypt扩展 yum install libmcrypt libmcrypt-devel php-mcrypt mhash 本地yum源可能没有这些包 我这里把yum指向aliyun的yun [root@kcw1 ~]# tar xf php-5.4.31.tar.bz2 [root@kcw1 ~]# cd php-5.4.31 [root@kcw1 php-5.4.31]# ./configure --prefix=/usr/local/php --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 --enable-sockets \ > --with-apxs2=/usr/local/apache/bin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 \ > --enable-maintainer-zts 报错:configure: error: Please reinstall the BZip2 distribution [root@kcw1 php-5.4.31]# yum install bzip2-devel 在执行OK make && make install 提供配置文件 [root@kcw1 php-5.4.31]# cp php.ini-production /etc/php.ini 编辑apache配置文件httpd.conf,以apache支持vim /etc/httpd/httpd.conf 添加如下二行 AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps 定位至DirectoryIndex index.html 修改为: DirectoryIndex index.php index.html 重启httpd看是否支持
vim /usr/local/apache/htdocs/index.php
<html><body><h1>It works!</h1></body></html> <?php phpinfo(); ?>
表示支持php了
看看时候能够连接数据库
<html><body><h1>It works!</h1></body></html> <?php $conn=mysql_connect('localhost','root','redhat'); 注意你的数据库账号密码 if($conn) echo "Scueess..."; else echo "Failure..."; phpinfo(); ?> ~
如果连接成功显示Scueess。。
失败显示Failure....
安装Xcache为Php加速
[root@kcw1 ~]# tar xf xcache-3.0.4.tar.bz2 [root@kcw1 ~]# cd xcache-3.0.4 [root@kcw1 xcache-3.0.4]# /usr/local/php/bin/phpize Configuring for: PHP Api Version: 20100412 Zend Module Api No: 20100525 Zend Extension Api No: 220100525 [root@kcw1 xcache-3.0.4]# ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config [root@kcw1 xcache-3.0.4]# make && make install 安装结束时,会出现类似如下行 extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20100525/ 编辑php.ini,整合php和xcache: 首先将xcache提供的样例配置导入php.ini # mkdir /etc/php.d # cp xcache.ini /etc/php.d 接下来编辑/etc/php.d/xcache.ini,找到zend_extension开头的行,修改为如下行 vim /etc/php.d/xcache.ini extension =/usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so xcache.mmap_path = "/tmp/xcache" [root@kcw1 xcache-3.0.4]# touch /tmp/xcache [root@kcw1 xcache-3.0.4]# chmod 777 /tmp/xcache 重启httpd看是否加载xcache模块
至此配置完成!注意编译所带的参数 可以在源码包下面用./configure --help |less 查看又相应的解释!
启用xcache后台管理
[root@kcw1 xcache-3.0.4]# cp -r htdocs /usr/local/apache/htdocs/admin 找到xcach.ini配置文件这一段 [xcache.admin] xcache.admin.enable_auth = On xcache.admin.user = "admin" xcache.admin.pass = "6a0194f9707fa832ece6f5b66a25567e" #echo -n "youp-assword" |md5sum |awk '{print $1}' 密码必须以MD5来存放不让重启httpd报错
然后在浏览器里输入http//192.168.0.1/admin
输入admin 和you_password
如有错误的地方还请大家多多指出来!