Saturday, July 25, 2020

Installing Apache Webserver with PHP scripting, and MySQL and PostgreSQL PHP connection driver under Ubuntu 18.04 LTS (Bionic Beaver)

Clement L. Rasul 1.  Download and install the Apache webserver software

# apt-get install apache2

If there are errors displayed during the installation, issue the update command before repeating the installation command.

# apt-get update --fix-missing
# apt-get install apache2


2.  Download and install the PHP scripting language

# apt-get install php

If there are errors displayed during the installation, issue the update command before repeating the installation command.

# apt-get update --fix-missing
# apt-get install php libapache2-mod-php

3.  Download and install the MySQL database server PHP connection driver.

# apt-get install php-mysql

If there are errors displayed during the installation, issue the update command before repeating the installation command.

# apt-get update --fix-missing
# apt-get install php-mysql


4.  Download and install the PostgreSQL database server PHP connection driver as follows:

# apt-get install php-pgsql

If there are errors displayed during the installation, issue the update command before repeating the installation command.

# apt-get update --fix-missing
# apt-get install php-pgsql



5.  By default, the Apache webserver should be running after installation.  You should restart the Apache webserver in order to load the PHP, MySQL and PostgreSQL support.  Issue the command:

# systemctl restart apache2.service


6. To check if the Apache process is running, issue the command

# ps ax | grep apache2

This should produce a display similar to this if it is running:

23263 ?        Ss     0:00 /usr/sbin/apache2 -k start
23265 ?        S      0:00 /usr/sbin/apache2 -k start
23266 ?        S      0:00 /usr/sbin/apache2 -k start
23267 ?        S      0:00 /usr/sbin/apache2 -k start
23268 ?        S      0:00 /usr/sbin/apache2 -k start
23269 ?        S      0:00 /usr/sbin/apache2 -k start
25621 pts/0    S+     0:00 grep --color=auto apache2

If the apache2 process is not running, the display should just produce this entry:

6433 pts/0    S+     0:00 grep --color=auto apache2

7.  To test if the Apache webserver is running using an Internet browser, type the address where the webserver is running.  On the local machine, the address is 127.0.0.1 (also known as the loopback address).  This should display a page similar to this.


This is the default page of the Apache web server.


8.  To change the default page of the Apache webserver, remove the "index.html" file in the subdirectory "/var/www/html" and create a sample HTML file called "index.html" as follows:

# cd /var/www/html
# rm index.html
# vi index.html


< html >
< head >
< title > My First HTML Page < /title >
< /head >
< body >
Hello World!< /body >
< /html >

My assumption here is, you are familiar with using the vi text editor in Linux.  You may use your own preferred text editor to create the HTML file.  After refreshing your browser, the display should look like this.




9.  To test if the Apache webserver has PHP scripting support, create the following "test.php" file and place it in the subdirectory "/var/www/html".

# cd /var/www/html
# vi test.php

< ?php 
phpinfo();
? >

Type in the address bar of the browser "http://127.0.0.1/test.php", the browser should display a page similar to this.




10.  To know if the MySQL database PHP connection driver is installed, you should see and entry in the PHP test page similar to this:




11.  Likewise, to know if the PostgreSQL database PHP connection driver is installed, you should see an entry in the PHP test page similar to this:



12.  Should there be a need to uninstall the Apache webserver, shut down the running apache2 process first before uninstalling.

# systemctl stop apache2.service
# apt-get remove apache2



No comments: