1. 程式人生 > 實用技巧 >apache 2.4.18+php7安裝流程

apache 2.4.18+php7安裝流程

  1. apache 2.4.18

先安裝apr,apr-util,和pcre

# tar xvf apr-1.5.2.tar.gz

# cd apr-1.5.2

# ./configure --prefix=/usr/local/apr && make && make install


2、安裝apr-util

# tar xvf apr-util-1.5.4.tar.bz2

# cdapr-util-1.5.4

# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr && make && make install


3、安裝pcre

# tar xvf pcre-8.37.tar.bz2

# cd pcre-8.37

# ./configure --prefix=/usr/local/pcre && make && make install


4.安裝httpd

./configure\
--prefix=/usr/local/apache\
--enable-so\
--enable-ssl\
--enable-cgi\
--with-rewrite\
--with-zlib\
--with-pcre=/usr/local/pcre\
--with-apr=/usr/local/apr\
--with-apr-util=/usr/local/apr-util\
--enable-mpms-shared=all\
--with-mpm=prefork\
--enable-proxy\
--enable-proxy-http\
--enable-proxy-ajp\
--enable-proxy-balancer\
--enable-lbmethod-heartbeat\
--enable-heartbeat\
--enable-slotmem-shm\
--enable-slotmem-plain\
--enable-watchdog


上面比較重要的就是指定 幾個路徑,apr,apr-util,pcre

另外一個是,--with-mpm=prefork 以及--enable-so


5、新增PATH環境變數

# cat /etc/profile.d/apache.sh

# export PATH=$PATH:/usr/local/apache/bin

# . /etc/profile.d/apache.sh


6、編輯配置httpd.conf配置檔案



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

#取消註釋,否則啟動會報下面的錯誤

LoadModule slotmem_shm_module modules/mod_slotmem_shm.so


error:

tailf /usr/local/apache/logs/error_log

[Thu Feb 04 10:36:40.825258 2016] [proxy_balancer:emerg] [pid 61695:tid 139808143390464] AH01177: Failed to lookup provider 'shm' for 'slotmem': is mod_slotmem_shm loaded??

[Thu Feb 04 10:36:40.825457 2016] [:emerg] [pid 61695:tid 139808143390464] AH00020: Configuration Failed, exiting


7、編寫啟動指令碼,方便開機自啟動

#!/bin/bash
#
#httpdStartupscriptfortheApacheHTTPServer
#
#chkconfig:-8515
#description:ApacheisaWorldWideWebserver.Itisusedtoserve\
#HTMLfilesandCGI.
#processname:httpd
#config:/etc/httpd/conf/httpd.conf
#config:/etc/sysconfig/httpd
#pidfile:/var/run/httpd.pid
#Sourcefunctionlibrary.
./etc/rc.d/init.d/functions
if[-f/etc/sysconfig/httpd];then
./etc/sysconfig/httpd
fi
#StarthttpdintheClocalebydefault.
HTTPD_LANG=${HTTPD_LANG-"C"}
#Thiswillpreventinitlogfromswallowingupapass-phrasepromptif
#mod_sslneedsapass-phrasefromtheuser.
INITLOG_ARGS=""
#SetHTTPD=/usr/sbin/httpd.workerin/etc/sysconfig/httpdtouseaserver
#withthethread-based"worker"MPM;BEWARNEDthatsomemodulesmaynot
#workcorrectlywithathread-basedMPM;notablyPHPwillrefusetostart.
#Pathtotheapachectlscript,serverbinary,andshort-formformessages.
apachectl=/usr/local/apache/bin/apachectl
httpd=${HTTPD-/usr/local/apache/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/var/run/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0
start(){
echo-n$"Starting$prog:"
LANG=$HTTPD_LANGdaemon--pidfile=${pidfile}$httpd$OPTIONS
RETVAL=$?
echo
[$RETVAL=0]&&touch${lockfile}
return$RETVAL
}
stop(){
echo-n$"Stopping$prog:"
killproc-p${pidfile}-d10$httpd
RETVAL=$?
echo
[$RETVAL=0]&&rm-f${lockfile}${pidfile}
}
reload(){
echo-n$"Reloading$prog:"
if!LANG=$HTTPD_LANG$httpd$OPTIONS-t>&/dev/null;then
RETVAL=$?
echo$"notreloadingduetoconfigurationsyntaxerror"
failure$"notreloading$httpdduetoconfigurationsyntaxerror"
else
killproc-p${pidfile}$httpd-HUP
RETVAL=$?
fi
echo
}
#Seehowwewerecalled.
case"$1"in
start)
start
;;
stop)
stop
;;
status)
status-p${pidfile}$httpd
RETVAL=$?
;;
restart)
stop
start
;;
condrestart)
if[-f${pidfile}];then
stop
start
fi
;;
reload)
reload
;;
graceful|help|configtest|fullstatus)
$apachectl[email protected]
RETVAL=$?
;;
*)
echo$"Usage:$prog{start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
exit1
esac
exit$RETVAL

重要的是指定這幾個檔案的路徑就OK了,一定要是你安裝的路徑:

apachectl=/usr/local/apache/bin/apachectl
httpd=${HTTPD-/usr/local/apache/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/var/run/httpd.pid}


8.httpd.pid檔案

因為自啟動指令碼中httpd的pid配置在/var/run/httpd.pid下面,所以還需要修改httpd.conf的配置檔案

vim /usr/local/apache/conf/httpd.conf


PidFile "/var/run/httpd.pid"


加完以後,在/var/run/httpd.pid建立一個這個檔案,設定好讀寫許可權。


然後重啟pc,因為偶爾會有不重啟,無法用service httpd stop關閉httpd程序。

重啟一下就OK了。

httpd到這裡結束了

記得檢查httpd.conf裡是否有這行:

LoadModulephp7_modulemodules/libphp7.so

=====================================================================


PHP 7的安裝:

  1. 安裝openssl元件,否則會報 ssl too old故障

yum -y openssl-devel

2.安裝其他必須元件

yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel


3.編譯

./configure\
--prefix=/usr/local/php7\
--with-config-file-path=/usr/local/php7/etc\
--with-config-file-scan-dir=/usr/local/php7/etc/php.d\
--with-apxs2=/usr/local/apache/bin/apxs\
--with-mcrypt=/usr/include\
--enable-mysqlnd\
--with-mysqli\
--with-pdo-mysql\
--enable-fpm\
--with-gd\
--with-iconv\
--with-zlib\
--enable-xml\
--enable-shmop\
--enable-sysvsem\
--enable-inline-optimization\
--enable-mbregex\
--enable-exif\
--enable-mbstring\
--enable-ftp\
--enable-gd-native-ttf\
--with-openssl\
--enable-pcntl\
--enable-sockets\
--with-xmlrpc\
--enable-zip\
--enable-soap\
--without-pear\
--with-gettext\
--enable-session\
--with-curl\
--with-jpeg-dir\
--with-freetype-dir\
--enable-opcache\
--disable-fileinfo


比較重要的有這幾個:

(1):必須加,記得檢查/usr/local/apache/bin/有apxs這個檔案

--with-apxs2=/usr/local/apache/bin/apxs\

(2):這幾個根據程式設計師具體需求加上

--enable-exif\
--enable-mbstring\
--with-gd\


然後就是

make && make install了


4.配置檔案

進入php原始碼的解壓包:

wKioL1csa7yRypAAAABLq3hsUCY926.png

cpphp.ini-production/usr/local/php7/etc/php.ini#在原始檔目錄下
cpsapi/fpm/init.d.php-fpm/etc/init.d/php-fpm   #在原始檔目錄下
cp/usr/local/php7/etc/php-fpm.conf.default/usr/local/php7/etc/php-fpm.conf
cp/usr/local/php7/etc/php-fpm.d/www.conf.default/usr/local/php7/etc/php-fpm.d/www.conf


5.新增系統變數:


echo -e '\nexport PATH=/usr/local/php7/bin:/usr/local/php7/sbin:$PATH\n' >> /etc/profile && source /etc/profile


設定PHP日誌目錄和php-fpm程序檔案(php-fpm.sock)目錄:

mkdir -p /var/log/php-fpm/ && mkdir -p /var/run/php-fpm && cd /var/run/ && chown -R nginx:nginx php-fpm

mkdir -p /var/lib/php/session

chown -R nginx:nginx /var/lib/php


6.設定開機啟動

chmod +x /etc/init.d/php-fpm

chkconfig --add php-fpm

chkconfig php-fpm on


7.啟動服務

service php-fpm start


netstat -tlunp看80和9000埠是否開開了。


=================================

整合PHP7和apache


在/usr/local/apache/conf/httpd.conf末尾加上兩行:

AddType application/x-httpd-php .php

PHPIniDir "/usr/local/php7/"


在此處後加上index.php索引檔案:

wKioL1csbQGwSxybAAAnDsDVxqM800.png



重啟一下apache就OK了。


轉載於:https://blog.51cto.com/duanyexuanmu/1770839