Writing PHP Extensions – Part 5 Web-enabling your extension

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 scripting language. In this article we will see how to make our extension available as a PHP module running under Apache.

The procedure is not complicated. It just requires a little bit of shell scripting to copy files into the right directories.

STEPS TO TAKE

  1. First, locate the mods-available folder of your PHP installation. This is most likely /etc/php5/mods-available
  2. 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.
  3. We enabled the helloworld extension using php5enmod command
  4. Apache is restarted

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 webenable in the same folder as the rest of the your extension code. Run chmod 775 webenable to give yourself executable permissions to this file.

After that run sudo ./webenable to execute the script

#!/bin/bash
cp helloworld.ini /etc/php5/mods-available
ln -s /etc/php5/mods-available/helloworld.ini /etc/php5/apache2/conf.d/helloworld.ini
php5enmod helloworld
service apache2 restart

When you run phpinfo() in your web page, you should see the helloworld module listed :

Screenshot from 2015-09-11 18:00:35

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Next: Part 6 – Adding A Class to your Extension

 

 

 

2 Trackbacks / Pingbacks

  1. Writing PHP Extensions – Part 4 Function Arguments | Truelogic Blog
  2. Writing PHP Extensions – Part 6 Adding a Class to your Extension | Truelogic Blog

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.