Linux, Web Server & Database
Install PHP on Linux Server
Get the right PHP version and extensions installed and working with your web server.
The Problem
Your application needs a specific PHP version and a specific set of extensions, and installing the wrong combination — or forgetting to connect PHP to your web server properly — leaves you with a server that just downloads .php files instead of running them.
About this problem
PHP installation issues almost always come down to two things: getting the exact version your application needs (since distro repositories often ship an older default), and making sure the web server is actually configured to hand .php requests to PHP rather than serving them as plain text or triggering a download.
This comes up constantly when deploying an application with specific version requirements, or when a distro's default PHP is too old for a modern framework.
What's Included
- Installing the exact PHP version your application requires, via the correct repository
- Installing the PHP extensions your application needs (mysqli, gd, curl, mbstring, etc.)
- Connecting PHP to your web server correctly (mod_php or PHP-FPM)
- Testing with a real PHP script to confirm it executes rather than downloads
What's NOT Included
- Debugging your application's own PHP code
- Installing a database (see MySQL/MariaDB installation services)
- Running multiple PHP versions side-by-side for different sites (can be scoped as an add-on)
How It Works
- Add the correct PHP repository (e.g. Ondrej's PPA on Ubuntu, or Remi on CentOS) for the version you need.
- Install PHP along with the specific extension list your application's documentation requires.
- Configure the web server to pass .php requests to PHP, either via mod_php or a PHP-FPM socket.
- Adjust key php.ini values (memory_limit, upload_max_filesize, max_execution_time) to sensible levels.
- Create a test script and confirm it executes correctly through the web server, not just the CLI.
In practice: you buy the service, send over whatever access or details the job needs, I investigate and do the work, and you confirm it's resolved before we call it done.
Frequently Asked Questions
- How do I know which PHP version I need?
- Your application's documentation or a composer.json/requirements file usually states a minimum version — installing older than that commonly causes fatal syntax or function errors.
- Why does my browser try to download my PHP file instead of running it?
- That means the web server isn't configured to hand .php files to the PHP interpreter — it's treating them as plain static files instead.
- Can I have two different PHP versions on the same server?
- Yes, most distros support running multiple PHP-FPM versions side-by-side, each on its own socket, with different sites pointed at different versions.
- What PHP extensions does WordPress need?
- At minimum mysqli, gd or imagick, curl, mbstring, xml and zip — missing ones show up as specific plugin or media errors rather than a single clear message.
- Why do I get a 'Class not found' error after installing PHP?
- That usually means a required extension isn't installed or enabled — the class exists in an extension that PHP hasn't loaded, not in PHP's core.
- Is it safe to use the latest PHP version?
- Usually yes for new projects, but older applications sometimes use deprecated functions removed in newer PHP versions — worth checking compatibility before jumping several major versions at once.