Jelkner's
Weblog


About me

Blog Posts Blog Tags Blog Feed

2023 2022 2021 2020 2019 2018 2017

Log in

Copyright © 2022
Jeffrey Elkner

Getting Started with PHP


PHP Logo

Now that NOVA Web Development has made the decision to focus on CiviCRM support, I have been forced to deal confront the question of whether I should be teaching PHP to students in my web design and development classes instead of Python. I have been an active participant in the Python community since 1999, and I am very fond of both the language and the community around it, so it is with some reluctance that I make this decision.

That said, there is nothing in the free software Python space that comes anywhere close to CiviCRM in terms of both features and community support. CiviCRM is the only thing that makes sense if we want to be able to compete using free software with things like Action Network and NationBuilder. Once the decision to support CiviCRM is made, one is lead through Drupal straight to PHP. So it's on to CiviCRM, Drupal, and PHP.

Tasks

  1. Install PHP on our student web server and learn how to enable PHP support on an individual student bases.
  2. Create a virtual machine with CiviCRM (and of necessity, Drupal) to use as a learning platform.

I'll begin with the first of these two tasks here. To create a KVM instance with Ubuntu 17.04 ready for PHP development, I:

  1. Used an ubuntu 17.04 net install image and selected only standard system utilities, OpenSSH server, and Basic Ubuntu server from the Software selection screen.
  2. I ran $ sudo apt install php, which in addition to installing the current version of PHP (7.0), also installed the apache2 web server and the libapache2-mod-php package.

That was all there was to it! Pointing my web browser at the virtual machine's IP address, I was greated with the familiar default ubuntu apache web page.

Next I added a file named info.php to the /var/www/html directory containing:

<?php
    phpinfo();
?>

After that, I pointed my hosts browser at the IP address of the virtual machine with /info.php appended, and was greeted with the PHP info page.

Activating User's public_html Directories

Next I want to enable both web (HTML) and PHP. Web should be enabled by default for all users, while PHP, being more of a security risk, should be enabled explicitly on a per user basis.

To enable users to serve websites from a public_html directory in their home directories, run:

$ sudo a2enmod userdir
$ sudo systemctl restart apache2

To enable PHP in these public_html directories on a per user basis, create a php-in-homedirs.conf file in the /etc/apache2/conf-available directory with the following:

<IfModule mod_userdir.c>
    <Directory /home/[USERNAME_1]/public_html>
        php_admin_value engine On
    </Directory>
</IfModule>
...
<IfModule mod_userdir.c>
    <Directory /home/[USERNAME_N]/public_html>
        php_admin_value engine On
    </Directory>
</IfModule>

where each [USERNAME_X] is replaced by the home directory of an actual user for whom you want to enable PHP.

Then run:

$ sudo a2enconf php-in-homedirs
$ sudo systemctl reload apache2