安装之前
确保你的环境可以上网(没网就不用往下看了)
清理已经安装过的相关软件
rpm -e httpd httpd-tools mysql mysql-libs php-mysql php-cli php-gd php-common php --nodeps
yum -y remove httpd*
yum -y remove mysql-server mysql mysql-libs
yum -y remove php*
yum clean all
同步时间
yum -y install ntp
ntpdate -u pool.ntp.org
解决依赖
用yum安装lanmp必备的库
yum -y install cmake gcc gcc-c++ gcc-g77 flex bison file libtool libtool-libs autoconf kernel-devel patch wget crontabs libjpeg libjpeg-devel libpng libpng-devel libpng10 libpng10-devel gd gd-devel libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel unzip tar bzip2 bzip2-devel libevent libevent-devel ncurses ncurses-devel curl curl-devel libcurl libcurl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel vim-minimal gettext gettext-devel ncurses-devel gmp-devel pspell-devel unzip libcap diffutils ca-certificates net-tools libc-client-devel psmisc libXpm-devel git-core c-ares-devel libicu-devel libxslt libxslt-devel xz expat-devel
创建用户
这里以www用户身份运行apache、nginx、php-fpm。
groupadd www
useradd -s /sbin/nologin -g www www
安装apache2.4
下载apr、apr-util、apache
APR(Apache portable Run-time libraries,Apache可移植运行库)的目的如其名称一样,主要为上层的应用程序提供一个可以跨越多操作系统平台使用的底层支持接口库。在早期 的Apache版本中,应用程序本身必须能够处理各种具体操作系统平台的细节,并针对不同的平台调用不同的处理函数。
wget http://mirrors.hust.edu.cn/apache//apr/apr-1.6.3.tar.gz
tar -zxvf apr-1.6.3.tar.gz
wget http://mirrors.hust.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
tar -zxvf apr-util-1.6.1.tar.gz
wget http://mirrors.hust.edu.cn/apache//httpd/httpd-2.4.33.tar.gz
tar -zxvf httpd-2.4.33.tar.gz
剪切apr、apr-util到apache的srclib目录
cp -rf ./apr-1.6.3 ./httpd-2.4.33/srclib/apr
cp -rf ./apr-util-1.6.1 ./httpd-2.4.33/srclib/apr-util
编译安装
cd httpd-2.4.33
./configure --prefix=/usr/local/apache --enable-mods-shared=most --enable-headers --enable-mime-magic --enable-proxy --enable-so --enable-rewrite --with-ssl --enable-ssl --enable-deflate --with-pcre --with-included-apr --with-apr-util --enable-mpms-shared=all --with-mpm=prefork --enable-remoteip
make && make install
其中,--prefix为apache的安装目录
配置文件
vim /usr/local/apache/conf/httpd.conf
1、找到:
#LoadModule rewrite_module modules/mod_rewrite.so
去除前面的‘#’号
2、找到:
User daemon
Group daemon
修改为刚刚创建的用户www:
User www
Group www
3、找到
#ServerName www.example.com:80
在其下一行添加:
ServerName 0.0.0.0:80
4、找到
<Directory />
AllowOverride none
Require all denied
</Directory>
修改为:
<Directory />
AllowOverride All
Require all granted
</Directory>
配置服务
cp /usr/local/apache/bin/apachectl /etc/init.d/httpd
sed -i '2 i\# chkconfig: 345 85 15\n# description: Activates/Deactivates Apache Web Server' /etc/init.d/httpd
chmod +x /etc/init.d/httpd
启动服务
systemctl enable httpd.service
systemctl start httpd.service
如果是centos6,请使用:
chkconfig httpd on
service httpd start
验证
查看httpd是否在监听:
netstat -natpl | grep httpd
用浏览器打开 http://127.0.0.1:80/
It works!