Tổng hợp cài đặt PHP Ubuntu các phiên bản

image-6 Tổng hợp cài đặt PHP Ubuntu các phiên bản

Giới thiệu

Cài đặt PHP trên Ubuntu là một bước thiết yếu để xây dựng và triển khai các ứng dụng web. Với mỗi phiên bản Ubuntu khác nhau, quy trình cài đặt có thể có những điểm khác biệt nhỏ. Bài viết này sẽ hướng dẫn chi tiết từng bước để bạn có thể dễ dàng thiết lập PHP trên các phiên bản Ubuntu phổ biến như 18.04, 20.04, và 22.04. Dù bạn là người mới bắt đầu hay đã có kinh nghiệm, hướng dẫn này sẽ giúp bạn cài đặt PHP một cách nhanh chóng và hiệu quả.

Cài đặt PHP-FPM các phiên bản

PHP-FPM5.6 :

apt update
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php

sudo apt install php5.6 php5.6-fpm -y

sudo apt-get install -y php5.6-mcrypt \
&& sudo apt-get install -y php5.6-mbstring \
&& sudo apt-get install -y php5.6-mysqlnd \
&& sudo apt-get install -y php5.6-soap \
&& sudo apt-get install -y php5.6-curl \
&& sudo apt-get install -y php5.6-gd \
&& sudo apt-get install -y php5.6-zip \
&& sudo apt-get install -y php5.6-imagick \
&& sudo apt-get install -y php5.6-dom \
&& sudo apt-get install -y php5.6-tidy \
&& sudo apt-get install -y php5.6-bcmath 

#enable fcgi mode
sudo a2enmod actions alias proxy_fcgi fcgid
sudo service apache2 restart

systemctl enable php5.6-fpm && systemctl start php5.6-fpm

#check status
sudo systemctl status php5.6-fpm

PHP-FPM7.2 :

apt update
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php

sudo apt install php7.2 php7.2-fpm -y

sudo apt-get install libapache2-mod-php7.2 -y \
&& sudo apt-get install -y php7.2-mcrypt \
&& sudo apt-get install -y php7.2-mbstring \
&& sudo apt-get install -y php7.2-mysqlnd \
&& sudo apt-get install -y php7.2-soap \
&& sudo apt-get install -y php7.2-curl \
&& sudo apt-get install -y php7.2-gd \
&& sudo apt-get install -y php7.2-zip \
&& sudo apt-get install -y php7.2-imagick \
&& sudo apt-get install -y php7.2-dom \
&& sudo apt-get install -y php7.2-tidy \
&& sudo apt-get install -y php7.2-bcmath

#enable fcgi mode
	sudo a2enmod actions alias proxy_fcgi fcgid
        systemctl enable php7.2-fpm && systemctl start php7.2-fpm
	sudo service apache2 restart

#Check Status :
	sudo systemctl status php7.2-fpm

PHP-FPM7.4 :

apt update
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php

sudo apt install php7.4 php7.4-fpm -y

sudo apt-get install libapache2-mod-php7.4 -y \
&& sudo apt-get install php7.4-fpm -y \
&& sudo apt-get install -y php7.4-mcrypt \
&& sudo apt-get install -y php7.4-mbstring \
&& sudo apt-get install -y php7.4-mysqlnd \
&& sudo apt-get install -y php7.4-soap \
&& sudo apt-get install -y php7.4-curl \
&& sudo apt-get install -y php7.4-gd \
&& sudo apt-get install -y php7.4-zip \
&& sudo apt-get install -y php7.4-imagick \
&& sudo apt-get install -y php7.4-dom \
&& sudo apt-get install -y php7.4-tidy \
&& sudo apt-get install -y php7.4-bcmath 

#enable fcgi mode
	sudo a2enmod actions alias proxy_fcgi fcgid
        systemctl enable php7.4-fpm && systemctl start php7.4-fpm
	sudo service apache2 restart

#Check Status :
	sudo systemctl status php7.4-fpm

PHP-FPM8.0:

apt update
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php

sudo apt-get install -y php8.0 php8.0-fpm php8.0-mcrypt \
&& sudo apt-get install libapache2-mod-php8.0 -y \
&& sudo apt-get install -y php8.0-mbstring \
&& sudo apt-get install -y php8.0-mysqlnd \
&& sudo apt-get install -y php8.0-soap \
&& sudo apt-get install -y php8.0-curl \
&& sudo apt-get install -y php8.0-gd \
&& sudo apt-get install -y php8.0-zip \
&& sudo apt-get install -y php8.0-imagick \
&& sudo apt-get install -y php8.0-dom \
&& sudo apt-get install -y php8.0-tidy \
&& sudo apt-get install -y php8.0-bcmath php8.0-common php8.0-memcached php8.0-redis \
&& apt install -y php8.0-gmp

#enable fcgi mode
	sudo a2enmod actions alias proxy_fcgi fcgid
        systemctl enable php8.0-fpm && systemctl start php8.0-fpm
	sudo service apache2 restart

#Check Status :
	sudo systemctl status php8.0-fpm

PHP-FPM8.3

apt update
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php

sudo apt-get install -y php8.3 php8.3-fpm php8.3-mcrypt \
&& sudo apt-get install libapache2-mod-php8.3 -y \
&& sudo apt-get install -y php8.3-mbstring \
&& sudo apt-get install -y php8.3-mysqlnd \
&& sudo apt-get install -y php8.3-soap \
&& sudo apt-get install -y php8.3-curl \
&& sudo apt-get install -y php8.3-gd \
&& sudo apt-get install -y php8.3-zip \
&& sudo apt-get install -y php8.3-imagick \
&& sudo apt-get install -y php8.3-dom \
&& sudo apt-get install -y php8.3-tidy \
&& sudo apt-get install -y php8.3-bcmath php8.3-common php8.3-memcached php8.3-redis \
&& apt install -y php8.3-gmp

#enable fcgi mode
	sudo a2enmod actions alias proxy_fcgi fcgid
        systemctl enable php8.3-fpm && systemctl start php8.3-fpm
	sudo service apache2 restart

#Check Status :
	sudo systemctl status php8.3-fpm

Hoặc có thể sử dụng Ctrl+C + Ctrl+V cho các bạn lười :

apt install apache2 -y \
&& apt update \
&& sudo apt install software-properties-common -y \
&& sudo add-apt-repository ppa:ondrej/php \
&& sudo apt install php5.6 php5.6-fpm php7.2 php7.2-fpm php7.4 php7.4-fpm php8.0 php8.0-fpm  -y \
&& sudo a2enmod actions alias proxy_fcgi fcgid \
&& systemctl enable apache2 php5.6-fpm php7.4-fpm php7.2-fpm php8.0-fpm \
&& sudo apt-get install -y php7.2-mcrypt php7.2-mbstring php7.2-mysqlnd php7.2-soap php7.2-curl php7.2-gd php7.2-zip php7.2-imagick php7.2-dom php7.2-tidy libapache2-mod-php7.2 \
&& sudo apt-get install -y php7.4-mcrypt php7.4-mbstring php7.4-mysqlnd php7.4-soap php7.4-curl php7.4-gd php7.4-zip php7.4-imagick php7.4-dom php7.4-tidy libapache2-mod-php7.4 \
&& sudo apt-get install -y php5.6-mcrypt php5.6-mbstring php5.6-mysqlnd php5.6-soap php5.6-curl php5.6-gd php5.6-zip php5.6-imagick php5.6-dom php5.6-tidy libapache2-mod-php5.6 \
&& sudo apt-get install -y php8.0-mcrypt php8.0-mbstring php8.0-mysqlnd php8.0-soap php8.0-curl php8.0-gd php8.0-zip php8.0-imagick php8.0-dom php8.0-tidy libapache2-mod-php8.0 \
&& systemctl start apache2 php5.6-fpm php7.2-fpm php7.4-fpm php8.0-fpm \
&& systemctl status apache2 php5.6-fpm php7.2-fpm php7.4-fpm php8.0-fpm \
&& a2enmod rewrite \
&& a2enmod headers \
&& for file in hosts; do cat "$file" >> /etc/hosts; done \
&& for file in ports.conf; do cat "$file" >> /etc/apache2/ports.conf; done \
&& cp ./conf/* /etc/apache2/sites-available/ \
&& cd /etc/apache2/sites-available/ \
&& a2ensite * \
&& apachectl configtest

Qua hướng dẫn này, bạn đã nắm được cách cài đặt PHP trên các phiên bản Ubuntu, từ cơ bản đến nâng cao. Việc thiết lập môi trường PHP chính xác là nền tảng quan trọng để phát triển và vận hành các ứng dụng web hiệu quả. Dù bạn sử dụng phiên bản Ubuntu nào, chỉ cần làm theo các bước hướng dẫn, bạn sẽ nhanh chóng có một môi trường PHP sẵn sàng cho mọi dự án của mình.

I am gaining experience and developing my skills in the field of information technology. My focus areas include basic network administration, troubleshooting, and supporting IT infrastructure. I am keen on learning and growing in various aspects of IT, from system setup and maintenance to exploring new technologies and methodologies.

Post Comment