Get installed packages

Assuming one needs to setup a LAMP server identically to a existing machine and it is important that all the specific packages are installed in order to guarantee a stable execution of the application. the following command prints out a single line list of installed packages for the provided search terms:

dpkg -l | grep -E 'apache|mysql|php' | awk '{printf "%s ",$2} END {print ""}'

Just change “apache|mysql|php” (RegEx!) with the packages you want to search and you get a list like the following:

apache2 apache2-bin apache2-data apache2-utils libapache2-mod-php libapache2-mod-php7.4 mysql-client-8.0 mysql-client-core-8.0 mysql-common mysql-server mysql-server-8.0 mysql-server-core-8.0 php php-common php-composer-ca-bundle php-composer-semver php-composer-spdx-licenses php-composer-xdebug-handler php-curl php-gd php-imagick php-json-schema php-mbstring php-mysql php-psr-container php-psr-log php-symfony-console php-symfony-dotenv php-symfony-filesystem php-symfony-finder php-symfony-process php-symfony-service-contracts php-xml php-zip php7.4 php7.4-cli php7.4-common php7.4-curl php7.4-gd php7.4-json php7.4-mbstring php7.4-mysql php7.4-opcache php7.4-readline php7.4-xml php7.4-zip python3-certbot-apache

On the target system just type (append the list):

apt install -y apache2 apache2-bin ...

And the same software is installed on the new server.