apache与php安装

安装库文件

yum install -y pcre pcre-devel apr apr-deve

安装apache

cd /usr/local/src/httpd-2.4.23

Bundled APR requested but not found at ./srclib/. Download and unpack the corresponding apr and apr-util packages to ./srclib/.

wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.5.2.tar.gz

wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.5.4.tar.gz

[root@a src]# tar -zxf apr-1.5.2.tar.gz -C httpd-2.4.23/srclib/
[root@a src]# tar -zxf apr-util-1.5.4.tar.gz -C httpd-2.4.23/srclib/

[root@a srclib]# mv apr-1.5.2/ apr
[root@a srclib]# mv apr-util-1.5.4/ apr-util

./configure --prefix=/usr/local/apache2 --with-included-apr --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --with-pcre

configure: error: in `/usr/local/src/httpd-2.4.23/srclib/apr':
configure: error: no acceptable C compiler found in $PATH

#安装gcc

yum -y install gcc

#重新编译

mod_deflate has been requested but can not be built due to prerequisite failures

#安装

yum install  zlib-devel openssl-devel

#重新编译,编译通过

make && make install

##安装php

wget http://cn2.php.net/get/php-5.6.28.tar.gz/from/this/mirror

#依赖包安装,可以在apache安装前进行安装

yum  install  -y  gcc  gcc-c++    make  zlib  zlib-devel  pcre  pcre-devel    libjpeg  libjpeg-devel  libpng  libpng-devel  freetype  freetype-devel  libxml2  libxml2-devel  glibc  glibc-devel  glib2  glib2-devel  bzip2  bzip2-devel  ncurses  ncurses-devel  curl  curl-devel    openssl  openssl-devel gd gd-devel libicu libicu-devel autoconf libevent libevent-devel   libmcrypt libmcrypt-devel
#安装
 

./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  --enable-bcmath

## php-7   --with-pdo-mysql 

configure: error: mcrypt.h not found. Please reinstall libmcrypt.
#安装

wget http://downloads.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz

tar –xzf libmcrypt-2.5.8.tar.gz

[root@a libmcrypt-2.5.8]# ./configure

make && make install

#重新编译php

error: Cannot find libmysqlclient_r under /usr/local/mysql.

ln -s libmysqlclient.so.20.3.3 libmysqlclient_r.so  (mysql5.7.16)

#编译动过

make && make install

apache与php结合

vim /usr/local/apache2/conf/httpd.conf
#找到
AddType application/x-gzip .gz .tgz
#在下面添加
AddType application/x-httpd-php .php

#找到

<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>
#修改

<IfModule dir_module>
    DirectoryIndex index.html index.htm index.php
</IfModule>

#

#ServerName www.example.com:80
#修改

#测试lamp是否安装成

#检验配置文件是否正确

[root@a conf]# /usr/local/apache2/bin/apachectl -t
Syntax OK
#启动apache

/usr/local/apache2/bin/apachectl  start

#查看是否启动

[root@a conf]# netstat -lnp |grep httpd
tcp        0      0 :::80                       :::*                        LISTEN      80644/httpd 

[root@a conf]# curl localhost
<html><body><h1>It works!</h1></body></html>

#php测试

[root@a htdocs]# vim 1.php

<?php
    echo "php解析正常";
?>
 

[root@a htdocs]# curl localhost/1.php
php解析正常

原文地址:https://www.cnblogs.com/HarveyBing/p/6140665.html