Optimalizace pro vyhledávače podle Rank Math - https://rankmath.com/ -->

<span class ="tr_" id="tr_3" data-source="" data-orig="Install And Uninstall PHP On Ubuntu">Install And Uninstall PHP On Ubuntu</span> | Plukovník Server - Hosting serverů infrastruktury
Site icon Colonel Server – Infrastructure Server Hosting

Install and Uninstall PHP on Ubuntu

php ubuntu

Have you ever wanted to build websites and web applications but weren’t sure where to start? Dobře, if you’re an Ubuntu user, then PHP is a powerful tool you’ll need in your arsenal. If you don’t know how to install PHP on Ubuntu or uninstall it from your Ubuntu system, then you’re in the right place. In this blog post, we’ll guide you on how to install and uninstall PHP on Ubuntu. Whether you’re a seasoned developer or just starting your web development journey, this guide will help you.

PHP Versions in Ubuntu The available PHP versions in Ubuntu depend on the Ubuntu version and the enabled sources:

Note: You can install additional PHP versions using PPAs like ppa:ondrej/php.

Additional Considerations:

How to Install PHP on Ubuntu

Installing PHP on Ubuntu enables a local development environment for testing and building dynamic applications.

Prerequisites

Method 1: Install PHP with Apache

  1. Update and upgrade packages:
sudo apt update && sudo apt upgrade
  1. Install prerequisites:
sudo apt install software-properties-common
  1. Add PHP PPA:
sudo add-apt-repository ppa:ondrej/php
  1. Update packages again:
sudo apt update
  1. Install Apache and PHP:
sudo apt install apache2 php7.4 libapache2-mod-php7.4

Replace 7.4 s 8.1 if desired.

  1. Restart Apache:
sudo systemctl restart apache2
  1. Verify PHP installation:
php -v
  1. Create info page:
sudo nano /var/www/html/info.php

Paste:

<?php phpinfo(); ?>

Method 2: Install PHP with NGINX

  1. Update and upgrade packages:
sudo apt update && sudo apt upgrade
  1. Install prerequisites:
sudo apt install software-properties-common
  1. Add PHP PPA and update:
sudo add-apt-repository ppa:ondrej/php
sudo apt update
  1. Install NGINX and PHP-FPM:
sudo apt install nginx php7.4-fpm

Replace 7.4 s 8.1 if desired.

  1. Configure NGINX for PHP:
sudo nano /etc/nginx/sites-available/default

Uncomment location ~ \.php$ block and save.

  1. Restart NGINX and PHP-FPM:
sudo systemctl restart nginx
sudo systemctl restart php7.4-fpm
  1. Verify Installation:
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/phpinfo.php

Visit http://<your_server_ip>/phpinfo.php

Installing PHP Modules

To install PHP modules:

sudo apt install php7.4-mysql

To list installed modules:

php -m

Why Uninstall PHP on Ubuntu?

Important Notes

Uninstall PHP 7.4

sudo apt remove --purge php7.4
sudo apt remove --purge php7.4-fpm
sudo rm -rf /etc/php/7.4

Uninstall PHP 8.1

sudo apt remove --purge php8.1
sudo apt remove --purge php8.1-fpm
sudo rm -rf /etc/php/8.1

Restart Web Server

sudo systemctl restart apache2
sudo systemctl restart nginx

Verify Uninstallation

php -v

Should return “command not found.”

Conclusion

In this guide, we covered how to install and uninstall PHP on Ubuntu. We discussed the different installation methods with Apache and NGINX, how to verify PHP installation, and how to cleanly uninstall PHP when necessary. Managing PHP installations is an essential skill for developers and sysadmins, offering flexibility and better control over server resources.

Exit mobile version