centos6安装apache2.4+php7.1

httpd-2.4.29.tar.gz

php-7.1.10.tar.gz

apr-1.5.2.tar.bz2

apr-util-1.5.4.tar.bz2

pcre-8.38.zip

解压

一、安装apache

安装apr
#cd apr-1.5.2
#./configure --prefix=/usr/local/apr

#make && make install

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

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

安装apache

#cd ../httpd-2.4.29

指定安装路径,指定3个依赖包安装目录,让apache核心装载DSO,启用重写功能
#./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre  --enable-so --enable-rewrite 

#make && make install

httpd(Apache)设置为启动服务
# cp /usr/local/apache2/bin/apachectl   /etc/rc.d/init.d/httpd
打开/etc/rc.d/init.d/httpd文件,在# !/bin/sh下面添加
# chkconfig: 2345 50 90
# description: Activates/Deactivates ApacheWeb Server

运行chkconfig把Apache添加到系统的启动服务组里面
# chkconfig  --add  httpd
# chkconfig  httpd  on

httpd.conf 里的User和Group可能是daemon改成apache,没有就建一个,家目录设置为/var/www

useradd -s /sbin/nologin -d /var/www apache

cd /var/www

mkdir html

chown apache:apache html

 

修改apache配置

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

ServerName localhost:80
DocumentRoot ”/var/www/html”

User=daemon Group=daemon改为apache

至此apache安装完成

#service httpd start     启动apache

二、安装php

解压php

可能依赖的包yum 安装

curses curses-devel gd gd-devel flex zlib-devel openssl openssl-devel libxpm-dev freetype-devel libssl-dev bzip2 bzip2-devel curl curl-devel gmp-devel unixODBC-devel pspell-devel libmcrypt libmcrypt-devel net-snmp net-snmp-devel openldap-devel openldap-servers openldap-clients flex zlib-devel  libicu  libicu-devel  libxslt  libxslt-devel*

 

./configure --prefix=/usr/local/php7 --with-apxs2=/usr/local/apache2/bin/apxs --with-curl   --with-freetype-dir   --with-gd   --with-gettext   --with-iconv-dir   --with-kerberos   --with-libdir=lib64   --with-libxml-dir   --with-mysqli   --with-openssl   --with-pcre-regex   --with-pdo-mysql   --with-pdo-sqlite   --with-pear   --with-png-dir   --with-xmlrpc   --with-xsl   --with-zlib   --enable-fpm   --enable-bcmath   --enable-libxml   --enable-inline-optimization   --enable-gd-native-ttf   --enable-mbregex   --enable-mbstring   --enable-opcache --enable-pcntl   --enable-shmop   --enable-soap   --enable-sockets --enable-sysvsem --enable-xml   --enable-zip  --enable-intl  --enable-ldap

 

 

 

一般而言

enable表示某个功能是否开启[yes/no],且这种功能往往是php内置的.

with表示,是否需要添加某个功能,往往需要指定依赖的外部库在哪里.

所以,enable的选项后面往往无参数,--disable-short-tags,--enable-safe-mode

with后的选项,往往带上参数,:--with-config-file-path=PATH

 

 

 

报错configure: error: Cannot find OpenSSL's

解决:

yum install openssl openssl-devel

ln -s /usr/lib64/libssl.so /usr/lib/

 

make &&make install

 

cp php.ini-development /usr/local/php7/lib/php.ini

php.ini-production 对应于 php.ini-recommended

php.ini-development 对应于 php.ini-dist

通常要将 php.ini-production 重命名为 php.ini

二者不同之处在于 php.ini-development 适合开发程式使用(测试用),

 php.ini-recommended 拥有较高的安全性设定,则适合上线当产品使用。

所以,我一般将 php.ini-recommended 或者 php.ini-production 修改为 php.ini,确保测试环境(本地)与正式环境(线上)一致。

 

两者部分区别表:

php.ini-production

php.ini-development

error_reporting = E_ALL & ~E_DEPRECATED

error_reporting = E_ALL | E_STRICT

display_errors = Off

display_errors = On

display_startup_errors = Off

display_startup_errors = On

track_errors = Off

track_errors = On

html_errors = Off

html_errors = On

mysqlnd.collect_memory_statistics = Off

mysqlnd.collect_memory_statistics = On

session.bug_compat_42 = Off

session.bug_compat_42 = On

session.bug_compat_warn = Off

session.bug_compat_warn = On

 

cp /usr/local/php7/etc/{php-fpm.conf.default,php-fpm.conf}

/usr/local/php7/sbin/php-fpm #启动

cd /usr/local/php7/etc/php-fpm.d/

# cp www.conf.default  www.conf

# /usr/local/php7/sbin/php-fpm -t

[12-Oct-2017 08:33:29] NOTICE: configuration file /usr/local/php7/etc/php-fpm.conf test is successful

[root@localhost sbin]#./php-fpm

 

 

 

 

配置apache支持php

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

添加AddType application/x-httpd-php .php .html,并修改默认起始页面

 DirectoryIndex index.php index.html

添加PHP和Apache环境变量

#vim /etc/profile  添加上export PATH=/usr/local/php7/bin:/usr/local/apache2/bin:$PATH

#source /etc/profile修改环境变量后需要运行该指令才会生效


然后执行php  -v 和httpd -v  查看安装的版本号

 

 

测试代码:

 

phpinfo();

?>

 

三、php安装其他扩展包

进入之前编译安装php包中

  1. cd ~/php7.1.10/ext/ldap  

  2. /usr/local/php/bin/phpize

  3. ./configure --with-php-config=/usr/local/php/bin/php-config --with-ldap  

cd ~/php7.2.3/ext/ldap

/server/php7/bin/phpize

./configure --with-php-config=/server/php7/bin/php-config --with-ldap

出错信息I

configure: error: Cannot find ldap.h

解决方法

yum install -y openldap openldap-devel 

出错信息II

configure: error: Cannot find ldap libraries in /usr/lib

解决方法

cp -frp /usr/lib64/libldap* /usr/lib/

继续执行

./configure --with-php-config=/usr/local/php/bin/php-config --with-ldap  

./configure --with-php-config=/server/php7/bin/php-config --with-ldap

之后

make && make install

安装完成后

修改php配置文件(~/lib/php.ini),将extension=ldap前的分号去掉,保存退出

一般是extension=php_ldap.dll改成extension=ldap.so

没改会报错:

会查找这里的/usr/local/php/lib/php/extensions/no-debug-zts-20160303/ldap.so

并重启php-fpm

Killall php-fpm

/usr/local/php/sbin/php-fpm

查看安装是否成功

php -m

如图

 

Intl模块也是如此

出错:

configure: error: Unable to detect ICU prefix or no failed. Please verify ICU install prefix and make sure icu-config works.

解决:

yum install libicu-devel



你可能感兴趣的:(lamp)