Python, Apache · 2 min read · Nov 12, 2025

Apache2에 Python 임베딩하기 mod_python (Debian/Ubuntu, Fedora/CentOS, Mandriva, OpenSUSE) - 2페이지

4 Mandriva 2008 Spring (2008.1)

4.1 mod_python 설치하기

mod_python을 설치하기 전에 main, main_updates, contrib, contrib_updates 저장소를 활성화해야 합니다. http://easyurpmi.zarb.org/로 가세요 - 이곳에서 이러한 저장소를 활성화하기 위해 실행해야 할 명령어를 제공받을 수 있습니다. 제 경우에는 다음과 같이 실행했습니다.

urpmi.addmedia contrib ftp://distrib-coffee.ipsl.jussieu.fr/pub/linux/MandrivaLinux/official/2008.1/i586/media/contrib/release with media_info/hdlist.cz
urpmi.addmedia --update contrib_updates ftp://distrib-coffee.ipsl.jussieu.fr/pub/linux/MandrivaLinux/official/2008.1/i586/media/contrib/updates with media_info/hdlist.cz
urpmi.addmedia main ftp://distrib-coffee.ipsl.jussieu.fr/pub/linux/MandrivaLinux/official/2008.1/i586/media/main/release with media_info/hdlist.cz
urpmi.addmedia --update main_updates ftp://distrib-coffee.ipsl.jussieu.fr/pub/linux/MandrivaLinux/official/2008.1/i586/media/main/updates with media_info/hdlist.cz

이렇게 저장소를 활성화합니다.

mod_python을 설치하려면 다음과 같이 실행합니다:

urpmi apache-mod_python

4.2 Apache 구성하기

이제 Apache가 Python 파일을 처리할 수 있도록 구성해야 합니다. 이를 위한 두 가지 방법이 있습니다. 첫 번째(기본) 방법은 Publisher Handler를 사용하는 것입니다. 이 방법은 .py 확장자를 가진 순수 Python 스크립트를 작성할 수 있게 해주며, Apache에 의해 해석됩니다. 두 번째 방법은 PSP Handler입니다. PSP는 Python Server Pages의 약자입니다. 이는 HTML 코드에 Python 코드를 직접 임베드할 수 있게 해주며, PHP와 유사합니다. PSP 파일은 .psp 확장자를 가집니다.

4.2.1 Publisher Handler

Publisher Handler를 활성화하려면 /etc/httpd/modules.d/16_mod_python.conf에서 mod_python 구성을 편집해야 합니다. 이 파일에는 많은 예제가 포함되어 있습니다 - 우리는 이 파일의 백업을 만들고 처음부터 다시 생성합니다. 여기서 지시문에 기본 Mandriva 문서 루트인 /var/www/html을 사용하고 있습니다 - 필요에 맞게 조정하세요. 중요한 줄은 AddHandler mod_python .py와 PythonHandler mod_python.publisher입니다:

cp /etc/httpd/modules.d/16_mod_python.conf /etc/httpd/modules.d/16_mod_python.conf_orig  
cat /dev/null > /etc/httpd/modules.d/16_mod_python.conf  
vi /etc/httpd/modules.d/16_mod_python.conf

| LoadModule python_module extramodules/mod_python.so Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all AddHandler mod_python .py PythonHandler mod_python.publisher PythonDebug On |

주의: 서버에서 ISPConfig(버전 2.2.24 이상)를 사용하는 경우, 위 파일에서 부분을 생략하세요. 이는 해당 디렉토리에 대해 mod_python을 전역적으로 활성화하게 됩니다. ISPConfig에서는 웹사이트별로 mod_python을 활성화할 수 있어, 웹사이트가 mod_python을 사용할 수 있는지에 대한 더 많은 제어를 제공합니다.

그 후 Apache를 재시작합니다:

/etc/init.d/httpd restart

이제 순수 Python 코드가 포함된 작은 Python 테스트 스크립트(예: /var/www/html/test.py)를 생성합니다…

vi /var/www/html/test.py

| def index(req): return "Test successful"; |

… 그리고 브라우저에서 호출합니다(예: http://192.168.0.100/test.py). 모든 것이 잘 진행되면 브라우저에 Test successful이 표시되어야 합니다.

4.2.2 PSP Handler

PSP Handler를 활성화하려면 /etc/httpd/modules.d/16_mod_python.conf에서 mod_python 구성을 편집해야 합니다. 이 파일에는 많은 예제가 포함되어 있습니다 - 우리는 이 파일의 백업을 만들고 처음부터 다시 생성합니다. 여기서 지시문에 기본 Mandriva 문서 루트인 /var/www/html을 사용하고 있습니다 - 필요에 맞게 조정하세요. 중요한 줄은 AddHandler mod_python .psp와 PythonHandler mod_python.psp입니다:

cp /etc/httpd/modules.d/16_mod_python.conf /etc/httpd/modules.d/16_mod_python.conf_orig  
cat /dev/null > /etc/httpd/modules.d/16_mod_python.conf  
vi /etc/httpd/modules.d/16_mod_python.conf

| LoadModule python_module extramodules/mod_python.so Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all AddHandler mod_python .psp PythonHandler mod_python.psp PythonDebug On |

주의: 서버에서 ISPConfig(버전 2.2.24 이상)를 사용하는 경우, 위 파일에서 부분을 생략하세요. 이는 해당 디렉토리에 대해 mod_python을 전역적으로 활성화하게 됩니다. ISPConfig에서는 웹사이트별로 mod_python을 활성화할 수 있어, 웹사이트가 mod_python을 사용할 수 있는지에 대한 더 많은 제어를 제공합니다. 또한 ISPConfig는 PSP Handler를 지원하지 않으며, Publisher Handler를 사용합니다.

그 후 Apache를 재시작합니다:

/etc/init.d/httpd restart

이제 HTML과 Python 코드가 포함된 작은 PSP 테스트 스크립트(예: /var/www/html/test.psp)를 생성합니다…

vi /var/www/html/test.psp

|

<% req.write("Hello!") %>

|

… 그리고 브라우저에서 호출합니다(예: http://192.168.0.100/test.psp). 모든 것이 잘 진행되면 브라우저에 Hello!가 표시되어야 합니다.

Share: X/Twitter LinkedIn

새 게시물을 받은 편지함에서 받기

스팸은 없습니다. 언제든지 구독 해지 가능합니다.