Home > Backend Development > PHP Problem > php-fpm user settings

php-fpm user settings

WBOY
Release: 2023-05-28 22:32:06
Original
1083 people have browsed it

With the popularity of PHP, more and more websites use PHP as the back-end language, and more and more websites use PHP-FPM as the FastCGI process manager because it can improve the operating efficiency of PHP. Reduce server load. But many website administrators encounter a common problem when using PHP-FPM: how to set up a PHP-FPM user.

In regular use of PHP-FPM, the PHP-FPM user is usually the default www-data, but if you need to use other users, PHP-FPM may not run properly or may cause security issues. Therefore, setting up the PHP-FPM user correctly is key to ensuring the security and performance of your web server.

This article will introduce how to set up user accounts in PHP-FPM.

Step One: Create a User Account

First, you need to create a user account. This user account will be the user under which the PHP-FPM process runs. You can choose a user account that is the same as the user group to which the website belongs or create a new user account.

  1. Create user account

If you choose to create a new user account, you can use the following command:

sudo adduser myuser
Copy after login

where myuser is the user account you want Created username. You can follow the CLI prompts to enter the password and other information, or you can use the "-G" parameter to add the user account to the specified user group, for example:

sudo adduser myuser -G mygroup
Copy after login

where, mygroup is the user account you want to add to The name of the user group.

  1. Modify the user group to which the user account belongs

If you choose to use an existing user account, you need to add the user account to the user group to which it belongs. For example, if you want to use www-data as the user account, and the user group to which the website belongs is developers, you can use the following command to add www-data to the developers user group:

sudo usermod -a -G developers www-data
Copy after login
  1. Change Home directory permissions

After creating a user account or adding a user account to a user group, you need to modify the home directory permissions of the user account to ensure that PHP-FPM can access its home directory as that user. . You can use the following command to modify the permissions of the home directory:

sudo chown -R myuser:www-data /home/myuser
sudo chmod 775 -R /home/myuser
Copy after login

where myuser is the user name of the user account you just created.

Step 2: Modify the PHP-FPM configuration file

Next, you need to modify the PHP-FPM configuration file to ensure that the correct user account is used. You can use the following command to open the main configuration file of PHP-FPM:

sudo nano /etc/php/7.2/fpm/pool.d/www.conf
Copy after login

Please replace "7.2" in the above command with your PHP version number.

In the file, you need to find the following configuration lines:

user = www-data
group = www-data
Copy after login

Replace them with the user account you created and the user group it belongs to.

For example, if your PHP-FPM user account is myuser and the user group it belongs to is mygroup, the modified configuration should be as follows:

user = myuser
group = mygroup
Copy after login

Save the file and restart the PHP-FPM service:

sudo systemctl restart php7.2-fpm
Copy after login

In this way, you have successfully set up the PHP-FPM user account.

Summary

When using PHP-FPM, it is very important to set up the correct user account, as this will help improve the security and performance of the web server. By creating a new user account, adding it to the user group it belongs to, and then setting it as the default user in the PHP-FPM configuration file, you can take full advantage of PHP-FPM and ensure that your web server is more Safety.

The above is the detailed content of php-fpm user settings. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template