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.
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
- 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 installis the command to install something on Ubuntu.
phpis the thing that is being installed.
libapache2-mod-phpis the apache2 PHP module dependency.
php-pgsqlis the PostgreSQL module for PHP dependency.
- Restart the apache2 service with
systemctl restart apache.
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.
- Navigate into the "etcpasswdapp" site folder with
- Make a new PHP index file with
- This will also open up the "nano" editor.
Edit the "index.php" file by adding some simple PHP code to the file such as:
<!DOCTYPE html> <html> <head> <title>Example</title> </head> <body> <?php echo phpinfo(); ?> </body> </html>
Save the file and exit the editor.
On the client computer navigate to the address of the PHP file such as "etcpasswdapp.com/index.php" 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.
- Notice that I didn't delete my
index.htmlpage but instead am able to call the
index.phpin place of it.
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.