安装apache,PHP与解析PHP

1.2安装apache

1.2.1下载

下载三个源码包放到 /usr/local/src/目录中

 

1.2.2解压、安装与编译

1、  解压

 tar zxvf apr-1.6.5.tar.gz

 tar zxvf apr-util-1.6.1.tar.gz

 tar zxvf httpd-2.4.39.tar.gz

2、  安装Apr以及Apr-until:

cd /usr/local/src/apr-1.6.5

./configure --prefix=/usr/local/apr

make && make install

cd /usr/local/src/apr-util-1.6.1

./configure –prefix=/usr/1ocal/apr-util --with-apr-/usr/local/apr

make && make install

3、  安装htpd,配置编译参数

编译与安装:

编译参数:

提前安装库文件 yum install -y pcre pcre-devel

  ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most

(--prefix 指定安装目录,--enable-so表示启用DSO,enable- mods- shared-most表示以共享的方式安装大多数功能模块)

编译安装

make && make install

   echo $?查看是否正确

安装完后,查httpd的目录结构以及modules目录下面的模块文件:

       ls /usr/local/apache2.4/

       ls /usr/local/apache2.4/modules/

 

查看加载了哪些模块: /usr/local/apache2.4/bin/apachectl -M

 

1.2.3遇到的问题:

 

解决的办法:yum install -y expat-devel

 

解决办法:重新编译安装apr_util

1.3安装php

1.3.1下载与解压

下载源码包放到 /usr/local/src/目录中

 

解压PHP源码包

tar zxf php-5.6.30.tar.gz

1.3.2 配置编译参数

cd php-5.6.30

./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/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

 

1.3.3编译和安装

       make

       make install

1.3.4复制配置文件  

  cp php.ini-production /usr/local/php/etc/php.ini

 

1.3.5 配置httpd支持PHP

1、 编辑httpd的主配置文件:

vim /usr/local/apache2.4/conf/httpd.conf

搜索ServerName,找到并修改为

 

再修改:

 

目的:允许所有请求,如果不设置该行,则我们访问的时候会报403错误

再搜索 AddType application/x-gzip .gz .tgz 修改为

 

再修改

 

:wq保存

1.3.6 出现问题与解决办法

常见几个错误及解决办法:

错误一:configure: error: xml2-config not found. Please check your 11bxml2 installation.

解决办法:# yum install -y 11bxml2-devel

错误二:configure: error: Cannot find OpenSSL's <evp.h>

解决办法:# yum install y openssl openssl-devel

错误三:checking for BZip2 in default path... not found

        configure: error: Please reinstall the BZip2 distribution

解决办法:# yum install -y bzip2 bzip2-devel

错误四:configure: error: png.h not found.

解决办法:# yum install -y libpng libpng-devel

错误五:configure: error: freetype.h not found.

解决办法:# yum install -y freetype freetype-devel

错误六:configure: error: mcrypt.h not found. Please reinstall libmcrypt.

解决办法:# yum install -y epel-release

          # yum install -y libmcrypt-devel

1.4解析php

1.4.1 测试LAMP是否成功

测试配置文件是否正确:

/usr/local/apache2.4/bin/apachectl -t

如果有错误,继续修改配置文件httpd.conf,如果正确则会显示"Syntax OK"。

 

启动httpd :

 /usr/local/apache2.4/bin/apachectl start

 

查看是否启动的命令:

netstat -lnp |grep httpd

测试:

curl localhost

 

如果显示了这一行则说明测试成功

1.4.2 测试是否正确解析PHP

vim /usr/local/apache2.4/htdocs/1.php

 

显示以下则说明php解析正确

 

猜你喜欢

转载自www.cnblogs.com/315z/p/12106407.html