DEV Community

Cover image for "P" is for PHP
DaNeil C
DaNeil C

Posted on • Updated on

"P" is for PHP

When I last left off I had just finished the PostgreSQL database install and basic configuration so now it's time for the "P" in the LAMP stack, PHP. The "P" in LAMP technically represents "PHP" (PHP: Hypertext Preprocessor); though like MySQL, PHP has also been substituted for other server-side scripting languages in recent years; such as, Perl, and Python.

[⭕]MySQL PostgreSQL

PHP is an server-side scripting language, and general purpose programming language, that can be deployed on most web servers, works on almost every operating system and platform, and is free to use. It was created in 1994 and in spite of its historical security issues it has been widely ported and remains popular for its ability to efficiency process code and create dynamic web content on/for a web server. 4

When building a dynamic website/application PHP commands are either embedded directly into HTML source code or in external files that are linked to. When a web server gets a request for a PHP file, like index.php, or encounters a link to an external PHP file in an HTML file, like index.html, the web server passes that part of the request to a PHP interpreter. The PHP interpreter will read the file and execute any PHP code it finds. Once done interpreting the file the output of the code will be passed back to the web server which will then send the dynamically created content back to the client/browser that made the original request.

This all means that any PHP code that is run will not be visible to the user making a request but instead will be run by/on the web server and will result in a dynamically created HTML document that will be visible to the user. 3

LAMPhp location

Table Of Contents

Step 1: Installing PHP
Step 2: Testing PHP

Step 1: Installing PHP

  1. To install the PHP module run sudo apt install php libapache2-mod-php php-pgsql.
    • This will install the PHP module with 2 dependencies of the PHP module for Apache and the PHP PostgreSQL connector.
    • sudo apt install is the command to install something on Ubuntu.
    • php is the thing that is being installed.
    • libapache2-mod-php is the apache2 PHP module dependency.
    • php-pgsql is the PostgreSQL module for PHP dependency.
  2. Restart the apache2 service with systemctl restart apache.

{Back to the Table Of Contents}

Step 2: Testing PHP

That's it. There is no configuring PHP. The set up is done but you need to test it to ensure that it is working.

  1. Navigate into the "etcpasswdapp" site folder with cd /var/www/etcpasswdapp/.
  2. Make a new PHP index file with nano index.php.
    • This will also open up the "nano" editor.
  3. Edit the "index.php" file by adding some simple PHP code to the file such as:

    <!DOCTYPE html>
            echo phpinfo();

    or Example PHP page

  4. Save the file and exit the editor.

  5. On the client computer navigate to the address of the PHP file such as "" and notice that there is now the PHP in the page. Below you can see the output of my phpinfo() command from my server computer. phpinfos

  • Notice that I didn't delete my index.html page but instead am able to call the index.php in place of it.

Notice that if you view the "source code" in the browser that you don't see the simple PHP page that I created by instead the dynamically created HTML output of the command in the next picture. Alt Text

{Back to the Table Of Contents}

DONE!! Now that the LAMP stack is installed and has some basic configurations it's time to move to setting up your website. For this I will be setting up the React frontend separate from the Ruby on Rails API backend and setting up their SSL configuration and then hardening the server itself.

[⭕]MySQL PostgreSQL

Happy Hacking
Happy Hacking ^_^



Please Note: that I am still learning and if something that I have stated is incorrect please let me know. I would love to learn more about what I may not understand fully.

Top comments (3)

rsvp profile image
Аqua 🜉іtæ ℠

& after that u can use, e.g., The SplEnum class. do u?

caffiendkitten profile image
DaNeil C

Thanks for asking. No, I am not using it and I have not gotten it to work for me with my current server computer set up.

That being said, I'm no PHP expert but in theory the SplEnum class should be available. SplEnum is part of the Standard PHP Library (SPL) that is available and compiled by default in PHP 5.0.0 and PHP 7 that I set up for this project should be backwards compatible.

The PHP manual on spl-types mentions that the extension is experimental and from what I can tell the SplEnum is part of the PECL extension that is not bundled with PHP and it needs to be installed to use the Spl specific classes.

rsvp profile image
Аqua 🜉іtæ ℠

TQ 4 TQ.:) Thanks 4 reply.This weird word PECL u can find @ 30% of PHP Library Docs (more useful example So PHP want u to learn a little bit of a compiling stuff as well. BTW, nice 2 reach out wonderful self-motivated people.