服务器重置了一下,想要安装最新的软件,在此记录一下
环境:
LSB Version: :core-4.1-amd64:core-4.1-noarch Distributor ID: CentOS Description: CentOS Linux release 7.2.1511 (Core) Release: 7.2.1511 Codename: Core
目标:
Apache 2.4.33 PHP 7.2.4 mysql 5.7.21
开始吧 ;)
Apache
1.安装编译环境 2.下载源码包并解压 3.配置、编译、安装 4.测试 5.加入系统服务、开机启动、加入系统命令
1. yum -y install gcc gcc- gcc++ zlib zlib-devel cmake
2. wget http://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.33.tar.bz2
tar -xjvf httpd-2.4.33.tar.bz2 (如果出错,检查是否安装了bzip2)
3.下载安装依赖 apr 、 apr-util、pcre,编译安装apache
wget http://archive.apache.org/dist/apr/apr-1.5.0.tar.gz
tar -zxvf apr-1.5.0.tar.gz
cd apr-1.5.0
./configure --prefix=/usr/local/apr/
make && make install
wget http://archive.apache.org/dist/apr/apr-util-1.5.4.tar.gz
tar -zxvf apr-util-1.5.4.tar.gz
cd apr-util-1.5.4
./configure --prefix=/usr/local/apr-util/ --with-apr=/usr/local/apr/
make && make install
wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.39/pcre-8.39.tar.gz
tar -zxvf pcre-8.39.tar.gz
cd pcre-8.39
./configure --prefix=/usr/local/pcre/
make && make install
cd httpd-2.4.33
./configure --prefix=/www/apache/httpd --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre/ --enable-rewrite --enable-so --enable-headers --enable-expires --with-mpm=worker --enable-modules=most --enable-deflate
make && make install
--prefix=/www/apache/httpd 表示指定apache的安装路径
--with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre/ 表示依赖的安装路径
--enable-rewrite提供URL规则的重写更嫩那个,即根据已知的URL地址,转换为其它想要的URL地址
--enable-so激活apache服务的DSO(Dynamic Shared Objects动态共享目标),即在以后可以以DSO的方式编译安装共享模块,这个模块本身不能以DSO方式编译。
--enable-headers提供允许对HTTP请求头的控制。
--enable-expires激活荀彧通过配置文件控制HTTP的“Expires:”和“Cache-Control:”头内容,即对网站图片、js、css等内容,提供客户端浏览器缓存的设置。这个是apache调优的一个重要选项之一。
--with-mpm=worker选择apache mpm的模式为worker模式。为worker模式原理是更多的使用线程来处理请求,所以可以处理更多的并发请求。而系统 资源的开销小玉基于进程的MPM prefork。如果不指定此参数,默认的模式是prefork进程模式。这个是apache调优的一个重要选项之一。
--enable-deflate提供对内容的压缩传输编码支持,一般是html、js、css等内容的站点。使用此参数会打打提高传输速度,提升访问者访问的体验。在生产环境中,这是apache调优的一个重要选项之一。4.测试
centos7使用systemctl代替chkconfig管理服务,防火墙也由iptables更换成了firewalld
首先用systemctl关闭防火墙:
systemctl stop firewalld.servicesystemctl disable firewalld.service
进入 /www/apache/httpd/bin ,备份和修改httpd.conf
cp httpd.conf httpd.conf.bak
vim httpd.conf
搜索ServerName
将前面的#去掉,修改为 ServerName localhost:80
cd ../httpd/bin
./apachectl start
浏览器访问。
It works!
5.加入开机启动:
将apachectl文件copy到/etc/init.d中,然后再/etc/rc.d/rc5.d中加入链接
cp /www/apache/httpd/bin/apachectl /etc/init.d/httpd
ln -s /etc/init.d/httpd /etc/rc.d/rc5.d/S85httpd
接下来加入系统服务:
运行chkconfig –list 发现列表中没有httpd,通过chkconfig –add httpd来添加,可能会提示httpd服务不支持chkconfig,需要编辑/etc/rc.d/init.d/httpd
在文件末尾添加以下注释信息:
# chkconfig: 345 85 15
# description: Activates/Deactivates Apache Web Server
运行chkconfig –list,httpd 就存在了
可以使用service httpd start 和 service httpd stop来启动和停止服务。
加入环境变量:
vi /etc/profile找到export行,在下面新增加一行,内容为:export PATH=$PATH:/www/apache/httpd/bin
注:= 等号两边不能有任何空格。这种方法最好,除非手动强制修改PATH的值,否则将不会被改变。
source /etc/profile