I am trying to access my project's index.php on the local server, but the code is not running.
The URL I use is:
The browser just displays (also see screenshot):
<?php
echo "working";
?>How can I access my code? Please help me, thanks.
2 Answers
Steps can vary depending on your error. Check the steps below:
Check that PHP is installed. If PHP isn't installed. Steps to install PHP ->
If PHP is installed, but you're still just seeing the raw text/code, it's likely that the module isn't loaded into Apache (assuming you're using Apache). Steps to do this ->
Use the web browser console to check the status being returned when viewing the page. It should return a 200 status. If 500 (syntax/config error), 404 (missing file), etc then troubleshoot accordingly.
Confirm Apache site root location as Apache can be configured to link to non-standard locations. Depending on your Apache version this config file location can change, but you're probably going to need to check the/etc/apache2/sites-enabled/000-default.conf. The option you're looking for is DocumentRoot which is where the site should load in the text.
Check that .htaccess file isn't overriding your install location and setting a new document root. The easiest way to test this is if you have a .htaccess file, temporarily rename it to another name (eg. mv .htaccess .htaccess_temp) which will remove any changes implemented by the .htaccess file.
Restart Apache as changes to config files are not automatically reflected by apache. sudo service apache2 restart
Above step mentioned are perfect. So not repeating the same. if u see that PHP code is coming the main problem is that server is not recognizing the PHP code and throwing output as an plan text. so you need to check that PHP is installed and recognized which are mentioned above. Moreover if you are new to PHP better to install XAMP and use that to code till the time you are familer with the htaccess, config files.