Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The solution to the problem of prompt File not found under LNMP

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Preface

In general, each virtual host is a website, which is generally accessed through a domain name. Recently, I encountered a problem when configuring LNMP (Linux Nginx MariaDB Php-fpm):

Visit the home page of the website and always improve your File not found.

After the final solution, a summary is: the permission problem of the root directory of the website.

cause

Tell me what happened. The system I use is Manjaro Linux system. So install the LNMP environment with one command: sudo pacman-S mariadb nginx php. At first, I put the symfony project in my home directory, which is ~ / projects. Then I officially copied a copy of nginx's configuration file symfony.conf from symfony, put it in the / etc/nginx/sites-available directory, changed the root parameter to / home/lrcn/projects/symfony/public, and changed the fastcgi_pass parameter to unix:/run/php-fpm/php-fpm.sock. OK, run the sudo nginx-t test to pass, and then restart nginx.

But here's the problem. I type symfony.dev in the browser (add a hosts to 127.0.0.1 symfony.dev) and always prompt File not found. Even if I set the site directory to 777! This question has been bothering me all day! My heart is about to explode. Finally I took a deep breath and thought about it. Sure enough, I got the answer after searching all the Internet resources.

That's how it's explained. The PHP-FPM program needs a user and user group to run the program. This user and group must have rx permissions on my project files. Some directories must also have rwx permissions, such as upload,log directories, and so on. The Nginx program also needs a user who also has rx permissions for the project file.

Solution method

Since my default user for nginx is http, I want to change it to nginx and add nginx to the www user group. At the same time, I changed the user of php-fpm to www and the user group to www.

1) create a user

Sudo useradd-s / sbin/nologin www # creates www users and automatically creates www user groups sudo gpasswd-a nginx www # to add nginx users to www user groups

2) modify the configuration file

Since I only care about the configuration related to file permissions here, I still need to adjust the rest of the configuration myself.

# grep "^ [^" ] "when / etc/php/php-fpm.d/www.conf# modifies, just modify user, group, listen.owner, listen.group, and the rest are default configurations [www] user = wwwgroup = wwwlisten = / run/php-fpm/php-fpm.socklisten.owner = wwwlisten.group = wwwlisten.mode = 0660pm = dynamicpm.max_children = 5pm.start_servers = 2pm.min_spare_servers = 1pm.max_spare_servers = write / etc/nginx/nginx.conf# on the first line The rest of the unchanged user nginx www

3) modify project file permissions

This step I found a very strange problem, if I put the website directory in the home directory of lrcn users, www users will never be able to access the project file, even if I set ~ / projects to chown www:www ~ / projects-R, it doesn't work. Running the test command sudo-u www stat ~ / projects/symfony still indicates that there is no permission. I think the / home/lrcn directory is owned by lrcn, and even if I change its subdirectory projects to www:www, it is not accessible. It makes sense. So, I put the project directory in the / var/www directory, then ran sudo-u www stat / var/www, and got the normal result:

[lrcn@lrcn-pc nginx] $sudo-u www stat / var/www [sudo] lrcn password: file: / var/www size: 4096 block: 8 IO block: 4096 directory device: 801h/2049d Inode:3671064 hard link: 3 permissions: (2775/drwxrwsr-x) Uid: (1000 / lrcn) Gid: (1001 / lrcn) recent visit: 2017-12-1000: 40 Uid: 04.274947995 + 0800Last change: 2017-12-1000: 41: 34.772321160 + 0800 recently changed: 2017-12-10 10 51purl 15.811999323 + 0800 creation time:-

If you get the above information, prove that www users can access the root directory of the site, and then move the project symfony to the / var/www directory.

[lrcn@lrcn-pc var] $tree www-L 2www └── symfony ├── bin ├── composer.json ├── composer.lock ├── config ├── public src ├── symfony.lock ├── var └── vendor

OK, modify the directory permissions. I changed the / var/www directory to lrcn:www and created a soft link to / var/www/symfony in the ~ / projcects directory so that I could manipulate the project files in the home directory. The question is why the owner of the / var/www directory should be changed to lrcn, because in this way, I can use lrcn users to manipulate the project file casually. Lrcn users are my users who log in to the linxu system. It is very convenient to use in the development project.

Sudo chown lrcn:www / var/www-R # change project permissions sudo ln-s / var/www/symfony ~ / projects/symfony # access project sudo chmod 775 / var/www-R # in home directory so that www users can manipulate files lrcn users create files or folders that inherit the www user group rather than the lrcn user group after lrcn users inherit the lrcn user group, this command is very important

The effect of the change:

[lrcn@lrcn-pc symfony] $ls-al total amount 108drwxrwsr-x 10 lrcn www 4096 December 10 01:14. Drwxrwsr-x 3 lrcn www 4096 December 10 00:41.. drwxrwsr-x 2 lrcn www 4096 December 10 00:41 bin-rwxrwxr-x 1 lrcn www 1146 December 10 00:41 composer.json-rwxrwxr-x 1 lrcn www 48074 December 10 00:41 composer.lockdrwxrwsr-x 3 lrcn www 4096 December 10 00:41 config-rwxrwxr-x 1 lrcn www 495 December 10 00:41. Env-rwxrwxr-x 1 lrcn www 495 December 10 00:41. Env.distdrwxrwsr-x 8 lrcn www 4096 December 10 00:41. Git-rwxrwxr-x 1 lrcn www 10 00:41. Gitignoredrwxrwsr-x 4 lrcn www 4096 December 10 00:41. Ideadrwxrwsr-x 2 lrcn www 4096 December 10 10:42 publicdrwxrwsr-x 3 lrcn www 4096 December 10 00:41 src-rwxrwxr-x 1 lrcn www 1889 December 10 00:41 symfony.lockdrwxrwsr-x 4 lrcn www 4096 December 10 00 lrcn www 41 vardrwxrwsr-x 5 lrcn www 4096 December 100 0041 vendor

Well, at this point, the problem of the website prompting File not found has been basically solved.

Then visit the home page of the website

Summary

The above is the whole content of this article, I hope that the content of this article has a certain reference and learning value for your study or work, if you have any questions, you can leave a message and exchange, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report