How to Install PHP for Displaying PHP Webpage in Apache Webserver on Linux Ubuntu 19.10 Operating System

Posted on

This is another article displaying on how to install PHP so that Apache Webserver can process and display a webpage written in PHP programming language. Furthermore, the Apache Webserver mentioned exist in a Linux Ubuntu operating system. In this context, it is a Linux Ubuntu 19.10 operating system. But before installing a PHP programming language or PHP module in Apache Webserver, it is obvious that the most important step is installing the Apache Webserver. For more information about the Apache Webserver’s installation process, it exist in this link. The following is the step for achieving the purpose :

1.Execute the following command for installing PHP and the associated PHP module in Apache Webserver :

root@hostname:/var/www/html# apt install php libapache2-mod-php php-mysql
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  libapache2-mod-php7.3 php-common php7.3 php7.3-cli php7.3-common php7.3-json php7.3-mysql php7.3-opcache php7.3-readline
Suggested packages:
  php-pear
The following NEW packages will be installed:
  libapache2-mod-php libapache2-mod-php7.3 php php-common php-mysql php7.3 php7.3-cli php7.3-common php7.3-json php7.3-mysql php7.3-opcache php7.3-readline
0 upgraded, 12 newly installed, 0 to remove and 0 not upgraded.
Need to get 4.048 kB of archives.
After this operation, 18,1 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://xxxxxxxxxxxxxxxxxxxxx/ubuntu eoan/main amd64 php-common all 2:69ubuntu2 [11,8 kB]
Get:2 http://xxxxxxxxxxxxxxxxxxxxx/ubuntu eoan-updates/main amd64 php7.3-common amd64 7.3.11-0ubuntu0.19.10.1 [919 kB]                                                                                     
Get:3 http://xxxxxxxxxxxxxxxxxxxxx/ubuntu eoan-updates/main amd64 php7.3-json amd64 7.3.11-0ubuntu0.19.10.1 [18,9 kB]                                                                                      
Get:4 http://xxxxxxxxxxxxxxxxxxxxx/ubuntu eoan-updates/main amd64 php7.3-opcache amd64 7.3.11-0ubuntu0.19.10.1 [184 kB]                                                                                    
Get:5 http://xxxxxxxxxxxxxxxxxxxxx/ubuntu eoan-updates/main amd64 php7.3-readline amd64 7.3.11-0ubuntu0.19.10.1 [12,3 kB]                                                                                  
Get:6 http://xxxxxxxxxxxxxxxxxxxxx/ubuntu eoan-updates/main amd64 php7.3-cli amd64 7.3.11-0ubuntu0.19.10.1 [1.411 kB]                                                                                      
Get:7 http://xxxxxxxxxxxxxxxxxxxxx/ubuntu eoan-updates/main amd64 libapache2-mod-php7.3 amd64 7.3.11-0ubuntu0.19.10.1 [1.354 kB]                                                                           
Get:8 http://xxxxxxxxxxxxxxxxxxxxx/ubuntu eoan/main amd64 libapache2-mod-php all 2:7.3+69ubuntu2 [2.928 B]                                                                                                 
Get:9 http://xxxxxxxxxxxxxxxxxxxxx/ubuntu eoan-updates/main amd64 php7.3 all 7.3.11-0ubuntu0.19.10.1 [9.240 B]                                                                                             
Get:10 http://xxxxxxxxxxxxxxxxxxxxx/ubuntu eoan/main amd64 php all 2:7.3+69ubuntu2 [2.800 B]                                                                                                               
Get:11 http://xxxxxxxxxxxxxxxxxxxxx/ubuntu eoan-updates/main amd64 php7.3-mysql amd64 7.3.11-0ubuntu0.19.10.1 [119 kB]                                                                                     
Get:12 http://xxxxxxxxxxxxxxxxxxxxx/ubuntu eoan/main amd64 php-mysql all 2:7.3+69ubuntu2 [2.012 B]                                                                                                         
Fetched 4.048 kB in 21s (189 kB/s)                                                                                                                                                                         
Selecting previously unselected package php-common.
(Reading database ... 153834 files and directories currently installed.)
Preparing to unpack .../00-php-common_2%3a69ubuntu2_all.deb ...
Unpacking php-common (2:69ubuntu2) ...
Selecting previously unselected package php7.3-common.
Preparing to unpack .../01-php7.3-common_7.3.11-0ubuntu0.19.10.1_amd64.deb ...
Unpacking php7.3-common (7.3.11-0ubuntu0.19.10.1) ...
Selecting previously unselected package php7.3-json.
Preparing to unpack .../02-php7.3-json_7.3.11-0ubuntu0.19.10.1_amd64.deb ...
Unpacking php7.3-json (7.3.11-0ubuntu0.19.10.1) ...
Selecting previously unselected package php7.3-opcache.
Preparing to unpack .../03-php7.3-opcache_7.3.11-0ubuntu0.19.10.1_amd64.deb ...
Unpacking php7.3-opcache (7.3.11-0ubuntu0.19.10.1) ...
Selecting previously unselected package php7.3-readline.
Preparing to unpack .../04-php7.3-readline_7.3.11-0ubuntu0.19.10.1_amd64.deb ...
Unpacking php7.3-readline (7.3.11-0ubuntu0.19.10.1) ...
Selecting previously unselected package php7.3-cli.
Preparing to unpack .../05-php7.3-cli_7.3.11-0ubuntu0.19.10.1_amd64.deb ...
Unpacking php7.3-cli (7.3.11-0ubuntu0.19.10.1) ...
Selecting previously unselected package libapache2-mod-php7.3.
Preparing to unpack .../06-libapache2-mod-php7.3_7.3.11-0ubuntu0.19.10.1_amd64.deb ...
Unpacking libapache2-mod-php7.3 (7.3.11-0ubuntu0.19.10.1) ...
Selecting previously unselected package libapache2-mod-php.
Preparing to unpack .../07-libapache2-mod-php_2%3a7.3+69ubuntu2_all.deb ...
Unpacking libapache2-mod-php (2:7.3+69ubuntu2) ...
Selecting previously unselected package php7.3.
Preparing to unpack .../08-php7.3_7.3.11-0ubuntu0.19.10.1_all.deb ...
Unpacking php7.3 (7.3.11-0ubuntu0.19.10.1) ...
Selecting previously unselected package php.
Preparing to unpack .../09-php_2%3a7.3+69ubuntu2_all.deb ...
Unpacking php (2:7.3+69ubuntu2) ...
Selecting previously unselected package php7.3-mysql.
Preparing to unpack .../10-php7.3-mysql_7.3.11-0ubuntu0.19.10.1_amd64.deb ...
Unpacking php7.3-mysql (7.3.11-0ubuntu0.19.10.1) ...
Selecting previously unselected package php-mysql.
Preparing to unpack .../11-php-mysql_2%3a7.3+69ubuntu2_all.deb ...
Unpacking php-mysql (2:7.3+69ubuntu2) ...
Setting up php-common (2:69ubuntu2) ...
Created symlink /etc/systemd/system/timers.target.wants/phpsessionclean.timer → /lib/systemd/system/phpsessionclean.timer.
Setting up php7.3-common (7.3.11-0ubuntu0.19.10.1) ...
Creating config file /etc/php/7.3/mods-available/calendar.ini with new version
Creating config file /etc/php/7.3/mods-available/ctype.ini with new version
Creating config file /etc/php/7.3/mods-available/exif.ini with new version
Creating config file /etc/php/7.3/mods-available/fileinfo.ini with new version
Creating config file /etc/php/7.3/mods-available/ftp.ini with new version
Creating config file /etc/php/7.3/mods-available/gettext.ini with new version
Creating config file /etc/php/7.3/mods-available/iconv.ini with new version
Creating config file /etc/php/7.3/mods-available/pdo.ini with new version
Creating config file /etc/php/7.3/mods-available/phar.ini with new version
Creating config file /etc/php/7.3/mods-available/posix.ini with new version
Creating config file /etc/php/7.3/mods-available/shmop.ini with new version
Creating config file /etc/php/7.3/mods-available/sockets.ini with new version
Creating config file /etc/php/7.3/mods-available/sysvmsg.ini with new version
Creating config file /etc/php/7.3/mods-available/sysvsem.ini with new version
Creating config file /etc/php/7.3/mods-available/sysvshm.ini with new version
Creating config file /etc/php/7.3/mods-available/tokenizer.ini with new version
Setting up php7.3-mysql (7.3.11-0ubuntu0.19.10.1) ...
Creating config file /etc/php/7.3/mods-available/mysqlnd.ini with new version
Creating config file /etc/php/7.3/mods-available/mysqli.ini with new version
Creating config file /etc/php/7.3/mods-available/pdo_mysql.ini with new version
Setting up php7.3-opcache (7.3.11-0ubuntu0.19.10.1) ...
Creating config file /etc/php/7.3/mods-available/opcache.ini with new version
Setting up php-mysql (2:7.3+69ubuntu2) ...
Setting up php7.3-json (7.3.11-0ubuntu0.19.10.1) ...
Creating config file /etc/php/7.3/mods-available/json.ini with new version
Setting up php7.3-readline (7.3.11-0ubuntu0.19.10.1) ...
Creating config file /etc/php/7.3/mods-available/readline.ini with new version
Setting up php7.3-cli (7.3.11-0ubuntu0.19.10.1) ...
update-alternatives: using /usr/bin/php7.3 to provide /usr/bin/php (php) in auto mode
update-alternatives: using /usr/bin/phar7.3 to provide /usr/bin/phar (phar) in auto mode
update-alternatives: using /usr/bin/phar.phar7.3 to provide /usr/bin/phar.phar (phar.phar) in auto mode
Creating config file /etc/php/7.3/cli/php.ini with new version
Setting up libapache2-mod-php7.3 (7.3.11-0ubuntu0.19.10.1) ...
Creating config file /etc/php/7.3/apache2/php.ini with new version
Module mpm_event disabled.
Enabling module mpm_prefork.
apache2_switch_mpm Switch to prefork
apache2_invoke: Enable module php7.3
Setting up libapache2-mod-php (2:7.3+69ubuntu2) ...
Setting up php7.3 (7.3.11-0ubuntu0.19.10.1) ...
Setting up php (2:7.3+69ubuntu2) ...
Processing triggers for man-db (2.8.7-3) ...
root@hostname:/var/www/html# 

2. In order to prove that the Apache Webserver can execute a webpage with a PHP script exist in it, just create a new file containing the following line :

<?php
phpinfo();
?>

Save the file in the root folder or root document of the Apache Webserver. Normally, it exists in ‘/var/www/html’. So, just save it in a file with the name of ‘phpinfo.php’ for an example. So, the full complete file exist in ‘/var/www/htm/phpinfo.php’.

3. Execute the file in a Web Browser application. If the installation of the PHP module is a success in an Apache Webserver, the following page will appear :

4. Last but not least, execute the following command to persist or to auto start the Apache Webserver’s service every time the operating system starts :

root@hostname:~# systemctl enable apache2
Synchronizing state of apache2.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable apache2
root@hostname:~#

Leave a Reply