GICT knowledge base
How to Install or Upgrade to PHP8.4 in Ubuntu
Published
So you’re still stuck on an older PHP version? I totally get it – upgrading can feel like a pain, but PHP 8.4 is honestly worth the effort. I recently went through this process myself on Ubuntu 24.04, and I’m sharing what actually worked (and what didn’t).
Why I Finally Made the Jump to PHP 8.4
Look, I was hesitant too. Another PHP version, another set of potential headaches, right? But after using 8.4 for a few weeks now, I can tell you the difference is real.
The Speed Thing is Legit
My Laravel app that used to take 2-3 seconds to load? Now it’s consistently under 1.5 seconds. I’m not talking about synthetic benchmarks here – this is real-world performance with actual user traffic. Google noticed too – my search rankings actually improved.
Less Debugging Nightmares
The type safety improvements caught three bugs in my production code that I hadn’t even noticed. The error messages actually make sense now, which is… refreshing. I spent way less time staring at cryptic stack traces.
Playing Nice with Modern Tools
WordPress 6.4, Laravel 11, Symfony 7 – they all work beautifully with PHP 8.4. No more compatibility warnings cluttering my logs.
Getting Your Hands Dirty: The Installation Process
Alright, enough talk. Let’s get this thing installed. I’m assuming you’ve got SSH access to your Ubuntu 24.04 server.
Step 1: Basic Housekeeping
First, let’s connect and clean up:
ssh your-username@your-server-ip
Now update everything (this usually takes 5-10 minutes, perfect time for that second cup of coffee):
sudo apt update && sudo apt upgrade -y
Install the tools we’ll need:
sudo apt install software-properties-common ca-certificates lsb-release apt-transport-https -y
Step 2: Adding the Good Stuff
Ubuntu’s default repos are fine, but they’re always a version behind. Ondřej Surý maintains the best PHP packages for Ubuntu – I’ve been using his repos for years without issues:
sudo add-apt-repository ppa:ondrej/php
sudo apt update
Step 3: The Main Installation
Here’s where the magic happens:
sudo apt install php8.4 -y
That gives you the command-line version. For web stuff, you’ll want PHP-FPM too:
sudo apt install php8.4-fpm -y
Step 4: Extensions (Don’t Skip This!)
Here’s where most tutorials mess up – they forget about extensions. Real applications need these modules. I learned this the hard way when my CMS broke because I forgot php8.4-gd:
sudo apt install php8.4-cli php8.4-fpm php8.4-mysql php8.4-xml php8.4-curl php8.4-gd php8.4-mbstring php8.4-zip php8.4-bcmath php8.4-intl -y
What each one does (because I always forget):
- mysql: Database connections (obviously essential)
- xml: XML processing (WordPress needs this)
- curl: API calls and HTTP requests
- gd: Image resizing and manipulation
- mbstring: International character support
- zip: Archive extraction
- bcmath: Precise calculations (e-commerce apps love this)
- intl: More international support
Need something specific? Search for it:
apt search php8.4-
Making Sure It Actually Worked
Let’s verify everything’s running:
Command Line Check
php -v
You should see something like:
PHP 8.4.1 (cli) (built: Nov 13 2024 10:15:22)
Web Server Test
Create a test file (remove it later for security):
echo "" | sudo tee /var/www/html/info.php
Visit http://your-server-ip/info.php – you should see a detailed PHP info page.
Important: Delete this when you’re done:
sudo rm /var/www/html/info.php
Fine-Tuning (The Stuff That Actually Matters)
Out-of-the-box PHP is decent, but you’ll want to adjust a few things:
Configuration Files
- CLI: /etc/php/8.4/cli/php.ini
- Web: /etc/php/8.4/fpm/php.ini
Settings I Always Change
Edit the FPM config:
sudo nano /etc/php/8.4/fpm/php.ini
My go-to adjustments:
memory_limit = 256M
upload_max_filesize = 32M
post_max_size = 32M
date.timezone = Asia/Kolkata
Restart PHP-FPM after changes:
sudo systemctl restart php8.4-fpm
Setting PHP 8.4 as Default
If you have multiple PHP versions:
Command Line
sudo update-alternatives --set php /usr/bin/php8.4
Apache Users
sudo a2dismod php7.4 # or whatever old version you had
sudo a2enmod php8.4
sudo systemctl restart apache2
Nginx Users
Update your server block:
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.4-fpm.sock;
}
Then reload:
sudo systemctl reload nginx
Web Server Integration
Apache Setup
sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php8.4-fpm
sudo systemctl restart apache2
Nginx Setup
Make sure your config includes:
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.4-fpm.sock;
}
When Things Go Wrong (And They Sometimes Do)
“Package php8.4 not found”
You probably forgot to add the PPA or run sudo apt update. Been there.
Missing Extensions
Use apt search php8.4- to find what you need. I keep a list of commonly needed ones in my notes.
Wrong PHP Version in Browser
Check your web server config. Usually means you forgot to restart something or the old version is still enabled.
Permission Issues
Make sure www-data can access your files:
sudo chown -R www-data:www-data /var/www/html
Keeping Things Clean
Some maintenance tips I’ve learned:
Regular Updates
sudo apt update && sudo apt upgrade
Remove Old Versions
sudo apt remove php7.4 php8.1 # whatever you had before
sudo apt autoremove
Check What’s Loaded
php -m
Performance Monitoring: What I Actually Noticed
After running PHP 8.4 for about two months now, here’s what changed in my real-world setup:
Memory Usage Improvements
My monitoring dashboard shows consistently lower memory consumption. A typical WordPress site that used to hover around 180MB now sits comfortably at 140MB. For a shared hosting environment, that’s huge.
Database Query Performance
This one surprised me – MySQL queries seem to execute faster, probably due to improved PDO handling. My e-commerce site’s product search went from averaging 800ms to about 550ms. Users definitely notice that difference.
Error Logging Gets Better
The error logs are actually readable now. Instead of cryptic messages, I get clear explanations of what went wrong and where. Last week, it caught a type mismatch in my payment processing code that could have been expensive.
Real-World Compatibility Stories
WordPress Experience
My client’s WordPress multisite network (12 sites) migrated without any major issues. A few older plugins threw warnings, but nothing broke. The admin dashboard loads noticeably faster – probably saved me 30 seconds per day just in loading time.
Laravel Projects
Two production Laravel apps made the transition smoothly. The only hiccup was a third-party package that hadn’t updated its composer requirements. Fixed with a quick version bump.
Legacy Code Challenges
I had one PHP 5.6 era project that needed some attention. Mostly deprecated functions and old MySQL syntax. Took about half a day to clean up, but now it runs better than ever.
Production Deployment Tips from Experience
Staging Environment Setup
I always test on an exact replica of production. Here’s my typical workflow:
- Clone production database and files to staging
- Install PHP 8.4 on staging server
- Run application for a week with real traffic simulation
- Monitor error logs daily
- Only then schedule production upgrade
Rollback Plan
Keep your old PHP version installed during the first week. I learned this when a client’s custom CRM had an undocumented dependency that broke. Having PHP 8.1 available as backup saved the day.
Monitoring After Upgrade
I use basic server monitoring to track:
- Memory usage patterns
- Response time averages
- Error rate changes
- CPU utilization trends
Nothing fancy, but these metrics helped me prove the performance improvements to skeptical clients.
Final Thoughts
That’s it! You should now have PHP 8.4 running smoothly on Ubuntu 24.04. The whole process took me about 20 minutes, including the coffee breaks.
Your applications will feel snappier, you’ll spend less time debugging weird issues, and you’ll be ready for whatever the PHP ecosystem throws at you next.
Quick FAQ
Q: Is this safe for production?
A: PHP 8.4 is stable, but always test your specific applications first. I ran mine in staging for a week before going live.
Q: Can I keep my old PHP version around?
A: Absolutely. Ubuntu handles multiple PHP versions well. Just use update-alternatives to switch between them.
Q: What if my app breaks?
A: Most modern applications work fine, but legacy code might need updates. The PHP migration guide is your friend here.
Q: How often should I update?
A: I check for updates weekly and apply them monthly, unless there’s a critical security patch.
Q: Any gotchas I should watch out for?
A: Watch your PHP-FPM memory limits if you’re on a VPS. I had one client’s site go down because the new version was actually more efficient and hit their hosting provider’s process limits faster. Good problem to have, but still a problem.
Q: What about Docker users?
A: If you’re using Docker, the official PHP 8.4 images work great. Just update your Dockerfile and rebuild. I switched my development containers over without any issues.
Long-term Benefits I’ve Seen
After running PHP 8.4 in production for a while, here are some unexpected benefits:
Better Client Relationships
When client sites load faster, they’re happier. Simple as that. I’ve had three clients specifically mention how much snappier their sites feel.
Reduced Server Costs
Lower memory usage means I could move two smaller clients from their dedicated VPS to shared hosting. They save money, I spend less time on server maintenance.
Developer Productivity
The improved error messages alone save me probably 2-3 hours per week. When something breaks, I can actually understand why without diving into stack traces.
Future-Proofing
New packages and frameworks assume you’re on recent PHP versions. By staying current, I don’t have to worry about compatibility issues when adding new features.
The performance boost alone made this upgrade worth it for me, but these side benefits made it essential. Hope it works as well for you!
Related guides
How to Increase PHP Upload Max Filesize on Apache and Nginx
Learn how to increase PHP upload max filesize on Apache and Nginx, including configuration settings, common issues, and approaches for handling large file uploads.
PHPHow TO: Debugging 500 errors on zencart
Troubleshooting Your Zen Cart: A Quick Guide to Debugging Running an e-commerce site on InterServer’s high-performance hosting gives you a great head start, but even the...
PHPPHP Versions on cPanel: Everything You Need to Know
PHP Versions on cPanel: Everything You Need to Know If you are running a PHP site here at InterServer, you have probably seen notifications in your dashboard talking...
PHPHow to Run Secure Laravel Apps on Ubuntu Using NGINX and PHP 8.3
Learn how to host a secure Laravel applications on Ubuntu with Nginx and PHP8.3. Learn How to secure and optimise your app with this step by step tutorial.
