Watch the video:
0:00 - Intro/Explanation
0:14 - Installing PHP8.3
1:00 - Installing PHP Extensions
1:52 - Linking PHP with Nginx
3:09 - Verify sites have PHP handling set
Why install PHP-FPM with Nginx?
Nginx by default doesn’t have a way to work well with PHP. However, being as modular as it is: It’s super easy to install and start using PHP on your server.
Just be aware of the security holes that could be introduced – PHP and Nginx have had many years getting it just right, but remember that what you put on your server may introduce other worrying holes in your security. I’m sure you’re aware of all of this anyway, besides the point.
How to install PHP-FPM
If you’re using Ubuntu the simplest way is to just install the latest version of PHP-FPM via Ondřej Surý’s Launchpad PPA. There are other ways of doing this if you don’t want to use this, or can’t use PPAs.
|
|
Now we can install PHP extensions. These are what I’ll be using for the project I’m working on, so yours may be different. For example:
|
|
Then we can customize PHP’s settings to better suit your server:
|
|
I’ll be changing upload_max_filesize
, post_max_size
, memory_limit
, max_execution_time
, max_input_vars
and max_input_time
- the last is unlimited by default.
Then, restart your PHP installation.
|
|
Verify installation
Finally, we need to make sure that Nginx is using the correct version.
In your /etc/nginx/sites-enabled
for your website, you can enable PHP by adding the following to your website’s server block:
|
|
This way we can manually set which websites can and can’t use PHP.