How to Install PHP and Manage PHP Versions

Installing PHP and Managing Versions

Install PHP on Ubuntu/Debian

Ubuntu's default repos may not have the latest PHP. Use the Ondrej PPA for more recent versions:

apt install software-properties-common -y
add-apt-repository ppa:ondrej/php -y
apt update
apt install php8.2 php8.2-fpm php8.2-mysql php8.2-curl php8.2-gd php8.2-mbstring php8.2-xml php8.2-zip -y

Install PHP on CentOS/AlmaLinux (Remi Repository)

dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm -y
dnf module enable php:remi-8.2 -y
dnf install php php-fpm php-mysqlnd php-curl php-gd php-mbstring php-xml -y

Check Active PHP Version

php -v

Switch Between PHP Versions (Ubuntu with multiple installed)

# For CLI:
update-alternatives --config php

# For Apache:
a2dismod php8.1
a2enmod php8.2
systemctl restart apache2

# For Nginx (PHP-FPM), update the socket path in your server block:
# fastcgi_pass unix:/run/php/php8.2-fpm.sock;

List Installed PHP Extensions

php -m

Install Additional Extensions

apt install php8.2-redis php8.2-imagick php8.2-intl -y

PHP Configuration File Location

php --ini   # Shows which php.ini is loaded

Common tweaks in php.ini: increase upload_max_filesize, post_max_size, memory_limit, and max_execution_time.

  • 0 Utenti hanno trovato utile questa risposta
Hai trovato utile questa risposta?

Articoli Correlati

Managing Users and Groups

Managing Users and Groups on Linux Proper user management is essential for server security. Avoid...

Managing Services with systemctl

Managing Services with systemctl systemctl is the standard tool for managing services on modern...

Monitoring Server Resources

Monitoring Server Resources Keeping an eye on your server's resource usage helps you identify...

Scheduling Tasks with Cron

Scheduling Tasks with Cron Cron allows you to schedule commands to run automatically at set...

Installing and Configuring Nginx

Installing and Configuring Nginx Nginx is a high-performance web server and reverse proxy widely...