{"id":2284,"date":"2015-09-11T12:33:18","date_gmt":"2015-09-11T12:33:18","guid":{"rendered":"http:\/\/truelogic.org\/wordpress\/?p=2284"},"modified":"2015-09-13T04:56:38","modified_gmt":"2015-09-13T04:56:38","slug":"writing-php-extensions-part-5-web-enabling-your-extension","status":"publish","type":"post","link":"https:\/\/truelogic.org\/wordpress\/2015\/09\/11\/writing-php-extensions-part-5-web-enabling-your-extension\/","title":{"rendered":"Writing PHP Extensions \u2013 Part 5 Web-enabling your extension"},"content":{"rendered":"<p><strong><a href=\"https:\/\/truelogic.org\/wordpress\/2015\/09\/10\/writing-php-extensions-part-4-function-arguments\/\">See Part 4 Here<\/a><\/strong><\/p>\n<p>So far our helloworld extension works only in the command (CLI) version of PHP. Most people use PHP as a web scripting language. In this article we will see how to make our extension available as a PHP module running under Apache.<\/p>\n<p>The procedure is not complicated. It just requires a little bit of shell scripting to copy files into the right directories.<\/p>\n<h4>STEPS TO TAKE<\/h4>\n<ol>\n<li>First, locate the mods-available folder of your PHP installation. This is most likely<em> \/etc\/php5\/mods-available<\/em><\/li>\n<li>Next we form a symlink of the helloworld.ini file to the php apache conf.d directory where all the registered extensions store their ini files.<\/li>\n<li>We enabled the helloworld extension using <em>php5enmod<\/em> command<\/li>\n<li>Apache is restarted<\/li>\n<\/ol>\n<p>The script to do the above is shown below. Be sure to change the paths as per your installation. Create the script in an editor and save it as <em>webenable<\/em> in the same folder as the rest of the your extension code. Run <em>chmod 775 webenable<\/em> to give yourself executable permissions to this file.<\/p>\n<p>After that run<em> sudo .\/webenable<\/em> to execute the script<\/p>\n<pre>#!\/bin\/bash\r\ncp helloworld.ini \/etc\/php5\/mods-available\r\nln -s \/etc\/php5\/mods-available\/helloworld.ini \/etc\/php5\/apache2\/conf.d\/helloworld.ini\r\nphp5enmod helloworld\r\nservice apache2 restart\r\n<\/pre>\n<p>When you run phpinfo() in your web page, you should see the helloworld module listed :<\/p>\n<p><a href=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2015\/09\/Screenshot-from-2015-09-11-180035.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-medium wp-image-2286\" src=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2015\/09\/Screenshot-from-2015-09-11-180035-620x532.png\" alt=\"Screenshot from 2015-09-11 18:00:35\" width=\"620\" height=\"532\" srcset=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2015\/09\/Screenshot-from-2015-09-11-180035-620x532.png 620w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2015\/09\/Screenshot-from-2015-09-11-180035-300x257.png 300w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2015\/09\/Screenshot-from-2015-09-11-180035.png 698w\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u00a0<\/strong><\/p>\n<h4><a href=\"https:\/\/truelogic.org\/wordpress\/2015\/09\/13\/writing-php-extensions-part-6-adding-a-class-to-your-extension\/\">Next: Part 6 &#8211; Adding A Class to your Extension<\/a><\/h4>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>See Part 4 Here So far our helloworld extension works only in the command (CLI) version of PHP. Most people use PHP as a web <a class=\"mh-excerpt-more\" href=\"https:\/\/truelogic.org\/wordpress\/2015\/09\/11\/writing-php-extensions-part-5-web-enabling-your-extension\/\" title=\"Writing PHP Extensions \u2013 Part 5 Web-enabling your extension\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":2239,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,302,298],"tags":[],"class_list":["post-2284","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-apachephp","category-cc","category-linux"],"_links":{"self":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/2284","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/comments?post=2284"}],"version-history":[{"count":4,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/2284\/revisions"}],"predecessor-version":[{"id":2301,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/2284\/revisions\/2301"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/media\/2239"}],"wp:attachment":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/media?parent=2284"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/categories?post=2284"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/tags?post=2284"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}