阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

CentOS6.8编译安装Apache2.4.25、MySQL5.7.16、PHP5.6.29

141次阅读
没有评论

共计 6655 个字符,预计需要花费 17 分钟才能阅读完成。

CentOS6.8 编译安装 Apache2.4.25、MySQL5.7.16、PHP5.6.29

初始化

# 固定 IP
vi /etc/sysconfig/network-scripts/ifcfg-eth0
ONBOOT=yes
BOOTPROTO=none
DNS1=202.96.209.133
IPADDR=192.168.159.68
PREFIX=24
GATEWAY=192.168.159.2

# 基础库 
yum groupinstall base
yum grouplist
yum groupinstall 'Development tools'
yum groupinstall 'Debugging Tools'
yum groupinstall 'Compatibility libraries'

安装 Apache

# 下载 
mkdir /app/src -p
cd /app/src/
wget -c http://mirrors.aliyun.com/apache/apr/apr-1.5.2.tar.gz
wget -c http://mirrors.aliyun.com/apache/apr/apr-util-1.5.4.tar.gz
wget -c http://mirrors.aliyun.com/apache/httpd/httpd-2.4.25.tar.gz
tar xf apr-1.5.2.tar.gz

# 安装 apr
cd apr-1.5.2
./configure --prefix=/app/apr-1.5.2
make && make install
ln -sv /app/apr-1.5.2/ /app/apr

# 安装 apr-util
cd ..
tar xf apr-util-1.5.4.tar.gz
cd apr-util-1.5.4
./configure --prefix=/app/apr-util-1.5.4 -
-with-apr=/app/apr-1.5.2/
make && make install
ln -sv /app/apr-util-1.5.4/ /app/apr-util

# 安装 httpd
yum install pcre-devel zlib-devel openssl-devel -y
cd ..
tar xf httpd-2.4.25.tar.gz
cd httpd-2.4.25
./configure --prefix=/app/httpd-2.4.25 --with-apr=/app/apr-1.5.2/ \
--with-apr-util=/app/apr-util-1.5.4/ --enable-so --enable-deflate --enable-expires \
--enable-headers --enable-ssl --enable-rewrite --enable-mpms-shared=all \
--with-mpm=prefork --enable-mods-shared=most
make
make install
ln -sv /app/httpd-2.4.25/ /app/httpd
vi /etc/profile.d/httpd.sh
export PATH=/app/httpd/bin:$PATH
. /etc/profile.d/httpd.sh
# 查看所有模块 
ls /app/httpd/modules/
# 查看加载模块 
apachectl -t -D DUMP_MODULES
vi /app/httpd/conf/httpd.conf
ServerName localhost:80
apachectl start
netstat -tunlp | grep httpd
cp ./httpd /etc/init.d/httpd
# 修改 pid 和 lock 文件路径 
vi /etc/init.d/httpd
apachectl=/app/httpd/bin/apachectl
httpd=${HTTPD-/app/httpd/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/app/httpd/logs/httpd.pid}
lockfile=${LOCKFILE-/app/httpd/logs/httpd}
apachectl stop
chmod +x /etc/init.d/httpd
/etc/init.d/httpd start
chkconfig --list | grep httpd
chkconfig --add httpd
chkconfig --list httpd
chkconfig httpd on
chkconfig --list httpd
#!/bin/bash
#
# httpd        Startup script for the Apache HTTP Server
#
# chkconfig: - 85 15
# description: The Apache HTTP Server is an efficient and extensible  \
#          server implementing the current HTTP standards.
# processname: httpd
# config: /etc/httpd/conf/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /var/run/httpd/httpd.pid
#
### BEGIN INIT INFO
# Provides: httpd
# Required-Start: $local_fs $remote_fs $network $named
# Required-Stop: $local_fs $remote_fs $network
# Should-Start: distcache
# Short-Description: start and stop Apache HTTP Server
# Description: The Apache HTTP Server is an extensible server 
#  implementing the current HTTP standards.
### END INIT INFO

# 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=/app/httpd/bin/apachectl
httpd=${HTTPD-/app/httpd/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/app/httpd/logs/httpd.pid}
lockfile=${LOCKFILE-/app/httpd/logs/httpd}
RETVAL=0
STOP_TIMEOUT=${STOP_TIMEOUT-10}

# The semantics of these two functions differ from the way apachectl does
# things -- attempting to start while running is a failure, and shutdown
# when not running is also a failure.  So we just do it the way init scripts
# are expected to behave here.
start() {echo -n $"Starting $prog:"
        LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
        RETVAL=$?
        echo
        [$RETVAL = 0 ] && touch ${lockfile}
        return $RETVAL
}

# When stopping httpd, a delay (of default 10 second) is required
# before SIGKILLing the httpd parent; this gives enough time for the
# httpd parent to SIGKILL any errant children.
stop() {status -p ${pidfile} $httpd > /dev/null
    if [[$? = 0 ]]; then
        echo -n $"Stopping $prog:"
        killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd
    else
        echo -n $"Stopping $prog:"
        success
    fi
    RETVAL=$?
    echo
    [$RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}

reload() {echo -n $"Reloading $prog:"
    if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
        RETVAL=6
        echo $"not reloading due to configuration syntax error"
        failure $"not reloading $httpd due to configuration syntax error"
    else
        # Force LSB behaviour from killproc
        LSB=1 killproc -p ${pidfile} $httpd -HUP
        RETVAL=$?
        if [$RETVAL -eq 7 ]; then
            failure $"httpd shutdown"
        fi
    fi
    echo
}

# See how we were called.
case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  status)
        status -p ${pidfile} $httpd
    RETVAL=$?
    ;;
  restart)
    stop
    start
    ;;
  condrestart|try-restart)
    if status -p ${pidfile} $httpd >&/dev/null; then
        stop
        start
    fi
    ;;
  force-reload|reload)
        reload
    ;;
  graceful|help|configtest|fullstatus)
    $apachectl $@
    RETVAL=$?
    ;;
  *)
    echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}"
    RETVAL=2
esac

exit $RETVAL

安装 MySQL

wget -c http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-boost-5.7.16.tar.gz
wget -c https://cmake.org/files/v3.7/cmake-3.7.1.tar.gz
tar xf cmake-3.7.1.tar.gz 
cd cmake-3.7.1
less README.rst 
./bootstrap --prefix=/app/cmake-3.7.1
gmake
gmake install
cd ..
ln -sv /app/cmake-3.7.1/ /app/cmake
export PATH=/app/cmake/bin:$PATH
tar xf mysql-boost-5.7.16.tar.gz 
cd mysql-5.7.16/
yum install ncurses-devel
cmake . -DCMAKE_INSTALL_PREFIX=/app/mysql-5.7.16 -DMYSQL_DATADIR=/app/mysql-5.7.16/data \
-DWITH_BOOST=/app/src/mysql-5.7.16/boost/ -DENABLED_LOCAL_INFILE=1 -DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1
make
make install
#初始化权限
cd /app/mysql-5.7.16
mkdir data
useradd mysql -M -s /sbin/nologin
chown mysql.mysql /app/mysql-5.7.16/ -R
#移走系统自带的配置文件
mv /etc/my.cnf /etc/my.cnf.ori
bin/mysqld --initialize --user=mysql --basedir=/app/mysql-5.7.16/ --datadir=/app/mysql-5.7.16/data/
cp support-files/mysql.server /etc/init.d/mysqld
/etc/init.d/mysqld start
bin/mysql -uroot -p
ALTER USER root@localhost IDENTIFIED BY 'root';

安装 PHP

cd /app/src
tar xf php-5.6.29.tar.gz
cd php-5.6.29
yum install libxml2-devel curl-devel libjpeg-devel libpng-devel freetype-devel
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
yum install libmcrypt-devel
./configure --prefix=/app/php-5.6.29 --with-apxs2=/app/httpd-2.4.25/bin/apxs \
--with-mysql --with-mysqli --enable-pdo --with-pdo-mysql --with-mysql-sock \
--enable-xml --with-libxml-dir --enable-sockets --with-curl \
--with-gd --enable-gd-native-ttf --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib \
--with-mcrypt --with-openssl --with-mhash --enable-zip --enable-mbstring --enable-mbregex \
--with-iconv --enable-static
make
make install
vi /app/httpd/conf/httpd.conf
DirectoryIndex index.php index.html
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

官方推荐使用 Apache 默认的 MPM:prefork, 每个请求使用单独的进程。
第二选择是 FastCGI:PHP-fpm,编译加上–enable-fpm
第三选择才是 Apache 的 worker 或 event,但要加上–enable-maintainer-zts

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2016-12/138993.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计6655字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中