Table of Contents
1. Web server Nginx permissions
2. PHP permission configuration
3. Permission configuration of MySQL service
4. Summary
Home Operation and Maintenance Nginx How to configure user permissions for nginx, php-fpm and mysql

How to configure user permissions for nginx, php-fpm and mysql

May 24, 2023 pm 08:01 PM
mysql php nginx

How to configure user permissions for nginx, php-fpm and mysql

Normally, the servers we run web applications on include Linux distributions such as CentOS, Ubuntu, Debian, etc. At this time, the permission control of Nginx, PHP, MySQL and other applications necessary to form the service architecture is very important. Each service has different permission requirements for the code directory. The lack of certain permissions will cause the service to be unable to read, write or run. , which lowers the permission requirements and creates the risk of intrusion and modification.

1. Web server Nginx permissions

The running framework of PHP is usually combined with Nginx to form LNMP or combined with Apache to form LAMP architecture. Here, Nginx is used as an example to describe what is needed to run the Nginx service. permissions.
We know that Nginx itself cannot parse PHP syntax, so Nginx will directly parse and return results for static files (such as HTML, etc.), but for PHP files, Nginx will transfer them to the PHP interpreter php-fpm for processing. After processing, the response is returned to the client browser.

Therefore, we need to unify the permissions required for Nginx and PHP services in our code directory.

① If the root user is used uniformly, general guest accounts will not be able to access the application. If nginx is configured to run as root, there will be a great security risk. Once attacked, the root identity will be obtained to perform everything in the system. operate.

If the permissions of the code directory are uniformly set to rwxrwxrwx, there will be a hidden danger that users can directly modify the code directory through the browser.

So the best way is to classify them into a new user group and assign the user group the necessary permissions to run Nginx and PHP to achieve permission directory management for web applications. In many cases, teams will use the www user group to manage code directory permissions and uniformly manage user www.

We can see the Nginx configuration file nginix.confThe running permissions divided in it are configured under the www user, so the Nginx child process is also executed by the www user, which can be passedps aux | grep nginx to view:

How to configure user permissions for nginx, php-fpm and mysql

You can see that the main process of nginx is root, and the other sub-processes are all users of www

nginx.conf configuration:

How to configure user permissions for nginx, php-fpm and mysql

2. PHP permission configuration

Same, php The running mode is also run by the main process root. The configuration in the child process pool (pool) is executed by the www user. The specific configuration is under etc\php-fpm.conf in the php root directory. Add two lines. :

user = www
 group = www
Copy after login

. You can also use ps aux | grep php to view the user identity used by the process:

How to configure user permissions for nginx, php-fpm and mysql

3. Permission configuration of MySQL service

Through ps aux | grep mysql we can see that the MySQL service is running under the mysql user. The service only requires us to When the php code connects to mysql, just bring the user name and password of mysql. It does not need to be unified as www, because the data layer needs to be isolated from the business logic layer to ensure the security of the underlying data. The authorization of mysql is mainly to add new users and divide permissions in the mysql service, which is used to control different PHP businesses to connect with identities with different permission ranges to ensure data security.

How to configure user permissions for nginx, php-fpm and mysql

4. Summary

nginx configuration:

user www www;
Copy after login

php-fpm:

user = www
group = www
Copy after login

Directory:

drwxr-xr-x 就是755
Copy after login

The above is the detailed content of How to configure user permissions for nginx, php-fpm and mysql. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP: Handling Databases and Server-Side Logic PHP: Handling Databases and Server-Side Logic Apr 15, 2025 am 12:15 AM

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

PHP's Purpose: Building Dynamic Websites PHP's Purpose: Building Dynamic Websites Apr 15, 2025 am 12:18 AM

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

PHP and Python: Code Examples and Comparison PHP and Python: Code Examples and Comparison Apr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

How to check whether nginx is started How to check whether nginx is started Apr 14, 2025 pm 01:03 PM

How to confirm whether Nginx is started: 1. Use the command line: systemctl status nginx (Linux/Unix), netstat -ano | findstr 80 (Windows); 2. Check whether port 80 is open; 3. Check the Nginx startup message in the system log; 4. Use third-party tools, such as Nagios, Zabbix, and Icinga.

PHP: An Introduction to the Server-Side Scripting Language PHP: An Introduction to the Server-Side Scripting Language Apr 16, 2025 am 12:18 AM

PHP is a server-side scripting language used for dynamic web development and server-side applications. 1.PHP is an interpreted language that does not require compilation and is suitable for rapid development. 2. PHP code is embedded in HTML, making it easy to develop web pages. 3. PHP processes server-side logic, generates HTML output, and supports user interaction and data processing. 4. PHP can interact with the database, process form submission, and execute server-side tasks.

How to create a mirror in docker How to create a mirror in docker Apr 15, 2025 am 11:27 AM

Steps to create a Docker image: Write a Dockerfile that contains the build instructions. Build the image in the terminal, using the docker build command. Tag the image and assign names and tags using the docker tag command.

Centos install mysql Centos install mysql Apr 14, 2025 pm 08:09 PM

Installing MySQL on CentOS involves the following steps: Adding the appropriate MySQL yum source. Execute the yum install mysql-server command to install the MySQL server. Use the mysql_secure_installation command to make security settings, such as setting the root user password. Customize the MySQL configuration file as needed. Tune MySQL parameters and optimize databases for performance.

How to install mysql in centos7 How to install mysql in centos7 Apr 14, 2025 pm 08:30 PM

The key to installing MySQL elegantly is to add the official MySQL repository. The specific steps are as follows: Download the MySQL official GPG key to prevent phishing attacks. Add MySQL repository file: rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm Update yum repository cache: yum update installation MySQL: yum install mysql-server startup MySQL service: systemctl start mysqld set up booting

See all articles