Step-by-Step Guide
Connect to Your EC2 Instance via SSH
Connect to your EC2 instance using SSH. Replace /path/to/your-key.pem with the path to your SSH key, and your-ec2-instance-public-dns with the public DNS of your EC2 instance.
ssh -i /path/to/your-key.pem ubuntu@your-ec2-instance-public-dns
Remove the Current PHP Version
Uninstall the current PHP version (7.4 in this case).
sudo apt-get purge php7.4*
sudo apt-get autoremove
sudo apt-get autoclean
Add the PHP 7.3 Repository
Add the repository for PHP 7.3 to your package manager.
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
Install PHP 7.3
Install PHP 7.3 and the necessary PHP extensions.
sudo apt-get install php7.3
sudo apt-get install php7.3-cli php7.3-fpm php7.3-json php7.3-common php7.3-mysql php7.3-zip php7.3-gd php7.3-mbstring php7.3-curl php7.3-xml php7.3-bcmath php7.3-json
Update the PHP Command Alternatives
If you have multiple PHP versions installed, update the alternatives to set PHP 7.3 as the default version.
sudo update-alternatives --set php /usr/bin/php7.3
sudo update-alternatives --set phar /usr/bin/phar7.3
sudo update-alternatives --set phar.phar /usr/bin/phar.phar7.3
sudo update-alternatives --set phpize /usr/bin/phpize7.3
sudo update-alternatives --set php-config /usr/bin/php-config7.3
Restart the Web Server
Restart your web server (Apache or Nginx) to apply the changes.
For Apache:
sudo systemctl restart apache2
For Nginx:
If you are using PHP-FPM with Nginx, restart PHP-FPM and Nginx:
sudo systemctl restart php7.3-fpm
sudo systemctl restart nginx