PHP Application Deployment on Apache: Essentials Quiz Quiz

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.

  1. Setting Up Document Root

    Which Apache directive specifies the directory from which PHP files will be served to users, commonly set to 'public_html' or 'www'?

    1. Listen
    2. DirectoryIndex
    3. ServerAlias
    4. DocumentRoot

    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.

  2. Testing PHP Processing

    When deploying a PHP application, how can you verify that Apache is correctly processing PHP files?

    1. Restart your computer
    2. Upload and visit a simple PHP file with phpinfo()
    3. Check the error_log for HTML errors
    4. Open the server with a text editor

    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.

  3. File Permissions for Security

    What is the recommended permission setting for PHP files to enhance security on a production Apache server?

    1. 400
    2. 644
    3. 777
    4. 600

    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.

  4. Configuring Default Page

    Which Apache directive determines which file is loaded by default when a directory is accessed, such as 'index.php'?

    1. Options
    2. DirectoryIndex
    3. AllowOverride
    4. Require

    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.

  5. Enabling .htaccess

    Which value must the AllowOverride directive be set to in order for .htaccess files to affect Apache configuration?

    1. Root
    2. None
    3. All
    4. Off

    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.

  6. Enabling PHP Module

    Which Apache configuration snippet is commonly required to process PHP files after installing PHP support?

    1. Alias /php /var/www/php
    2. ScriptAlias /php /usr/lib/cgi-bin/php
    3. AddType application/x-httpd-php .php
    4. ProxyPass /php http://localhost/php

    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.

  7. Uploading Application Files

    What is the most common method for uploading your PHP files to a remote Apache server?

    1. Uploading using Bluetooth
    2. Using FTP or SFTP clients
    3. Saving files to a USB stick and inserting it into the server
    4. Editing files directly in the browser

    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.

  8. Configuring Virtual Hosts

    When hosting multiple PHP applications on the same Apache server, which feature allows you to define separate domain or subdomain configurations?

    1. Virtual Host
    2. Server Token
    3. Rewrite Engine
    4. LogLevel

    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.

  9. Securing Sensitive Files

    Which of the following .htaccess rules prevents direct browser access to '.env' or other sensitive PHP configuration files?

    1. Deny from all
    2. Allow from all
    3. RewriteBase /
    4. Redirect 301 / /index.php

    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.

  10. Updating Apache After Changes

    What command must you execute after modifying the main Apache configuration file to apply your changes?

    1. Run a virus scan
    2. Restart or reload the Apache service
    3. Clear the browser cache
    4. Uninstall and reinstall PHP

    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.