<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Control WebPanel Wiki &#187; apache run python script</title>
	<atom:link href="https://wiki.centos-webpanel.com/tag/apache-run-python-script/feed" rel="self" type="application/rss+xml" />
	<link>https://wiki.centos-webpanel.com</link>
	<description>CentOS WebPanel Wiki</description>
	<lastBuildDate>Wed, 12 Feb 2025 20:38:16 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.1.1</generator>
	<item>
		<title>Apache run python script</title>
		<link>https://wiki.centos-webpanel.com/apache-run-python-script</link>
		<comments>https://wiki.centos-webpanel.com/apache-run-python-script#comments</comments>
		<pubDate>Thu, 14 Jan 2016 23:13:54 +0000</pubDate>
		<dc:creator><![CDATA[publisher]]></dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[apache run python script]]></category>

		<guid isPermaLink="false">http://wiki.centos-webpanel.com/?p=446</guid>
		<description><![CDATA[Install python &#038; python3 and run python scripts with apache on your CentOS WebPanel server. Install python yum install python Install python3 yum install python3 Check python version python -V Check python3 version python3 -V Create a test script cd /home/USERNAME/public_html mkdir cgi-bin nano cgi-bin/test.py Python2 test script in the file: /home/USERNAME/public_html/cgi-bin/test.py #!/usr/bin/python # enable [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Install python &#038; python3 and run python scripts with apache on your CentOS WebPanel server.</p>
<p><strong>Install python</strong></p>
<pre>yum install python</pre>
<p><strong>Install python3</strong></p>
<pre>yum install python3</pre>
<p><strong>Check python version</strong></p>
<pre>python -V</pre>
<p><strong>Check python3 version</strong></p>
<pre>python3 -V</pre>
<p><strong>Create a test script</strong></p>
<pre>
cd /home/USERNAME/public_html
mkdir cgi-bin
nano cgi-bin/test.py
</pre>
<p>Python2 test script in the file:<br />
<strong>/home/USERNAME/public_html/cgi-bin/test.py</strong></p>
<pre>
#!/usr/bin/python
# enable debugging
import cgitb
cgitb.enable()
print "Content-Type: text/plain\r\n\r\n"
print
print "Hello World!"
</pre>
<p>Python3 test script in the file:<br />
<strong>/home/USERNAME/public_html/cgi-bin/test.py</strong></p>
<pre>
#!/usr/bin/python3
# enable debugging
import cgitb
cgitb.enable()
print ("Content-Type: text/plain\r\n\r\n")
print
print ("Hello World!")
</pre>
<p><strong>Update test.py file and folder cgi-bin permissions</strong></p>
<pre>chown -R USERNAME.USERNAME /home/USERNAME/public_html/cgi-bin
chmod +x /home/USERNAME/public_html/cgi-bin/test.py
</pre>
<p>Now create .htaccess file to handle this script.<br />
Add this test code bellow in your file <strong>/home/USERNAME/public_html/cgi-bin/.htaccess</strong></p>
<pre>
Options +ExecCGI
AddHandler cgi-script .py
</pre>
<div class="st-alert st-alert- "><a href="/how-to-enable-mod_suexec-with-apache" title="How to enable mod_suexec with CentOS WebPanel" target="_blank">Please don't forget to enable mod_suexec for security reasons if you will have with multiple sites.</a>
</div>
<p><strong>Enable CGI</strong><br />
Create File: /usr/local/apache/conf.d/mod_cgid.conf</p>
<pre>LoadModule cgid_module modules/mod_cgid.so

&lt;IfModule cgid_module&gt;
&lt;Directory /home/*/public_html/cgi-bin/&gt;
Options ExecCGI SymLinksifOwnerMatch
SetHandler cgi-script
AddHandler cgi-script .cgi .pl .py
Require all granted
AllowOverride All
&lt;/Directory&gt;
&lt;/IfModule&gt;
</pre>
<p>Now restart apache and you are ready to run your cgi-scripts.</p>
<pre>service httpd restart</pre>
<p>Test if cgid module is now loaded</p>
<pre>/usr/local/apache/bin/httpd -M|grep cgid</pre>
<p><strong>Test if suexec module is now loaded</strong></p>
<pre>/usr/local/apache/bin/httpd -M|grep suexec</pre>
<p>If module is loaded, you should get output containing this: <strong>suexec_module (shared)</strong><br />
<a href="http://wiki.centos-webpanel.com/how-to-enable-mod_suexec-with-apache" title="How to enable mod_suexec with CentOS WebPanel" target="_blank">http://wiki.centos-webpanel.com/how-to-enable-mod_suexec-with-apache</a></p>
<p><em>Running cgi scripts requires some security so don't forget to check this instructions</em><br />
<a href="http://wiki.centos-webpanel.com/how-to-run-cgi-scripts-with-apache" title="How to secure cgi scripts with suexec" target="_blank">http://wiki.centos-webpanel.com/how-to-run-cgi-scripts-with-apache</a></p>
<p><strong>Now you can run your python script by using URL</strong></p>
<pre>http://domain.com/cgi-bin/test.py</pre>
]]></content:encoded>
			<wfw:commentRss>https://wiki.centos-webpanel.com/apache-run-python-script/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
