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
- First, locate the mods-available folder of your PHP installation. This is most likely /etc/php5/mods-available
- 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.
- We enabled the helloworld extension using php5enmod command
- 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 :
Next: Part 6 – Adding A Class to your Extension
Leave a Reply