It looks like you've set up your virtual host and hosts file correctly, but the issue might be related to Apache not interpreting the PHP code and instead serving the index.php file as plain text. This can happen if the PHP module is not enabled in Apache or if the .htaccess file is not being read correctly.
Here are some steps to troubleshoot and resolve the issue:
-
Enable mod_rewrite: Make sure that the
mod_rewritemodule is enabled in Apache. This module is necessary for the.htaccessfile to work properly.You can enable it by running the following command:
sudo a2enmod rewrite -
Restart Apache: After enabling
mod_rewrite, you need to restart Apache for the changes to take effect.sudo systemctl restart apache2 -
Check .htaccess: Ensure that the
.htaccessfile is present in your/var/www/test/publicdirectory and that it is the default one provided by Laravel. If it's missing, you can get a fresh copy from a new Laravel installation or from the Laravel repository. -
Enable PHP module: Make sure that the PHP module is enabled in Apache. You can enable it with the following command:
sudo a2enmod php<version>Replace
<version>with the version of PHP you are using (e.g.,php7.4). -
Check Apache Configuration: Ensure that the
AllowOverridedirective is set toAllwithin your<Directory>block in the virtual host file, which it is as per your provided configuration. This allows.htaccessfiles to override server configuration settings. -
Permissions: You mentioned setting permissions to 775 and 777. While this is okay for a development server, make sure that the owner of the files is the Apache user (usually
www-dataon Ubuntu). You can set the correct ownership with:sudo chown -R www-data:www-data /var/www/test -
Check Apache Error Logs: If none of the above steps work, check the Apache error logs for any specific errors that might be occurring. You can view the error log with:
sudo tail -f /var/log/apache2/error.log -
Ensure PHP is Working: Create a
phpinfo.phpfile in your/var/www/test/publicdirectory with the following content to ensure PHP is working:<?php phpinfo(); ?>Then navigate to
http://test.local/phpinfo.phpin your browser. If PHP is configured correctly, you should see the PHP information page. -
Clear Laravel Cache: Sometimes, Laravel cache can cause issues. Clear the cache by running these commands from your project root:
php artisan config:clear php artisan cache:clear php artisan view:clear php artisan route:clear
After following these steps, try accessing http://test.local again. If the problem persists, please provide any error messages you're seeing in the Apache error log for further assistance.