linux 下搭建两个虚拟主机,但是总是显示第一个

今天在测试环境把LAMP(Linxu+Apache+Mysql+PHP/Python/Perl)架构搭建起来以后,出现了两个问题

1,php链接mysql出错,结果是没有加载对应的mysql模块

2,创建了两个虚拟机,访问的时候却始终只会访问其中一个默认的(我看了下是按我配置文件名排序的第一个文件创建的虚拟机)


解决方法

1,在php的文件 /etc/php.ini 当中有个配置参数 extension_dir ,默认是注销的,我看了下我本地对应的mysql模块是存在,有 mysql.so 文件。

此时可以执行 php -m 去查看对应的模块是否加载ok了,

[root@colinspace etc]# php -m

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php/modules/mysql.so' - /usr/lib/php/modules/mysql.so: cannot open shared object file: No such file or directory in Unknown on line 0

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php/modules/mysqli.so' - /usr/lib/php/modules/mysqli.so: cannot open shared object file: No such file or directory in Unknown on line 0

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php/modules/pdo.so' - /usr/lib/php/modules/pdo.so: cannot open shared object file: No such file or directory in Unknown on line 0

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php/modules/pdo_mysql.so' - /usr/lib/php/modules/pdo_mysql.so: cannot open shared object file: No such file or directory in Unknown on line 0

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php/modules/pdo_sqlite.so' - /usr/lib/php/modules/pdo_sqlite.so: cannot open shared object file: No such file or directory in Unknown on line 0

[PHP Modules]

bz2

calendar

Core

ctype

date

ereg

exif

filter

ftp

gettext

gmp

hash

iconv

libxml

openssl

pcntl

pcre

readline

Reflection

session

shmop

SimpleXML

sockets

SPL

standard

tokenizer

xml

zlib


[Zend Modules]

这里可以发现问题所在,所以修改extension_dir参数为 “extension_dir = "/usr/lib64/php/modules/" ”

再次执行php -m 不会又任何warning信息,此时会正常显示全部已经加载的模块,

经过测试之后php链接mysql ok


2,两个虚拟主机访问都指向了同一个默认的主机,却没有报错,后来httpd -S 去check看配置文件是否有错,显示

[root@colinspace etc]# httpd -S

httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

[Sat Mar 08 20:08:14 2014] [warn] _default_ VirtualHost overlap on port 80, the first has precedence

VirtualHost configuration:

wildcard NameVirtualHosts and _default_ servers:

*:80                   bbs.example.com (/etc/httpd/conf.d/bbs.conf:1)

*:80                   blog.example.com (/etc/httpd/conf.d/blog.conf:1)

Syntax OK

虽然语法正确,但是有个warn显示: _default_ VirtualHost overlap on port 80, the first has precedence

原来是我的主配置文件里面的 #NameVirtualHost *:80 是注销的,所以当第二个虚拟主机访问的时候会访问第一个默认的,

去掉这个参数前面的注销符,然后重启apache service之后在check,就ok了

[root@colinspace etc]# /etc/init.d/httpd restart

Stopping httpd: [  OK  ]

Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

[  OK  ]

[root@colinspace etc]# httpd -S

httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName



VirtualHost configuration:

wildcard NameVirtualHosts and _default_ servers:

*:80                   is a NameVirtualHost

        default server bbs.example.com (/etc/httpd/conf.d/bbs.conf:1)

        port 80 namevhost bbs.example.com (/etc/httpd/conf.d/bbs.conf:1)

        port 80 namevhost blog.example.com (/etc/httpd/conf.d/blog.conf:1)

Syntax OK

[root@colinspace etc]#



再次页面访问测试,一切OK


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章