next up previous contents
Next: PHP MySQL 語法 Up: PHP 安裝 Previous: PHP 安裝   Contents

建立使用環境

  1. 遠端登入 kvm8.deyu.wang 虛擬機。
    [root@dyw219 ~]# ssh root@kvm8.deyu.wang
    root@kvm8.deyu.wang's password: 
    Last login: Sat Dec  6 09:45:29 2014 from 192.168.122.1
    [root@kvm8 ~]#
    
  2. 使用 yum 安裝 php,會將其相依套件 httpd,也就是網頁伺服器也裝起來。
    [root@kvm8 ~]# yum install php -y
    Loaded plugins: fastestmirror, refresh-packagekit
    Determining fastest mirrors
    dywang                                                   | 1.9 kB     00:00     
    Setting up Install Process
    Resolving Dependencies
    --> Running transaction check
    
    Dependencies Resolved
    
    ================================================================================
     Package             Arch         Version                    Repository    Size
    ================================================================================
    Installing:
     php                 x86_64       5.4.30-1.el6.remi          dywang       2.7 M
    Installing for dependencies:
     apr                 x86_64       1.3.9-5.el6_2              dywang       123 k
     apr-util            x86_64       1.3.9-3.el6_0.1            dywang        87 k
     apr-util-ldap       x86_64       1.3.9-3.el6_0.1            dywang        15 k
     httpd               x86_64       2.2.15-26.el6              dywang       821 k
     httpd-tools         x86_64       2.2.15-26.el6              dywang        72 k
     mailcap             noarch       2.1.31-2.el6               dywang        27 k
     php-cli             x86_64       5.4.30-1.el6.remi          dywang       2.6 M
     php-common          x86_64       5.4.30-1.el6.remi          dywang       932 k
    
    Transaction Summary
    ================================================================================
    Install       9 Package(s)
    Upgrade       0 Package(s)
    
    ..........
    
    Complete!
    
  3. httpd 的設定檔 /etc/httpd/conf/httpd.conf,預設設定中只要加入你的網頁伺服器網域名稱就可以了。
    [root@kvm8 ~]# vim /etc/httpd/conf/httpd.conf 
    [root@kvm8 ~]# grep kvm8 /etc/httpd/conf/httpd.conf 
    ServerName kvm8.deyu.wang:80
    
  4. 啟動 httpd 服務。
    [root@kvm8 ~]# /etc/init.d/httpd start
    Starting httpd:                                            [  OK  ]
    
  5. 設定開機啟動 httpd 服務。
    [root@kvm8 ~]# chkconfig httpd on
    
  6. 檢查 httpd 開機啟動狀況。
    [root@kvm8 ~]# chkconfig --list httpd
    httpd          	0:off	1:off	2:on	3:on	4:on	5:on	6:off
    
  7. 在此練習中,先不考慮防火牆設定,故先關閉防火牆。
    [root@kvm8 ~]# /etc/init.d/iptables stop
    iptables: Flushing firewall rules:                         [  OK  ]
    iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
    iptables: Unloading modules:                               [  OK  ]
    [root@kvm8 ~]# chkconfig iptables off
    [root@kvm8 ~]# chkconfig --list iptables
    iptables       	0:off	1:off	2:off	3:off	4:off	5:off	6:off
    
  8. 伺服器架設,不可能不使用防火牆。防火牆設定開啟 80 port。
    [root@kvm8 ~]# vim /etc/sysconfig/iptables
    [root@kvm8 ~]# cat /etc/sysconfig/iptables
    # Firewall configuration written by system-config-firewall
    # Manual customization of this file is not recommended.
    *filter
    :INPUT ACCEPT [0:0]
    :FORWARD ACCEPT [0:0]
    :OUTPUT ACCEPT [0:0]
    -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
    -A INPUT -p icmp -j ACCEPT
    -A INPUT -i lo -j ACCEPT
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
    -A INPUT -j REJECT --reject-with icmp-host-prohibited
    -A FORWARD -j REJECT --reject-with icmp-host-prohibited
    COMMIT
    
  9. 防火牆重新啟動,設定開機啟動。 注意:要確定防火牆編輯正確,否則重新啟動後,自己可能被擋在外面,無法連線。
    [root@kvm8 ~]# /etc/init.d/iptables restart
    iptables: Applying firewall rules:                         [  OK  ]
    [root@kvm8 ~]# chkconfig iptables on
    [root@kvm8 ~]# chkconfig --list iptables
    iptables       	0:off	1:off	2:on	3:on	4:on	5:on	6:off
    
  10. 從 deyu.wang 主機必須可以連線 http://kvm8.deyu.wang。



2017-06-01