Main Menu

search

You are here

PHP

[last updated: 2023-12-09]
Clients & Webservers
mySQL
PHPmyAdmin
-----

Very rough, random notes ...

  • PHP (Hypertext PreProcessor) is a scripting language especially suited to website work. It is installed with the LAMP installation of mySQL.
  • PHP is primarily used on Server-side (and JavaScript on Client Side) to generate dynamic web pages over HTTP
  • Installed on Dell tower via Software Manager, version: 1:7.2+60ubuntu1
    -----
  • php.ini:
    phpinfo() says:
    "Configuration File (php.ini) Path => /etc/php/7.2/cli"
    looking for lines that would install/load an extension, I see bunches of lines of the form (eg):
      ;extension=bz2
      note there is no .so listed, also note there's no space between ; and ext...

    I'm confused as to whether this is the actual load instruction or just an example
          since the ' ; ' at the start of the line suggests "end of command" meaning what follows is like a comment???
    -----

  • PHP files (programs) are of the form:
    <?php
    [commands/statements];
    ?>
  • comment lines can be entered into php programs by starting with "//"
    alternatively, blocks of lines can be commented with "/*" to start, and "*/" to end.
  • -----

  • PHP Extensions:
    • These are files with a .so extension that give extra features and procedures to PHP
    • Extensions are located in an extension-directory
      $ php-config --extension-dir ... will give location of extension directory
      however if php-config is not installed (and it's not on my tower), install it with:
      $ sudo apt-get install php-config
      However phpinfo() will also give location of extension directory
      and it tells me that mine is at: /usr/lib/php/20170718
        and in that folder there is a gd.so file ...
    • $ php -m | head ... supposedly gives list of installed extensions (modules), however gd is not there
      $ php -m ... gives much longer list, which does include gd ...

    • Add an extension:
      • extensions get loaded in the php.ini file with a line eg.:
        extension=mysql.so
      • So for me to add gd.so (which is now loaded into my extension directory):
        $ sudo nano /etc/php/7.2/cli/php.ini
        and copied existing syntax to add:
        ;extension=gd
      • forum says I now need to stop and restart php ...
        from: (link to:) how-to for extensions
        In case of Apache

        $ /etc/init.d/httpd restart ... this gave error
        $ sudo /etc/init.d/apache2 restart ... this worked

    -----

  • $ php -m | head ... supposedly gives list of installed modules
    $ php -m ... gives a list of lots more modules ...
    -----
  • from: (link to:) tecmint
    to see if you have a working version of PHP installed:
    • create a file: /var/www/html/infophp.php:
      <?php phpinfo(); ?>
    • then execute from terminal with:
      # php -f /var/www/html/infophp.php
    • This command tells me that I do not have PHP installed (2019-12-30)
      but I can install it with:
            $ apt install php7.2-cli
            $ apt install hhvm
    • After installing php, infophp.php worked.
  • Execute PHP files from CLI:
    from: (link to:) tecmint
    # php -f /var/www/html/[fileName].php
  • redirect output to a file:
    • one option: (link to:) codeutopia
    • another (simpler) option:
      • create test1.php:
        <?php echo "some text from php program... "; ?>
      • create test_it.php:
        <?php
        exec ('php test1.php', $output);
        file_put_contents('logFile.txt', $output);
        ?>
      • Then execute in terminal with:
        # php -f /var/www/html/test_it.php
      • However: executing this from browser by entering localhost/test_it.php did Not work...

    -------------------

    The tutorialsPoint tutorial (... link to: ...) describes using php programs to interact with a mysql database.
    They describe embedding the php code into an html file, eg:
    <html>
    <body>
    <?php
    [php commands];
    ?>
    </body>
    </html>

    If this file is saved as testHtm.htm into the /var/www/html directory,
    then it will be executed when you open a browser with the URL: localhost/testHtm.htm

    interesting link: (link to:) connectwww.com
    --------------------------------------------------------------------

  • Links:

    -------------------------------------------------------

.

.

.

eof