LAMP is the common software stack used in Linux systems to create a web server along with PHP and MySQL server applications. However, sometimes, especially if someone is a beginner and has done some wrong setting then he or she would want to reinstall the LAMP. However, before that, it is better to completely remove the existing LAMP stack from your Linux systems such as Ubuntu or Debian before installing it again.
To completely uninstall a LAMP (Linux, Apache, MySQL, PHP) server and start fresh, here are the steps you will need to perform on your Linux system. The given steps are performed on Ubuntu or Debian systems.
- First of all, stop the actively running service of the web server that is Apache including database server MySQL or MariaDB, and PHP services on your server by running the following commands:
sudo systemctl stop apache2 sudo systemctl stop mysql sudo systemctl stop php*-fpm
- After stopping the services, uninstall the packages that are used to install Apache, MySQL, and PHP on your system using the default package manager which is APT in Ubuntu.
sudo apt remove apache2 mysql-server php*-fpm
- Even after uninstalling the LAMP server components, their configuration file would leave behind and may cause problems later. Hence to completely clean, also delete any remaining Apache, MySQL, and PHP configuration files and directories. On Ubuntu, these are typically located in the
/etc/php/(version)((version) could be 7.4, 8.1 depending upon your PHP version ) directories. To remove any directory & its content or file from Linux we can use the
rmcommand , like this:
sudo rm -rf /etc/apache2 /etc/mysql /etc/php/*
- Reinstall the Apache, MySQL, and PHP packages (in short LAMP server) on your system using the Linux package manager. For example, on Ubuntu, you can use the
aptcommand like this:
sudo apt install apache2 mysql-server php-fpm
- Configure the Apache, MySQL, and PHP services on your server according to your needs for various PHP-based web applications you want to run on your Linux systems.
Once you have followed the steps given above on your Linux desktop or server, the LAMP server stack will be completely uninstalled from your system and after that, you can start with a fresh configuration. However, the steps are given to perform on Ubuntu or Debian-based systems. Hence will be slightly different for RedHat-based systems.