Israel Science and Technology Directory

InternetApache server

Installing PHP 8.1, Apache2 and Sqlite3 in Linux Mint 20.3 / 21.0

This page is intended for people who want to upgrade to PHP 8.1 with Sqlite3 database in Linux Mint version 20.3 or version 21.

For previous versions of PHP, Apache2 server was installed separately. In PHP 8.1 this is unnecessary, because the installation of PHP 8.1 includes the Apache2 module.

1: Install PHP 8.1

Run the following command in a Terminal window to add the source to your PPA (Personal Package Archive, list of Linux repositories in your computer):

sudo add-apt-repository ppa:ondrej/php -y

Update and upgrade your repositories by running the following commands in a terminal window:

sudo apt update
sudo apt upgrade -y

Install PHP together with the Apache2 module by running the following:

sudo apt install php8.1 libapache2-mod-php8.1

2: Check the list of all PHP modules installed by entering:

php --modules

If the module you need does not appear on the list, install it by entering:

sudo apt install php8.1-module_name

For example, to install the sqlite3 module enter:

sudo apt install php8.1-sqlite3

To install both the mysql and sqlite3 modules enter:

sudo apt install php8.1-{mysql,sqlite3}

3: Define the default location of the website for your Apache2 server

In the Apache server, the default directory of the website is:

/var/www/html

If you wish to change this location, edit the Apache configuration file by calling xed editor in a terminal window.

sudo xed /etc/apache2/sites-available/000-default.conf

Add a hash (#) sign at the beginning of the following line to mark it as a comment:

DocumentRoot /var/www/html

Add the following line after the commented out line:

DocumentRoot /The-location-of-your-website

Save the file and exit.

Edit Apache configuration file:

sudo xed /etc/apache2/apache2.conf

Towards the end of this file there is a series of lines with the following format:

<Directory ...>
.
.
.
</Directory>

To add the location of your website directory, add the following at the end of the list:

<Directory /The-location-of-your-website>
	Options Indexes FollowSymLinks
	AllowOverride None
	Require all granted
</Directory>

# Specify the default file name(s) to load, in the example below "index.htm index.html".  
DirectoryIndex index.htm index.html

To reload these new definitions, stop the server.

sudo service apache2 stop

Restart the server.

sudo service apache2 restart

Finally, open a browser window and call http://localhost/ to see if the website is visible.