Combining Apache, PHP and MySQL creates a simple but popular web development stack called LAMP (Linux, Apache, MySQL, PHP). This open source stack is widely used to build PHP based web applications and websites. In this article, we will discuss the commands used to install LAMP server on Debian 12 Bookworm or 11 Bullseye.
LAMP consists of a Linux operating system running Apache, PHP and MySQL. Apache is a popular open source web server that manages millions of websites to serve content over the internet. It is a highly scalable web server software with support for multiple operating systems such as Linux, Windows and macOS.
Whereas PHP (Hypertext Preprocessor) is not an unknown server-side programming language but is used by most web developers around the world. Often developers used it in combination with a web server like Apache, Nginx and others.
In addition, PHP language applications can interact with various database systems to store data, including MySQL or MariaDB. Well, MySQL is also an open-source relational database management system (RDBMS) that is widely used to store data for web applications, content management systems (CMS), and e-commerce websites.
1. Update Debian 12 or 11 server
The first step you should take on the Debian server or desktop is to make sure the system is up to date. Therefore, on your command terminal, run the given command, which will also update the APT package index cache.
sudo apt update && sudo apt upgrade -y
2. Install Apache web server
Next, we will install the Apache web server packages available for download using the standard Debian 12 and 11 APT package manager.
sudo apt install apache2
3. Start and enable the Apache service
After completing the installation process, we will start the Apache service and also enable it so that it can start automatically whenever our system restarts or in the event of a crash.
sudo systemctl start apache2
sudo systemclt enable apache2
To confirm service status use:
systemctl status apache
4. Install PHP on Debian 12 or 11
The default version of PHP to install on Debian would not be the latest. For example, when I was working on this article, Bookworm version 12 was using PHP 8.2, and for 11 bullseye PHP7.4.
So if you want to use the system’s default PHP versions, all you have to do is run:
sudo apt install php
While common PHP extensions can use:
sudo ap install php-{common,mysql,xml,xmlrpc,curl,gd,imagick,cli,dev,imap,mbstring,opcache,soap,zip,intl}
(optional) Nowif you want that latest available version of PHP if not available on your Debian then use a third party repository called Sury.
Download the GPG key
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
Add the Sury.org repository.
sudo sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
Run the system update
sudo apt update
Next, run the default command we showed at the beginning of this step.
5. Install MySQL/MariaDB server
If you want the complete stack of LAMP servers, you must also install MYSQL or MariaDB. And for this we must run the following command:
For MySQL:
Unfortunately, MySQL is not available by default to be installed from the Debian 11 and 12 repositories, so we need to configure it manually first. See our article: How to install MySQL on Debian 11 or 12.
However, we recommend using MariaDB as it is a fork of MySQL and works just like MySQL.
sudo apt install mariadb-server
Other articles:
0 Comments