LAMP架构系统服务搭建过程详解

2019-10-12 16:01:39于丽

二、Apache服务安装

apache可以通过yum的方式来安装,也可以通过源码编译的方式来安装,这里采用编译源码的方式进行安装。

1. 系统环境

CentOS 6.4 x86_64 Mini 版本安装

2. 下载解压apache安装包

[root@vip src]# cd /usr/local/src
[root@vip src]# wget http://mirror.bit.edu.cn/apache/httpd/httpd-2.2.31.tar.gz
[root@vip src]# tar zxf httpd-2.2.31.tar.gz

3. 安装必要的库和工具

[root@vip src]# yum install -y pcre pcre-devel apr apr-devel zlib-devel gcc make

4. 配置编译参数

[root@vip httpd-2.2.31]# cd httpd-2.2.31
[root@vip httpd-2.2.31]# ./configure 
--prefix=/usr/local/apache2 
--with-included-apr 
--enable-so 
--enable-deflate=shared 
--enable-expires=shared 
--enable-rewrite=shared 
--with-pcre
[root@vip httpd-2.2.31]# echo $?

5. 编译安装

[root@vip httpd-2.2.31]# make && make install
[root@vip httpd-2.2.31]# echo $?

6. 配置apache环境变量

[root@vip httpd-2.2.31]# echo 'export PATH=$PATH:/usr/local/apache2/bin' > /etc/profile.d/http.sh
[root@vip httpd-2.2.31]# source /etc/profile.d/http.sh

7. apache的启动和停止

apachectl start  # 启动
apachectl stop   # 停止
apachectl restart # 重启
apachectl -t    # 检查语法
apachectl -M    # 查看加载模块

8. 将apache加入系统服务

# 拷贝服务脚本
[root@vip httpd-2.2.31]# cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd
[root@vip httpd-2.2.31]# vim /etc/init.d/httpd  # 第一行下边添加2行内容
#!/bin/sh
# chkconfig: 2345 61 61
# description: Apache
# 添加到系统服务 并设置开机启动
[root@vip httpd-2.2.31]# chkconfig --add httpd
[root@vip httpd-2.2.31]# chkconfig httpd on

9. 验证服务是否正常

[root@vip httpd-2.2.31]# service httpd start
httpd: apr_sockaddr_info_get() failed for vip  # 出现警告信息
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

解决警告信息的方法:去掉 ServerName www.example.com:80 行的注释#。

 三、PHP系统安装

1. 下载解压安装包

[root@vip ~]# cd /usr/local/src
[root@vip src]# wget http://cn2.php.net/get/php-5.5.38.tar.gz/from/this/mirror -O php-5.5.38.tar.gz
[root@vip src]# tar zxf php-5.5.38.tar.gz

2. 下载依赖库和工具

[root@vip src]# yum install -y epel-release
[root@vip src]# yum install -y libxml2-devel openssl openssl-devel bzip2 bzip2-devel 
libjpeg-devel libpng libpng-devel freetype freetype-devel libmcrypt-devel

3. 编译配置安装选项

[root@vip php-5.5.38]# cd php-5.5.38
[root@vip php-5.5.38]# ./configure 
--prefix=/usr/local/php 
--with-apxs2=/usr/local/apache2/bin/apxs 
--with-config-file-path=/usr/local/php/etc 
--with-mysql=/usr/local/mysql 
--with-libxml-dir 
--with-gd 
--with-jpeg-dir 
--with-png-dir 
--with-freetype-dir 
--with-iconv-dir 
--with-zlib-dir 
--with-bz2 
--with-openssl 
--with-mcrypt 
--enable-soap 
--enable-gd-native-ttf 
--enable-mbstring 
--enable-sockets 
--enable-exif 
--disable-ipv6