Assess your understanding of deploying PHP applications with Apache, covering configuration, directory structure, permissions, and best practices for a secure and efficient setup. Ideal for beginners exploring PHP hosting environments and deployment procedures.
Which Apache directive specifies the directory from which PHP files will be served to users, commonly set to 'public_html' or 'www'?
Explanation: DocumentRoot defines the directory Apache serves files from, making it essential for configuring where PHP applications are hosted. ServerAlias specifies alternative domain names, which does not affect file serving paths. DirectoryIndex determines default files like 'index.php', not the serving directory. Listen specifies which port Apache runs on. Only DocumentRoot sets the content directory.
When deploying a PHP application, how can you verify that Apache is correctly processing PHP files?
Explanation: By uploading and accessing a file containing phpinfo(), you can ensure the PHP interpreter is active through Apache. Looking for HTML errors in logs does not verify PHP processing. Restarting your computer or opening the server in a text editor neither test PHP functionality nor involve Apache or the browser.
What is the recommended permission setting for PHP files to enhance security on a production Apache server?
Explanation: Setting PHP files to 644 allows the owner to read and write, while everyone else can read, reducing risks while allowing web server access. Permissions set to 777 are insecure, granting excessive access. 600 is overly restrictive, potentially blocking the server from reading files. 400 would prevent server processes editing or writing required files. 644 strikes the right balance.
Which Apache directive determines which file is loaded by default when a directory is accessed, such as 'index.php'?
Explanation: DirectoryIndex sets the default file like 'index.php' or 'index.html' served when a user accesses a directory. AllowOverride manages which directives can be overridden in .htaccess. Options controls what features are available in a directory. Require is used for access control. DirectoryIndex specifically relates to default loading files.
Which value must the AllowOverride directive be set to in order for .htaccess files to affect Apache configuration?
Explanation: AllowOverride set to 'All' enables .htaccess files to override server configuration in the specified directory. 'None' disables .htaccess usage. 'Off' is not a valid value for AllowOverride, and 'Root' is not a directive value. Using 'All' gives the necessary permission for .htaccess overrides.
Which Apache configuration snippet is commonly required to process PHP files after installing PHP support?
Explanation: The AddType directive tells Apache to handle .php files with the PHP processor, ensuring proper PHP execution. Alias maps web requests to filesystem locations but does not process file types. ProxyPass is used for reverse proxying, not PHP. ScriptAlias is for CGI scripts, not PHP by default. AddType is standard for enabling PHP parsing.
What is the most common method for uploading your PHP files to a remote Apache server?
Explanation: FTP or SFTP clients provide a reliable and secure way to upload files from local computers to servers. Editing files directly in the browser is not generally supported or secure. Bluetooth is rarely used for web server file transfers. Using USB sticks is inconvenient and not practical for remote servers, making FTP or SFTP the standard.
When hosting multiple PHP applications on the same Apache server, which feature allows you to define separate domain or subdomain configurations?
Explanation: Virtual Host allows Apache to serve different websites or applications from the same server, each with its own domain or subdomain. Rewrite Engine manages URL rewriting but does not handle separate domains. Server Token determines information disclosed about the server. LogLevel configures log verbosity, not hosting structure.
Which of the following .htaccess rules prevents direct browser access to '.env' or other sensitive PHP configuration files?
Explanation: ‘Deny from all’ blocks web access to files or directories specified in .htaccess, protecting sensitive files like '.env'. RewriteBase simply changes the base URL for rewritten requests and does not restrict access. Redirect 301 redirects URLs but does not protect files. Allow from all grants access, the opposite of what's required for security.
What command must you execute after modifying the main Apache configuration file to apply your changes?
Explanation: Restarting or reloading the Apache service applies configuration changes and updates the server's behavior. Clearing the browser cache affects only the user's view, not server configuration. Reinstalling PHP is unnecessary for config updates. Running a virus scan is unrelated to configuration application. Service management is the required step.