Issue: PHP Code Not Executing, Visible as HTML in Source Code
When attempting to execute PHP code within a project, it remains inert, showing instead as HTML tags within the browser's source code. Apache is properly operational, the PHP pages display correctly, yet the PHP code remains inactive.
Solution:
Inspect the following configurations:
-
Web Server Access: Ensure that the file is accessed via a web server URL (e.g., http://localhost/file.php), not through local file access (file://localhost/www/file.php).
-
PHP Installation and Operation: Verify that PHP is installed and functioning correctly. Execute "php -v" from the command line to obtain version information or error reports.
-
Apache Configuration (httpd.conf): Uncomment the PHP module's entry (e.g., LoadModule php5_module "c:/php/php5apache2_2.dll").
-
PHP MIME Type: Confirm that Apache's httpd.conf includes the PHP MIME type (e.g., AddType application/x-httpd-php .php). Additionally, ensure that this entry is uncommented.
-
PHP File Extension: Ensure the file has the .php extension or the extension specified in the MIME definition mentioned in point 4.
-
Short Tags: Avoid using short tags () in the PHP file, as they may not be enabled on all servers. Use
For additional guidance, refer to the PHP manual for installation and setup tips.
The above is the detailed content of Why Isn't My PHP Code Executing—Showing as HTML Instead?. For more information, please follow other related articles on the PHP Chinese website!
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn