[php] html 파일안의 php 코드 실행하기 : Apache 2 server on ubuntu can't parse php code inside html file
2024.08.13 02:30
[php] html 파일안의 php 코드 실행하기 :
Apache 2 server on ubuntu can't parse php code inside html file
[Question]
I installed apache2, php5 and the php5 apache module on Ubuntu 13.04.
Php is working on .php files but lines of php code inside html files do not execute.
Googling I found that must add AddHandler... and AddType... lines to httpd.conf but the version installed doesn't have this file or at least can't find it in /etc/apache2/
code example:
<html>
<head></head>
<body>
<?php
phpinfo();
?>
</body>
</html>
[Answer]
Got it to work. my version of apache doesn't have httpd.conf, instead has php5.conf in /etc/apache2/mods-enabled/
editing that file, found this:
<FilesMatch ".+\.ph(p[345]?|t|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch ".+\.phps$">
SetHandler applicatio
....
....
added the lines:
<FilesMatch ".+\.html$">
SetHandler application/x-httpd-php
</FilesMatch>
now php parses the html files and <?php ... ?> code works.
[Other Answer]
You can probably use a .htaccess configuration file for this.
Create a blank text file and name it .htaccess
(If your operating system does not allow file names starting with a dot just name the file temp.htaccess temporarily. After you have uploaded it to your server, rename the file to .htaccess)
Add the following line into the file:
AddType application/x-httpd-php .html .htm
If this does not work, try changing it to:
AddType application/x-httpd-php5 .html .htm
This is assuming that your apache configuration allows for .htaccess files to override the default settings.
[출처] https://stackoverflow.com/questions/17495382/apache-2-server-on-ubuntu-cant-parse-php-code-inside-html-file
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.

