The article demonstrates how to configure PHP 8 FPM on Linux operating systems like Ubuntu and Debian. It helps you properly set it up and avoid unwanted “permission denied” errors. PHP7.x-FPM and PHP8.x-FPM are the available versions, with the latest being PHP8.1-FPM.
How to configure php8-fpm on Ubuntu 22.04, 20.04 or Debian
If you are a developer, you will probably encounter many permission errors related to the owner and file owner of USER in projects. So how to configure and set the php-fpm versions properly? Let’s discuss and present with itsmeit in this article.
1. The common reason for file ownership permission errors on Linux, Ubuntu.
- Uploading files to a hosting/server
- Modifying the contents of a file without taking ownership
- Rendering, public code, deploying source code, cache, etc. that is not owned
- Improperly changing ownership.
If you’re new to Linux, you may be tempted to use the chmod 777 or 755 command to set file permissions. However, setting permissions to 777 is never a good idea as it greatly impacts the security of your website or app. It’s a temporary solution, not a permanent fix. The correct way to solve the problem is by correctly configuring the read, write, execute, and ownership permissions. Keep reading to learn about how to properly configure php8-fpm on Ubuntu 22.04, 20.04, and Debian.
2. Set file owner for USER on Ubuntu or Linux Debian
Once you have successfully installed the desired version of PHP on your system, you can follow the guide on installing PHP 8. Then, navigate to the file www.conf in “/etc/php/8.0/fpm/pool.d/” and make necessary edits. (Make sure to replace “8.0” with your specific PHP version).
Before doing this, you can make a backup in case you want to go back to the default.
sudo cp -R /etc/php/8.0/fpm/pool.d/www.conf /etc/php/8.0/fpm/pool.d/www.conf.bak sudo nano /etc/php/8.0/fpm/pool.d/www.conf
As depicted in the image, you will come across the line with the value [www]. When you use Nginx or Apache server, the web/app projects will be set in the /var/www/… This indicates that all the directories located under /var/www/ will be influenced by the user and group permissions, similar to the values shown below.
- user = www-data
- group = www-data
- listen.owner = www-data
- listen.group = www-data
- user = itsmeit
- group = www-data
- listen.owner = itsmeit
- listen.group = www-data
The default configuration is user/group = www-data, which means that when you upload a file or render a project to the server, it will be assigned the permission of www-data:www-data. This can result in a “permission denied” error, since only the www-data user has write and execute permissions (add, edit, delete). Even if you use the root user, you may still encounter the same permission errors.
So, the solution is to configure php8-fpm on Debian or Ubuntu and grant USER read, write, and execute permissions. In this case, USER is assigned to itsmeit. Similarly, you can specify permissions for groups. In this example, the default group is www-data and it has read, write, and execute permissions assigned to itsmeit.
Then restart the php-fpm to make the changes effective.
sudo service php8.0-fpm restart
Once you set it up like that, you’ll use the user you specify to manage web/app projects. You can also create ssh keys to login when working on VPS.
The article on how to configure php8-fpm on Ubuntu 22.04, 20.04 and Debian will provide you with a comprehensive understanding of the USER’s read, write, and execute permissions. With these permission settings in place, you will be able to prevent unexpected errors when using php7.x-fpm or php8.x-fpm.
— Read more: Chmod in Linux | Ubuntu, Chmod Permissions Command Example
– Advertising –