To set up a development environment on Linux, we need three key components: the Apache web server, a database (MySQL or MariaDB), and the PHP programming language. Below is a guide for installation and proper configuration to ensure everything works together seamlessly.
Basic Installation
- Update the system:
sudo apt update && sudo apt upgrade
- Install the Apache server:
sudo apt install apache2
- Install PHP and the Apache module:
sudo apt install php libapache2-mod-php php-mysql
- Install the MySQL or MariaDB server:
sudo apt install mysql-server sudo apt install mariadb-server
- Secure the database installation:
sudo mysql_secure_installation
You can verify it\'s working by entering http://localhost in your browser.
Configuration for PHPStorm
If you are using PHPStorm, you must set the path to the PHP interpreter. The path in Linux is:
/usr/bin/php
Installing the Latest PHP Version
If you want to use the latest stable version, use the PPA repository:
sudo add-apt-repository ppa:ondrej/php sudo apt update sudo apt install php libapache2-mod-php php-cli php-mysql php-curl php-xml php-mbstring
Note: Replace specific version numbers (like 8.3) with the latest available version in your repository, or simply omit the version number to install the default latest package.
Switching Between PHP Versions
First, set PHP in the terminal (CLI):
sudo update-alternatives --config php sudo update-alternatives --set php /usr/bin/php8.3
Note: Adjust the path (e.g., /usr/bin/php8.3) to match your installed version.
Then, you must also tell Apache which module to use so the website runs on the same version as the terminal:
sudo a2dismod php8.1 # Disable old version (e.g., 8.1) sudo a2enmod php8.3 # Enable new version 8.3 sudo systemctl restart apache2
Note: Replace 8.1 and 8.3 with your actual installed versions.