Get rid of PHP
Just a click bite!

For the last five years, I used Lando to manage all my development environments related to PHP. Today, I tried to use PHP directly on my machine without the help of Lando, and it was disastrous every time I ran anything. Sqlite didn’t work. After checking out my versions, I found both 7.4 and 8.1. I decided to clean my machine from any trace of PHP and install only the latest version.
To interpret or run a PHP script, we need PHP runtime, or let’s call it PHP, in our machine. We can use this command to see what we have in our system (at least, I am using Ubuntu and Aptitude to manage my apps).
dpkg -l | grep php

Figure 1 demonstrates the results of my running the above command on my machine. Before running this or deciding to write this article, I ran it once and deleted the PHP version available using the following command.
sudo apt-get purge php7.4
To delete the remaining packages, we can pass the output of dpkg -l | grep php
to sudo apt-get purge
as follow:
sudo apt purge $(dpkg -l | grep php | awk '{print $2}')
You can ask ChatGPT or Bard about the meaning of this command ;). We won't see anything if we run the listing command after this operation.
Get rid of web servers
I want a fresh start (without re-installing my operating system), so we will delete all web servers on our machine.
We first check all the applications or processes using port 80, reserved for these services. We will use Netstat for our checking:
sudo ss -tlnp | grep ':80'
Output:
LISTEN 0 511 0.0.0.0:80 0.0.0.0:* users:(("nginx",pid=2548,fd=6),("nginx",pid=2546,fd=6),("nginx",pid=2544,fd=6),("nginx",pid=2543,fd=6),("nginx",pid=2542,fd=6),("nginx",pid=2541,fd=6),("nginx",pid=2540,fd=6),("nginx",pid=2539,fd=6),("nginx",pid=2538,fd=6))
LISTEN 0 511 [::]:80 [::]:* users:(("nginx",pid=2548,fd=7),("nginx",pid=2546,fd=7),("nginx",pid=2544,fd=7),("nginx",pid=2543,fd=7),("nginx",pid=2542,fd=7),("nginx",pid=2541,fd=7),("nginx",pid=2540,fd=7),("nginx",pid=2539,fd=7),("nginx",pid=2538,fd=7)
With this, we know that Nginx is installed on our machine (believe it or not, I forgot what I had). We could also use other commands to check the services or packages, such as:
systemctl list-units --type=service | grep 'our-service'
dpkg -l | grep 'our-service'
Or check the configuration files of these services if we know them, like in the case of Apache and Nginx:
ls /etc/apache2
ls /etc/nginx
Then, you can remove them by executing these commands
sudo systemctl stop apache2
sudo systemctl disable apache2
sudo apt purge apache2 apache2-utils
sudo apt autoremove
dpkg -l | grep apache2 # to Check whether they are gone!
# If you get results in the previous command.
sudo apt purge $(dpkg -l | grep apache | awk{$2})
Same thing for Nginx. Now, you can follow up with other services related to web development like MySQL, SQLite, Postgres, MongoDB, or whatever. In my case, I don’t have any of these besides MongoDB.
Starting from scratch
Now, we will install the latest version of PHP in our clean environment.
sudo add-apt-repository ppa:ondrej/php
This guy has all the versions of PHP and keeps them up to date in his PPA (Personal Package Archives). Then, the obvious command:
sudo apt install php8.2 -y
I never noticed this, but installing PHP automatically brings some Apache packages.
dpkg -l | grep apache
ii apache2 2.4.52-1ubuntu4.6 amd64 Apache HTTP Server
ii apache2-bin 2.4.52-1ubuntu4.6 amd64 Apache HTTP Server (modules and other binary files)
ii apache2-data 2.4.52-1ubuntu4.6 all Apache HTTP Server (common files)
ii apache2-utils 2.4.52-1ubuntu4.6 amd64 Apache HTTP Server (utility programs for web servers)
ii libapache2-mod-php8.2 8.2.10-1+ubuntu22.04.1+deb.sury.org+2 amd64 server-side, HTML-embedded scripting language (Apache 2 module)
Well, that’s mainly it for this article or short post. Whenever you need a package, use this command:
sudo apt install php8.2-x
With x
being the name of the package.