Files Used in PHP "include" Statements

Provides a tutorial example on how to the PHP engine search for files given in the 'include' statements.

When you use the "include" statement to execute script stored in a separate file, the PHP engine uses the following rules to search and find the script file.

1. If an absolute path is given together with the file name, the PHP engine will search for the file in the directory of the given absolute path only. For example, the following code will search for include_extra.php in /usr/share/php directory only.

<?php
  include "/usr/share/php/include_extra.php";
?>

2. If a relative path is given together with the file name, the PHP engine will search for the file in the directory of the given path relative to the current working directory, which may not be the same as the directory of the calling script is located. For example, the following code will search for include_extra.php in the same directory where the code is executed.

<?php
  include "./include_extra.php";
?>

3. If no path is given together with the file name, the PHP engine will search for the file in the following 3 locations sequentially:

For example, the following code will search for include_extra.php in multiple places.

<?php
  include "include_extra.php";
?>

So the best way to use the "include" statement is to give the file name only and make sure the included files are stored in one of the "include_path" directory.

Table of Contents

 About This Book

 Introduction to Linux Systems

 Cockpit - Web Portal for Administrator

 Process Management

 Files and Directories

 Users and Groups

 File Systems

 Block Devices and Partitions

 LVM (Logical Volume Manager)

 Installing CentOS

 SELinux - Security-Enhanced Linux

 Network Connection on CentOS

 Software Package Manager on CentOS - DNF and YUM

 Running Apache Web Server (httpd) on Linux Systems

Running PHP Scripts on Linux Systems

 Install and Manage PHP Packages on CentOS

 "php -i" - Dump PHP Environment Information

 Install and Manage PHP Modules on CentOS

Files Used in PHP "include" Statements

 Publish PHP Scripts on Apache Web Server

 Dump PHP/Apache Environment Information

 Change PHP Configuration Settings

 Apache PHP file_put_contents() Permission Denied

 SELinux Security Context on /var/www/html

 Migrate Old Scripts to New PHP Release

 Running MySQL Database Server on Linux Systems

 Running Python Scripts on Linux Systems

 vsftpd - Very Secure FTP Daemon

 Postfix - Mail Transport Agent (MTA)

 Dovecot - IMAP and POP3 Server

 Email Client Tools - Mail User Agents (MUA)

 LDAP (Lightweight Directory Access Protocol)

 GCC - C/C++ Compiler

 Graphics Environments on Linux

 Conda - Environment and Package Manager

 Tools and Utilities

 Administrative Tasks

 References

 Full Version in PDF/EPUB