编译安装软件需要安装开发环境,关闭iptables和selinux
# yum groupinstall "Development Tools" "Server Platform Development"
一、编译安装httpd
httpd2.4需要apr、apr-util依赖包
1.编译安装apr、apr-util
# tar xf apr-1.5.0.tar.bz2 # cd apr-1.5.0 # ./configure --prefix=/usr/local/apr # make && make install # tar xf apr-util-1.5.3.tar.bz2 # cd apr-util-1.5.3 # ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr # make && make install
2.编译安装httpd
在安装之前需要安装pcre-devel包,因为在编译安装http时会安装pcre,这个包依赖于pcre-devel,系统自带没有pcre-devel这个包
# yum install pcre-devel # tar xf httpd-2.4.10.tar.bz2 # cd httpd-2.4.10 # ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --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 # make && make install
3.启动httpd服务
编译安装的httpd自带有启动脚本:apachectl,所以执行/usr/local/apache/bin/apachectl命令即可启动httpd服务
直接使用apachectl命令需做一下步骤:
# vim /etc/profile.d/httpd.sh # . /etc/profile.d/httpd.sh # echo $PATH # cat /etc/profile.d/httpd.sh export PATH=/usr/local/apache/bin:$PATH
4.修改httpd的主配置文件 vim /etc/httpd24/httpd.conf ,添加下行即可:
PidFile "/var/run/httpd.pid"
5.将之前的httpd sysv服务脚本拷贝过来并修改配置文件中的以下数据:
cp /etc/rc.d/init.d/httpd /etc/rc.d/init.d/httpd24 # pidfile: /var/run/httpd.pid apachectl=/usr/local/apache/bin/apachectl httpd=${HTTPD-/usr/local/apache/bin/httpd} pidfile=${PIDFILE-/var/run/httpd.pid}
#!/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/httpd24
6.加入服务列表并启动服务:
# chkconfig --add httpd24 # chkconfig httpd24 on # service httpd24 status # service httpd24 start
二、编译安装mysql
1.新建一个lvm,然后将其挂载到数据库目录下:
# fdisk /dev/sda # partx -a /dev/sda # partx -a /dev/sda # pvcreate /dev/sda5 # vgcreate myvg /dev/sda5 # lvcreate -L 5G -n mylv myvg # mkfs.ext4 /dev/myvg/mylv # mkdir -pv /mydata/data # mount /dev/myvg/mylv /mydata/data
2.新建用户以安全方式运行
# groupadd -r mysql # useradd -g mysql -r -s /sbin/nologin -M -d /mydata/data mysql # chown -R mysql:mysql /mydata/data
3.安装并初始化mysql
# tar xf mariadb-5.5.43-linux-x86_64.tar.gz -C /usr/local # cd /usr/local # ln -sv mariadb-5.5.43-linux-x86_64 mysql # cd mysql # chown -R root:mysql ./* # scripts/mysql_install_db --datadir=/mydata/data/ --user=mysql //初始化数据库
4.为数据库创建主配置文件
# mkdir /etc/mysql # cp support-files/my-large.cnf /etc/my.cnf
5.修改配置文件:添加如下几行,并修改此文件中thread_concurrency的值为你的CPU个数乘以2
datadir = /mydata/data //数据存放目录 innodb_file_per_table= on //每个innnodb表使用单个表文件 skip_name_resolve = on //跳过主机名称解析
6.为mysql提供sysv服务脚本,并添加至服务列表
# cp support-files/mysql.server /etc/rc.d/init.d/mysqld # chmod +x /etc/rc.d/init.d/mysqld # chkconfig --add mysqld
7.在配置文件中定义“pid-file”文件路径,否则启动mysql会出现错误
vim /etc/my.cnf pid-file=/mydata/data/mysql.pid vim /etc/rc.d/init.d/mysqld mysqld_pid_file_path=/mydata/data
8.输出mysql的man手册至man命令中:
# vim /etc/man.config 添加下行即可: MANPATH /usr/local/mysql/man
9.输出mysql的头文件至系统文件路径/usr/include:
# ln -sv /usr/local/mysql/include /usr/include/mysql
10.输出mysql的库文件给系统库查找路径:
# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
重新加载系统库:
# ldconfig
11.修改PATH环境变量,让系统可以直接使用mysql的相关命令:
vim /etc/profile.d/mysqld.sh # export PATH=/usr/local/mysql/bin:$PATH # . /etc/profile.d/mysqld.sh # service mysqld start
三、编译安装php
1.开始安装php所需依赖环境:
# yum -y groupinstall "Desktop Platform Development" # yum -y install bzip2-devel libmcrypt-devel libxml2-devel // libmcrypt-devel 本地光盘没有在epel源里面。其他的是epel源.,编译安装libmcrypt 如何安装epel源? 先安装yum优先级插件: # yum install yum-priorities 安装epel: # rpm -Uvh http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm #rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm 导入epel: # rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 修改epel配置文件中epel的源级别:加入下行就OK了 priority=11 创建缓存: # yum makecache
2.编译安装libmcrypt
# tar xf libmcrypt-2.5.7.tar.gz # cd libmcrypt-2.5.7 # ./configure --prefix=/usr/local/libmcrypt # make && make install
3.开始编译安装php:
# tar xf php-5.4.40.tar.bz2 # cd php-5.4.40 # ./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=/usr/local/libcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts //msqli:对应mysql另外的一个接口 ,freetype:多种字体 libxml:处理xml的文档 socket:支持socket apxs:支持http第三方模块 zts:如果之前安装过httpd且模块是prefork则不需要,否则必须安装上去 # make -j //启用多线程安装(由于php安装比较耗时) # make install
默认情况下http是不支持php的,所以需要修改配置文件:
# cp /etc/httpd24/httpd.conf /etc/httpd24/httpd.conf.bak
4.为php提供配置文件:
# cp php.ini-production /etc/php.ini
确认php模块是否加载进来:
5.编辑apache文件使其支持php:
在文件中添加入下行:
DirectoryIndex index.php index.html AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps
6.重置下httpd服务:
# /usr/local/apache/bin/apachectl reload
7.默认测试页面在/usr/local/apache/htdocs,添加一个index.php测试文件:
<?php $link = mysql_connect('127.0.0.1','root',' '); if ($link) echo "Success..."; else echo "Failure..."; phpinfo(); mysql_close(); ?>
8.测试网页http://hostloaclIP