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


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