CentOS下搭建LAMP環境及遇到的問題
一、搭建過程
請參考百度經驗:
二、遇到的問題及解決辦法
2.1 問題一
如果是外網不可以ping能虛擬機器,則說明網路設定有問題,請參考:
在按照百度經驗中第三步,開啟Apache伺服器時,出現下列錯誤:
httpd: Could not reliably determine the server’s fully qualified domain name, using localhost.localdomain for ServerName
2.2 問題一的解決方案:
- 用vim編輯器開啟 httpd.conf
將裡面的 #ServerName localhost:80 註釋去掉即可。
# If your host doesn't have a registered DNS name, enter its IP address here.
# You will have to access it by its address anyway, and this will make
# redirections work in a sensible way.
#
ServerName localhost:80
#
# UseCanonicalName: Determines how Apache constructs self-referencing
# URLs and the SERVER_NAME and SERVER_PORT variables.
# When set "Off", Apache will use the Hostname and Port supplied
# by the client. When set "On", Apache will use the value of the
再重啟 httpd伺服器
service httpd restart
檢視是否存在網路入口檔案
如果存在index.php,或者是以.php檔案結尾的檔案,就可以進入第4步,如果沒有,則需要先建立。
[root@localhost ~]# ls /var/www/html/
index.php phpinfo.php
- 在WEB入口目錄(/var/www/html/)下建立.php檔案
[root@localhost ~]# vi /var/www/html/index.php
<?php
echo "Hello world!";
?>
- 然後可以通過虛擬機器訪問,輸入如下命令即可:
[root@localhost ~]# curl localhost:80
Hello world!
- 檢視IP地址後,可以在本地通過瀏覽器訪問 http://192.168.137.79:80 ,如果頁面顯示 “Hello world!” ,即表示apache已安裝並啟動成功。
如果4和5都不能訪問伺服器,則可以繼續往下看。
2.3 問題二:
主機與虛擬機器互PING成功,但主機無法訪問虛擬機器上啟動的web服務?
問題描述:
- 本機能ping通虛擬機器
- 虛擬機器也能ping通本機
- 虛擬機器能訪問自己的web
- 本機無法訪問虛擬機器的web
後來發現是防火牆將80埠遮蔽了的緣故。
檢查是不是伺服器的80埠被防火牆堵了,可以通過命令:
telnet {伺服器ip}80 來測試。
2.4 問題二的解決方法
將80埠開啟,輸入如下命令:
/sbin/iptables -I INPUT -p tcp –dport 80 -j ACCEPT
然後儲存:
/etc/rc.d/init.d/iptables save
重啟防火牆
/etc/init.d/iptables restart
檢視CentOS防火牆資訊:(可以看到開啟了80埠)
[root@localhost ~]# /etc/init.d/iptables status
表格:filter
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:80
Chain FORWARD (policy ACCEPT)
num target prot opt source destination
Chain OUTPUT (policy ACCEPT)
num target prot opt source destination
- 或者可以直接關閉CentOS的防火牆,關閉其服務即可:
/etc/init.d/iptables stop
永久關閉防火牆:
chkconfig –level 35 iptables off
- 最後,開啟主機瀏覽器,輸入虛擬機器IP地址,就可以訪問虛擬機器的WEB伺服器了!
相關文章
- LAMP(CentOS 7.2)環境下搭建WordPressLAMPCentOS
- 詳解CentOS5.5 下搭建 PHP 環境(最佳的LAMP環境)CentOSPHPLAMP
- Fabric 環境搭建遇到問題及解決
- Linux|UNIX下LAMP環境的搭建及常見問題[連載2]LinuxLAMP
- CentOS 7.3搭建LAMP環境和WordpressCentOSLAMP
- CentOS環境下LAMP開發環境的搭建與配置(10分鐘搞定!!!)CentOSLAMP開發環境
- 【轉】 Windows下LAMP環境搭建WindowsLAMP
- CentOS7.3 編譯搭建 lamp 環境CentOS編譯LAMP
- CentOS7.0 LAMP環境搭建(MariaDB)CentOSLAMP
- Windows 10 下搭建 Homestead 環境 Vagrant up 所遇到的問題及解決Windows
- php環境搭建---LAMPPHPLAMP
- react native搭建環境時遇到的問題React Native
- Linux下原始碼搭建LAMP環境Linux原始碼LAMP
- Centos下搭建golang環境CentOSGolang
- linux搭建lamp環境LinuxLAMP
- Centos7環境下安裝redis及常見的問題CentOSRedis
- Centos下搭建LAMP+PHPCentOSLAMPPHP
- RHEL5.3下搭建LAMP+Django環境(二)LAMPDjango
- LAMP環境搭建-MySQL5.6LAMPMySql
- 搭建TS環境遇到的問題
- Windows 下 Homestead 環境搭建遇到的坑Windows
- Windows10系統下LAMP開發環境的搭建WindowsLAMP開發環境
- CentOS5.5下快速編譯安裝最新的LAMP環境CentOS編譯LAMP
- 如何在CentOS 7上搭建LAMP環境(使用YUM或編譯)CentOSLAMP編譯
- Mac下使用Brew搭建PHP(LNMP/LAMP)開發環境MacPHPLNMPLAMP開發環境
- 關於 dnmp 環境下,laravel 試用 swoole 遇到的問題Laravel
- Vagrant 搭建 CentOS 環境CentOS
- centos 前端環境搭建CentOS前端
- centos搭建virtualenv環境CentOS
- lamp環境搭建與phpwind,wordprss實現LAMPPHP
- centos 7.2 64位 docker安裝lamp環境CentOSDockerLAMP
- FastDFS與Nginx的搭建及遇到的問題ASTNginx
- Centos7下搭建Laravel環境(非docker)CentOSLaravelDocker
- AWD平臺搭建及遇到的問題分析
- 搭建lamp環境以及安裝配置phpmyadminLAMPPHP
- Lamp(linux+apache+mysql+php)環境搭建LAMPLinuxApacheMySqlPHP
- Centos6.5搭建LAMPCentOSLAMP
- Centos7.2搭建LampCentOSLAMP