Configuring HTTP Support for PHP and web hosting

Source: Internet
Author: User
Tags hosting web hosting

Configuring HTTPD support PHP
    • HTTPD Master configuration file/usr/local/apache2.4/conf/httpd.conf
    • Vim/usr/local/apache2.4/conf/httpd.conf
      修改以下4个地方ServerName  这个打开后开启httpd后没有警告Require all denied   这个修改为Require all granted 防止打开虚拟主机配置文件时403AddType application/x-httpd-php .php 加上这行才可以解析phpDirectoryIndex index.html index.php  添加默认索引页DocumentRoot "/usr/local/apache2.4/htdocs" 这个参数可以定义网站的域名根目录
    • /USR/LOCAL/APACHE2.4/BIN/APACHECTL-T//Test syntax, the configuration needs to be checked before loading
    • /usr/local/apache2.4/bin/apachectl Graceful//reload config file, do not restart service
    • Iptables-i input-p TCP--dport 80-j ACCEPT//Open 80 port
    • NETSTAT-LNTP//View 80 ports
  [[email protected] ~]# netstat-lntpactive Internet connections (only servers) Proto recv-q send-q Local A ddress Foreign Address State pid/program name TCP 0 0 0.0.0.0:22 0.0.0 .0:* LISTEN 1122/sshd TCP 0 0 127.0.0.1:25 0.0.0.0:* LIS         TEN 2094/master tcp6 0 0::: 3306:::* LISTEN 2658/mysqld      TCP6 0 0::: +:::* LISTEN 2387/httpd TCP6 0                  0::: +:::* LISTEN 1122/sshd tcp6 0 0:: 1:25 :::* LISTEN 2094/master  
    • Opening the host IP address on the physical machine browser can be accessed
    • Do not open IP home page troubleshooting ideas
      -Now on the physical machine to see if the IP can ping, Telnet can pass, and then see if there is no open 80 port on the virtual machine
      [[email protected] ~]# iptables -I INPUT -p tcp --dport 80 -j ACCEPT[[email protected] ~]# iptables -nvLChain INPUT (policy ACCEPT 58 packets, 3900 bytes)pkts bytes target     prot opt in     out     source               destination         0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:80
    • Write a Test php,vim/usr/local/apache2.4/htdocs/1.php
[[email protected] ~]# vim /usr/local/apache2.4/htdocs/1.php<?phpphpinfo();?>
  • Open the host IP address/1.php on the physical machine browser, you can open the PHP information page, if you do not support PHP parsing, access to the file will show the source code.
  • Troubleshooting

    • Check if Apache has loaded the PHP module

        [[email protected] ~]#/usr/local/apache2.4/bin/apachectl-mloaded Modules:core_module (Static) So_module (static) Http_module (static) Mpm_event_module (static) Authn_file_module ( Shared) Authn_core_module (shared) authz_host_module (shared) authz_groupfile_module (shared) Authz_user_module ( Shared) Authz_core_module (shared) access_compat_module (shared) auth_basic_module (shared) reqtimeout_module (shared) Filter_module (shared) mime_module (shared) log_config_module (shared) env_module (shared) headers_module (shared) Setenvif_module (shared) version_module (shared) unixd_module (shared) status_module (shared) autoindex_module (shared) Dir_module (shared) alias_module (shared) php7_module (shared)  
    • View PHP Module files
      [[email protected] ~]# ls /usr/local/apache2.4/modules/libphp7.so /usr/local/apache2.4/modules/libphp7.so[[email protected] ~]# ls /usr/local/apache2.4/modules/libphp5.so /usr/local/apache2.4/modules/libphp5.so
    • Check out these four items for Apache configuration file
#LoadModule php5_module        modules/libphp5.soLoadModule php7_module        modules/libphp7.soServerName www.example.com:80    AddType application/x-compress .Z    AddType application/x-gzip .gz .tgz    Addtype application/x-httpd-php .php<Directory />    AllowOverride none    Require all granted</Directory>
    • "/usr/local/apache2.4/bin/apachectl-t" checks the configuration file for syntax errors
      • Configuring PHP7 parsing only needs to replace the PHP module loaded in the configuration file with Php7, the other same
      • Ctrl+r use: Reverse-search and invoke executed commands. (Reverse-i-search).
        How to use: Press CTRL+R after the command line into the "(Reverse-i-search)": "State, and then enter the used parameters, the corresponding command will be displayed directly, enter to execute the command.
Default virtual host for httpd
    • Windows definition Hosts
      • C:\Windows\System32\drivers\etc\hosts
        192.168.21.128 www.abc.com www.123.com
      • Can ping check if it resolves to the IP you need
    • One server can access multiple Web sites, each of which is a virtual host
    • Concept: Domain name (hostname), DNS (domain name resolution System), hosts (domain name resolution for LAN)
    • Any domain name resolves to this machine, the virtual host that can be accessed is the default virtual host
    • Vim/usr/local/apache2/conf/httpd.conf
# Virtual hostsInclude conf/extra/httpd-vhosts.conf打开这个选项,启用虚拟主机配置文件/usr/local/apache2.4/conf/extra/httpd-vhosts.conf
    • Vim/usr/local/apache2.4/conf/extra/httpd-vhosts.conf
  <virtualhost *:80> documentroot "/data/wwwroot/abc.com" ServerName abc.com serveralias www.abc.c Om www.123.com errorlog "logs/abc.com-error_log" Customlog "Logs/abc.com-access_log" common</virtualhost><v Irtualhost *:80> documentroot "/data/wwwroot/111.com" ServerName 111.com serveralias www.example.com errorl OG "logs/111.com-error_log" customlog "Logs/111.com-access_log" COMMON</VIRTUALHOST>  
    • Create a Directory
      [[email protected] ~]# mkdir /data/wwwroot[[email protected] ~]# mkdir /data/wwwroot/abc.com[[email protected] ~]# mkdir /data/wwwroot/111.com
    • Create a index.php file
      [[email protected] ~]# vim /data/wwwroot/abc.com/index.php[[email protected] ~]# vim /data/wwwroot/111.com/index.php<?phpecho "abc.com";
    • /usr/local/apache2/bin/apachectl–t
    • /usr/local/apache2/bin/apachectl Graceful
    • Testing a virtual Host
    • The abc.com here is the default virtual host
Extended
    • All Apache hosts are pointing to the first

Configuring HTTP Support for PHP and web hosting

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.