Configuring HTTPD support PHP
[[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
[[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
- 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