CentOS6.8服务器LAMP环境搭建(一) 安装Apache2.4.25

来源:互联网 发布:js数组合并函数 编辑:程序博客网 时间:2024/06/06 01:55
一、系统环境
系统平台:
CentOS 6.8 64位
Apache版本: 
httpd-2.4.25.tar.gz
MySQL版本: 
mysql-5.7.18.tar.gz
PHP版本: 
php-7.1.4.tar.gz
phpMyAdmin版本:phpMyAdmin-4.7.0-all-languages.tar.gz

二、安装前准备
在安装PHP之前,应先安装PHP需要的最新版本库文件,例如libxml2、libmcrypt以及GD2库等文件。安装GD2库是为了让PHP支持GIF、PNG和JPEG等图片格式,所以在安装GD2库之前还要先安装最新的zlib、libpng、freetype和jpegsrc等库文件。而且整个环境的搭建中还会穿插安装一些扩展和软件,可按照步骤安装。

1、准备所需库文件(有的安装了后面也没用,但是统统安装吧)
autoconf-2.69.tar.gz
freetype-2.7.1.tar.gz
libgd-2.1.0.tar.gz
jpegsrc.v9.tar.gz
libmcrypt-2.5.8.tar.gz
libpng-1.6.29.tar.gz
libxml2-2.7.8.tar.gz
zlib-1.2.11.tar.gz
apr-1.5.2.tar.gz
apr-util-1.5.4.tar.gz
pcre-8.40.tar.gz
curl-7.54.0.tar.gz

2、安装系统所需依赖库(由于在后面的安装过程中遇到很多缺少依赖的问题,所以现在整理了一下,集中在这一步安装)
yum -y install gcc gcc-c++ gcc-g77 make cmake bison ncurses-devel autoconf automake zlib* fiex* libxml*  libmcrypt* libtool-ltdl-devel* libaio libaio-devel bzr libtool ncurses5-devel imake libxml2-devel expat-devel

3、卸载之前安装的旧版本环境
a、使用yum remove xxxx命令
b、使用
rpm -e xxxx命令
c、删除相关文件rm -rf xxxx 

4、将准备好的.tar.gz软件包上传到服务器的/usr/local/src目录下

5、使用tar -zxvf xxxx命令逐一解压软件包

三、安装依赖库
1、安装libxml2
# cd /usr/local/src/libxml2-2.7.8
# ./configure --prefix=/usr/local/libxml2
# make && make install

2、安装libmcrypt
# cd /usr/local/src/libmcrypt-2.5.8
# ./configure --prefix=/usr/local/libmcrypt
# make && make install 

3、安装zlib
# cd /usr/local/src/zlib-1.2.11
# ./configure --prefix=/usr/local/zlib
# make && make install 

4、安装libpng
# cd /usr/local/src/libpng-1.6.29
# ./configure --prefix=/usr/local/libpng
# make && make install

5、安装jpeg9
这个软件包安装有些特殊,其它软件包安装时如果目录不存在,会自动创建,但这个软件包安装时需要手动创建。
# mkdir /usr/local/jpeg9
# mkdir /usr/local/jpeg9/bin
# mkdir /usr/local/jpeg9/lib
# mkdir /usr/local/jpeg9/include
# mkdir -p /usr/local/jpeg9/man/man1
# cd /usr/local/src/jpeg-9
# ./configure --prefix=/usr/local/jpeg9/ --enable-shared --enable-static
# make && make install 

6、安装freetype
# cd /usr/local/src/freetype-2.7.1
# ./configure --prefix=/usr/local/freetype
# make && make install

7、安装autoconf
# cd /usr/local/src/autoconf-2.69
# ./configure
# make && make install

8、安装GD库
# cd /usr/local/src/libgd-2.1.0
# ./configure -prefix=/usr/local/gd2 \
--with-jpeg=/usr/local/jpeg9 \
--with-png=/usr/local/libpng/  \
--with-zlib=/usr/local/zlib/  \
--with-freetype=/usr/local/freetype
# make && make install

9、安装xpm
# yum -y install libXpm-devel.x86_64

10、安装apr
# cd apr-1.5.2
# ./configure --prefix=/usr/local/apr
# make && make install

11、安装apr-util
# cd apr-util-1.5.4
# ./configure  --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make && make install

12、安装pcre
# cd pcre-8.40
# ./configure --prefix=/usr/local/pcre
# make && make install

13、安装curl
# cd curl-7.54.0
# ./configure  --prefix=/usr/local/curl
# make && make install

四、安装Apache
1、下载源码
# cd /usr/local/src
# wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.25.tar.gz

2、解压
# tar -zxvf 
httpd-2.4.25.tar.gz

3、进入源码目录,开始安装
# cd 
httpd-2.4.25
./configure --prefix=/usr/local/apache2 \
--with-pcre=/usr/local/pcre \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util \
--with-z=/usr/local/zlib \
--enable-so \
--enable-expires=shared \
--enable-rewrite=shared \
--enable-static-support
# make && make install

4、安装完之后,配置Apache,
找到/usr/local/apache2/conf/httpd.cnf
a、将文件中的 
#ServerName www.example.com:80 改为 ServerName localhost:80,ServerRoot的路径改为"/usr/local/apache2",DocumentRoot的路径改为"/usr/local/apache2/htdocs"。

b、修改所有文件的权限
<Directory />
    Options FollowSymLinks
    AllowOverride All
    Order deny,allow
    Allow from all
    Satisfy all
</Directory>

<Directory "/usr/local/apache2/cgi-bin">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
</Directory>

c、修改根目录权限
<Directory "/usr/local/apache2/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
    Require all granted
</Directory>

d、配置欢迎页(首页) 
<IfModule dir_module>
    DirectoryIndex index.php index.html index.htm
</IfModule>

e、加载PHP模块和开启其他扩展
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
Addtype application/x-httpd-php .php .phtml

f、
配置启动脚本
# cp /usr/local/src/httpd-2.4.25/build/rpm/httpd.init /etc/init.d/httpd

注意文件中有三处主要的地方需要修改下的:
httpd=${HTTPD-/usr/local/apache2/bin/httpd} 
pidfile=${PIDFILE-/usr/local/apache2/logs/${prog}.pid} 
CONFFILE=/usr/local/apache2/conf/httpd.conf
请根据自己的实际情况更改相应的路径!

g、设置Apache服务并启动
chmod +x /etc/init.d/httpd
# chkconfig --add httpd
# chkconfig httpd on
# /etc/init.d/httpd start

# netstat -lnp |grep httpd


安装了好多次,这是最后一次安装成功的详细过程,存档备用,仅供参考。

0 0
原创粉丝点击