[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.

경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
어린이용이며, 설치가 필요없는 브라우저 게임입니다.
https://s1004games.com

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

 

 

 

 

 

 

 

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
158 [php 응용개발] XE 템플릿 문법 file 졸리운_곰 2025.05.16 90
157 [php] PHP 보안강화 하기 졸리운_곰 2025.04.27 58
156 [php] php 와 javascript 차이 & 상호 간의 호출 방법 file 졸리운_곰 2024.08.13 99
» [php] html 파일안의 php 코드 실행하기 : Apache 2 server on ubuntu can't parse php code inside html file 졸리운_곰 2024.08.13 86
154 [php] 리눅스 (유닉스 ) 계열에서 php로 마이크로소프트 MS SQL 서버 접속 : Microsoft Drivers for PHP for SQL Server의 Linux 및 macOS 설치 자습서 졸리운_곰 2024.08.07 89
153 PHP 실행 지연(delay) 시키기 졸리운_곰 2024.07.07 86
152 [PHP] 문자열 비교하기 - ===, strcmp(), strcasecmp(), strncmp() 졸리운_곰 2024.07.07 117
151 [PHP] 외부 URL의 내용 얻어오기(cURL, file_get_contents) 졸리운_곰 2024.07.07 276
150 [PHP] CURL를 활용하여 POST방식으로 JSON데이터 주고 받기 졸리운_곰 2024.06.21 138
149 [MySQL+PHP] MySQL 접속후 데이터 가져오기 졸리운_곰 2024.04.18 108
148 [php] [xampp] xampp php 버전 폴더 (디렉토리) 별 설정 : Running multiple PHP versions on XAMPP file 졸리운_곰 2024.03.21 1067
147 [php] [PHP] Laravel - PayPal 결제 모듈 연동하기 (2) - 백엔드 처리 file 졸리운_곰 2024.03.17 102
146 [php] [PHP] Laravel - PayPal 결제 모듈 연동하기 (1) file 졸리운_곰 2024.03.17 199
145 [php] PHP - Show JSON array in html table 졸리운_곰 2024.02.18 81
144 [php] php / string을 json으로 변환 한 뒤 값 가져오기 졸리운_곰 2024.02.18 107
143 [php] Low Code Web Content Server: Making Marks on the Digital Shore. An Anecdotal View. : 로우 코드 웹 콘텐츠 서버: 디지털 해안에 흔적을 남기다. 일화적인 견해. file 졸리운_곰 2024.02.18 90
142 [php] [xampp] [php] php의 mail() 함수로 구글 이메일 보내기 / XAMPP 서버 및 aws의 EC2 / php mail function to send Gmail at XAMPP and AWS EC2 not working / Username and Password not accepted. file 졸리운_곰 2023.09.12 154
141 [php] PHP / MariaDB / 데이터베이스 값 가져와서 출력하기 졸리운_곰 2023.06.22 91
140 [php] Start Using HTML5 WebSockets Today With a PHP Server 지금 PHP 서버에서 HTML5 WebSocket 사용 시작 졸리운_곰 2023.05.09 143
139 [php] json_encode 유니코드 한글 깨짐 해결방법 졸리운_곰 2023.02.04 157
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED