linux中centros6.7安装php5.6,httpd-2.2.19(web产品化)遇到的问题总结
前段时间在公司实习,web系统产品化的过程踩了很多坑,在这边总结一下,由于对linux不是很懂,全是自己一步步一个一个问题解决的
1,查看系统中是否安装apache,php,mysql环境
Apache-2.2.15
Php-5.2.17
Mysql-5.0.67
2,PHP的安装编译
由于thinkPHP5.0要求php版本>=5.4
可以不必卸载平台中的PHP-5.2.17,只需将路径覆盖
安装php5.6.30
将下载好的压缩包通过winSCP移动到/home目录下
# tar zxvf php-5.6.30.tar.gz
# cd php-5.6.30
# ./configure --prefix=/usr/local/php5.6 --with-libxml-dir=/usr/include/libxml2 --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql
产生错误
Error:libxml2库查询不到
查看平台安装的libxml2的安装路径
# find -name ‘*libxml2*’
查找到的文件没有编译文件
下载libxml2-2.7.8.tar.gz的安装包
移动到/home目录下
# tar zxvf libxml2-2.7.8.tar.gz
# cd libxml2-2.7.8
# ./configure
# make
# make install
Libxml2默认安装到.usr/local/include/libxml2目录下
# cd
# cd php-5.6.30
# ./configure --prefix=/usr/local/php5.6 --with-libxml-dir=/usr/include/libxml2 --with-zlib --with-jpeg-dir --with-png-dir --with-iconv --enable-sockets --without-pdo-sqlite --with-gmp --with-openssl --enable-ftp --with-pdo-mysql --enable-wddx --enable-sysvsem --enable-sysvshm --enable-sysvmsg --disable-xmlreader --disable-xmlwriter --disable-dom --with-gd --without-pear --with-bz2 --with-curl --disable-dba --enable-exif --with-gettext --with-kerberos --with-apxs2=/usr/local/apache2/bin/apxs --with-pic --with-mysql=/usr/local/mysql --with-freetype-dir=/usr/local/lib
# make
# make install
有错误提示:
# /usr/bin/ld: cannot find -lz
# collect2: ld returned 1 exit status
# make: *** [sapi/cli/php] 错误 1
Centos6.7.iso挂载
首先要在虚拟机的编辑设置中CD/DVD驱动器选项中勾选设备状态(已连接)
# mkdir media
# mount -t iso9660 /dev/cdrom / media/
# cd media/Package
里面有需要安装的依赖包
安装所需要的依赖包 # rpm -ivh zlib-devel-1.2.3-29.el6.x86_64.rpm # rpm -ivh libjpeg-turbo-devel-1.2.1-3.el6_5.x86_6.rpm # rpm -ivh libpng-devel-1.2.49-1.el6_2.x86_64 # rpm -ivh sqlite-devel-3.6.20-1.el6.x86_64.rpm # rpm -ivh gmp-devel-4.3.1-7.el6_2.2.x86_64.rpm # rpm -ivh ftp-0.17-54.el6.x86_64.rpm # rpm -ivh openssl-devel-1.0.1e-42.el6.x86_64.rpm # rpm -ivh krb5-devel-1.10.3-42.el6.x86_64.rpm # rpm -ivh keyutils-libs-devel-1.4-5.el6.x86_64.rpm # rpm -ivh libcom_err-devel-1.41.12-22.el6.x86_64.rpm # rpm -ivh libselinux-devel-2.0.94-5.8.el6.x86_64.rpm # rpm -ivh libsepol-devel-2.0.41-4.el6.x86_64.rpm # rpm -ivh bzip2-devel-1.0.5-7.el6_0.x86_64.rpm # rpm -ivh libcurl-devel-7.19.7-46.el6.x86_64.rpm # rpm -ivh libidn-devel-1.18-2.el6.x86_64.rpm # rpm -ivh freetype-devel-2.3.11-15.el6_6.1.x86_64.rpm |
3,检测环境安装
我们先在这个var/web/cu 目录下新建一个文件
test.php
<?php $link = mysql_connect('localhost','root','123456'); if($link){ echo 'connect success'; }else{ echo 'connect error'; } mysql_close(); Echo ‘Hello World’; phpInfo(); ?>
然后访问 192.168.228.29/test.php
页面上输出connect success Hello World
php mysql环境安装成功
4安装php_screw 加密库
# tar zvxf php_screw-1.5_modify.tar.gz
# cd php_screw-1.5
# phpize
出错:bash:phpize:command not found
ln -s /找到你的phpize所在路径 /usr/bin/phpize
ln -s /找到你的php-config所在路径 /usr/bin/php-config
ln -s /找到你的php所在路径 /usr/bin/php
# phpize
出错,bash:/usr/bin/phpize:权限不够
# cd usr/bin
# chmod a+x phpize
# cd php_screw-1.5
# phpize
#./configure --with-php-config=/usr/local/php5.6/bin/php-config
# make
出错
/root/php_screw-1.5/php_screw.c: In function ‘zm_startup_php_screw’:/root/php_screw-1.5/php_screw.c:124: error: ‘struct _zend_compiler_globals’ has no member named ‘extended_info’
/root/php_screw-1.5/php_screw.c: In function ‘zm_shutdown_php_screw’:
/root/php_screw-1.5/php_screw.c:133: error: ‘struct _zend_compiler_globals’ has no member named ‘extended_info’
make: *** [php_screw.lo] Error 1
将 124行,133行 的
CG(extended_info) = 1;
修改为:
CG(compiler_options) |= ZEND_COMPILE_EXTENDED_INFO;
# make
(在modules中生成.so文件)
# make clean
# cd tools
# make
加密工具生成,但是phpInfo()输出时,没有提示php_screw()--》enable,
编译出错!
5,将web部署到服务器上
查看 httpd.conf的文档
<VirtualHost *:80>
DocumentRoot /var/web/cu
ServerName *:80
</VirtualHost>
<VirtualHost *:81>
DocumentRoot /var/web/nmu
ServerName *:81
</VirtualHost>
Web文档都放在var/web目录下
Cu的端口是80
Num的端口是81
所以我们可以把E-NVS的端口设置为82
1,在http.conf文档中添加82端口号
Listen 80
Listen 81
Listen 82
ServerName 127.0.0.1
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /var/web/cu
ServerName *:80
</VirtualHost>
<VirtualHost *:81>
DocumentRoot /var/web/nmu
ServerName *:81
</VirtualHost>
<VirtualHost *:82>
DocumentRoot /var/web/e-nvs/trunk/src
ServerName *:82
</VirtualHost>
<Directory "/var/web/cu">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
2,在var/web下新建目录e-nvs
将项目的代码拷贝进来
3,访问82端口时提示
You don't have permission to access / on this server
修改httpd.conf文件
修改:
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
为:(允许指向外部的目录进行访问)
<Directory />
Options Indexes FollowSymLinks
AllowOverride None
</Directory>
<Directory />
Options Indexes FollowSymLinks ExecCGI
AllowOverride None
</Directory>
重新访问82端口,192.168.228.29:82/public。页面显示正常,点击登录,路径不对,显示404.
查看httpd.conf,发现没有rewrite_module模块,所以需要重新安装编译该模块
重新下载一个对应版本的apache(即httpd-2.2.19)
# tar zvxf httpd-2.2.19.tar.gz
# cd httpd-2.2.19
# ./configure --prefix=/usr/local/apache --enable-deflate=shared --enable-headers=shared --enable-info=shared --enable-rewrite=shared --enable-ssl=shared --enable-so
# make
# find -name mod_rewrite.c (httpd-2.2.19/modules/mappers)
# /usr/local/apache2/bin/apxs -c mod_rewrite.c
# /usr/local/apache2/bin/apxs -i -a -n mod_rewrite mod_rewrite.la
此时,在apache2/modules/mod_rewrite.so文件存在
在httpd.conf中LoadModule rewrite_module modules/mod_rewrite.so 该条语句也已经出现
重启apache,出错
httpd: Syntax error on line 72 of /usr/local/apache2/conf/httpd.conf: Can't locate API
module structure `mod_rewrite_module' in file
/usr/local/apache2/modules/mod_rewrite.so: /usr/local/apache2/modules/mod_rewrite.so: undefined symbol: mod_rewrite_module
Httpd.conf中找到那行
需要自己手工修改mod_rewrite_module 为 rewrite_module
再重启apache
点击登录按钮时出错
提示:could not find driver
是php.ini的配置问题
重新编译php,在./configure 中添加 --with-pdo-mysql
同时,在php.ini中找到
extension=php_pdo.dll
extension=php_pdo_firebird.dll
extension=php_pdo_mssql.dll
extension=php_pdo_mysql.dll
将这四行前面的;去掉,在phpInfo中看到pdo-mysql已经被编译进去,在php.ini中添加一行
extension=pdo_mysql.so
重新启动apache,又有新的错误
提示: SQLSTATE[HY000] [2002] Connection timed out
将数据库连接修改成 localhost,登录成功