How to Install PHP 8.4 on Ubuntu 24.04

Page 1


How to Install PHP 8.4 on Ubuntu 24.04

SettingupawebserverorrunningapplicationsthatrelyonPHPrequirestherightversion toensurecompatibilityandperformance.PHP8.4,thoughrelativelynew,offersvarious enhancementsandfeaturesthatcanimprovedevelopmentworkflowsandapplication behavior.ThisguidewalksthroughthestepstoinstallPHP8.4onUbuntu24.04with minimalfriction.

Step 1: Update the System

Beforeinstallinganynewpackages,ensureyoursystemisuptodate.Runthefollowing commandstorefreshthepackagelistandapplyavailableupdates:

sql

sudoaptupdate

sudoaptupgrade-y

Thiskeepsthesystemstableandreducesthechancesofencounteringversion-related conflictsduringPHPinstallation.

Step 2: Add PHP Repository

https://docs.vultr.com/

Ubuntu’sdefaultpackagesourcesmaynotincludethelatestPHPversion,especiallyPHP 8.4.Toaccessit,addthe ondrej/php repository,whichmaintainsupdatedPHPpackagesfor Ubuntusystems.

sql

sudoaptinstallsoftware-properties-common-y

sudoadd-apt-repositoryppa:ondrej/php

sudoaptupdate

AddingthisrepositoryensuresPHP8.4isavailabletoinstalldirectlythroughapt

Step 3: Install PHP 8.4

Oncetherepositoryisaddedandthepackagelistrefreshed,proceedtoinstallPHP8.4:

nginx

sudoaptinstallphp8.4-y

Aftertheinstallationcompletes,verifytheversion:

nginx

php-v

YoushouldseeoutputconfirmingthatPHP8.4isinstalledandactive.

Step 4: Install Common PHP Extensions

Dependingontheapplicationorframeworkyouplantorun,additionalPHPmodulesmight berequired.Somecommononesinclude:

python

sudoaptinstallphp8.4-cliphp8.4-commonphp8.4-mysqlphp8.4-xmlphp8.4-curlphp8.4mbstringphp8.4-zipphp8.4-bcmathphp8.4-gd-y

https://docs.vultr.com/ Theseextensionssupporttaskslikedatabaseinteraction,filehandling,imageprocessing, andmore.

Step 5: Configure PHP 8.4 Settings (Optional)

Youmaywanttoadjustsomesettingsinthephp.inifile,suchasmemorylimits,fileupload size,orerrorreportinglevel.Thelocationofthephp.inifiledependsonwhetheryou're usingPHPwithApacheorNginx:

● ForApache:/etc/php/8.4/apache2/php.ini

● ForNginx(withPHP-FPM):/etc/php/8.4/fpm/php.ini

Useatexteditorlikenanotomodify:

bash

sudonano/etc/php/8.4/fpm/php.ini

Afterediting,remembertorestartthewebserverorPHP-FPMtoapplythechanges.

Step 6: Configure Web Server (Apache or Nginx)

Ifyou'reusingApache: lua

sudoaptinstalllibapache2-mod-php8.4-y

sudosystemctlrestartapache2

Ifyou'reusingNginxwithPHP-FPM: nginx

sudoaptinstallphp8.4-fpm-y

sudosystemctlrestartphp8.4-fpm

MakesureyourwebserverconfigurationpointstothecorrectPHPsocketorportifusing PHP-FPM.

Step 7: Test PHP Installation

https://docs.vultr.com/

CreateasimplePHPfiletoconfirmthatPHPisworkingproperlythroughthewebserver. Usethiscommandtocreatethefile:

css sudonano/var/www/html/info.php

Insertthefollowingline: php <?phpphpinfo();?>

Saveandclosethefile,thenopenawebbrowserandnavigateto: pgsql http://your-server-ip/info.php

YoushouldseeaPHPinformationpagedetailingthecurrentversion,loadedmodules,and configurationoptions.

Step 8: Clean Up (Optional)

Onceyou'veconfirmedPHPisworking,it’sagoodideatoremovetheinfo.phpfileto preventexposingsensitiveconfigurationdetails.

bash sudorm/var/www/html/info.php

Final Thoughts

InstallingPHP8.4onUbuntu24.04isastraightforwardprocess.Whetheryou'repreparing torunaCMS,developcustomapplications,orhostAPIs,havingtherightversionofPHP ensurescompatibilitywiththelatestfeaturesandstandards.Thissetupalsoallowsyouto tailortheconfigurationtofityourapplicationrequirementswithgreaterflexibility.

Formoredetailsandadvancedoptions,refertothefullguideavailableat How to Install PHP 8 on Ubuntu 24.04.

Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.