第17章 PHP动态解析
17.1 PHP数据库的安装
检查apche和数据库的安装情况
检查PHP所需要的lib库(如果没有。可以直接yum)
[root@localhost ~]# rpm -qa zlib libxml libjpcg freetype libpng gd curl libiconv zlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel
libxml2-devel-2.9.1-6.el7_2.3.x86_64
libpng-1.5.13-7.el7_2.x86_64
gd-devel-2.0.35-26.el7.x86_64
zlib-1.2.7-18.el7.x86_64
zlib-devel-1.2.7-18.el7.x86_64
freetype-2.8-14.el7.x86_64
libpng-devel-1.5.13-7.el7_2.x86_64
gd-2.0.35-26.el7.x86_64
curl-7.29.0-54.el7.x86_64
freetype-devel-2.8-14.el7.x86_64
安装库
[root@localhost ~]# yum list|egrep "libconv*"
libconfig.x86_64 1.4.9-5.el7 @base
libconfig-devel.x86_64 1.4.9-5.el7 @base
libconfig.i686 1.4.9-5.el7 base
libconfig-devel.i686 1.4.9-5.el7 base
17.2 PHP安装
上传文件进行解压:进入配置文件进行相应参数的配置:
./configure
--prefix=/application/php7.3.11
--with-apxs2=/usr/bin/apxs
--with-mysql=/application/mysql
--with-xmlrpc
--with-freetype-dir
--with-zlib
--with-openssl
--with-gd
--with-jpeg-dir
--with-png-dir
--with-iconv=/home/girl/tools/libiconv-1.16
--enable-short-tags
--enable-sockets
--enable-zend-multibyte
--enable-soap
--enable-mbstring
--enable-static
--enable-gd-native-ttf
--with-curl
--with-xsl
--enable-ftp
--with-libxml-dir
安装成功
[root@localhost php-7.3.11]# make && make install
检查是否成功
[root@localhost php-7.3.11]# echo $?
0
软链接的创建(去掉版本号)
[root@localhost php-7.3.11]# ln -s /application/php7.3.11/ /application/php
[root@localhost php-7.3.11]# ll /application/php
lrwxrwxrwx. 1 root root 23 10月 31 01:44 /application/php -> /application/php7.3.11/
[root@localhost php-7.3.11]# ll /application/php/
总用量 4
drwxr-xr-x. 2 root root 4096 10月 31 01:36 bin
drwxr-xr-x. 2 root root 22 10月 31 01:36 etc
drwxr-xr-x. 3 root root 16 10月 31 01:36 include
drwxr-xr-x. 3 root root 16 10月 31 01:36 lib
drwxr-xr-x. 3 root root 16 10月 31 01:36 php
drwxr-xr-x. 4 root root 26 10月 31 01:36 var
17.3 PHP排错
问题:
/configure: line 6311: /application/apache/bin/apxs: No such file or direct
解决方法:
#yum install -y perl*
#yum install -y httpd-devel
#find / -name apxs 得到的路径是:/usr/sbin/apxs
于是修改--with-apsx2=/usr/sbin/apxs指定到正确路径
问题:
configure: error: Cannot find OpenSSL's <evp.h>
解决办法: yum install openssl openssl-devel
问题:
configure: error: Please reinstall the iconv library.
解决办法:
安装数据库libiconv
[root@localhost php-7.3.11]# wget https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.16.tar.gz
或者
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
tar xvzf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/home/girl/tools/libiconv-1.14
make && make install
ln -s /home/girl/tools//libiconv-1.14 /home/girl/tools/ libiconv
问题:
./stdio.h:1010:1: 错误:‘gets’未声明(不在函数内)
_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
^
make[2]: *** [progname.o] 错误 1
make[2]: 离开目录“/home/girl/tools/libiconv-1.14/srclib”
make[1]: *** [all] 错误 2
make[1]: 离开目录“/home/girl/tools/libiconv-1.14/srclib”
解决方法:
方法一:删除文件:stdio.in.h文件
_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead"),如下命令:
cd
libiconv-1.14/srclib
sed -i -e '/gets is a security/d' ./stdio.in.h
方法二:将:/stdio.in.h文件中的:
_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets
instead");
改为:
#if defined(GLIBC) && !defined(UCLIBC) && !__GLIBC_PREREQ(2,
16)
_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets
instead");
#endif
- configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
解决方法:
yum -y install libxslt libxslt-devel
17.4实战配置apache整合PHP
进入http的配置文件中,找到如下字段,添加两行代码,目的师能够让apache支持解析php
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
添加完成后
查找到用户daemon。将用户改为自定义用户,目的是提高安全性。
转到文件默认的首页文件
(<IfModule dir_module>
DirectoryIndex index.html),添加一个index.php
比对文件添加了什么