Score:0

Could someone guide me through the use of symlinks in nginx for php modules?

br flag

so I'm running an ubuntu 20.04 server, with Nginx on it. After a difficult week, I managed to make it run normally, including php through php-fpm.

My problem is that I don't want hundreds of folders in my website's root (set at /var/www/www.my-domain.com/), so I'd like to put all the php related extensions I install (such as phpmyadmin, and IceCoder so far) in another folder (let's say /var/php/) and link all requests of php index from the root folder (like if I type https://my-domain.com/icecoder or https://my-domain.com/phpmyadmin) to redirect me to the folder where their index.php files are.

The problems with that are :

  • first, I don't know how to make the symlink work (I know the "ln -s target destination" command) but it never works.
  • second, that I don't know how to configure the default.conf file to make it happen.

I tried to pout a simple index.php with <?php phpinfo();?> inside in a /php folder in my root folder, but when I access it through the browser, I get an error "No file input setup". If I try to just access the said folder (for example https://my-domain.com/icecoder) I end up on my website, and for this one, the direct address to this index.php file works... except I only get a "working" state for hours, the text but no css. Dev tools do not even load.

Here are my config files (my real domain is anonymised under my-domain):

  1. nginx.conf

     user www-data;
     worker_processes  auto;
    
     error_log  /var/log/nginx/error.log notice;
     pid        /var/run/nginx.pid;
    
    
     events {
         worker_connections  1024;
     }
    
    
     http {
         include       /etc/nginx/mime.types;
         #include      /etc/nginx/sites-available/*.conf;
         #default_type  application/octet-stream;
    
         #root       /var/www;
         log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                           '$status $body_bytes_sent "$http_referer" '
                           '"$http_user_agent" "$http_x_forwarded_for"';
    
         access_log  /var/log/nginx/access.log  main;
    
         sendfile        on;
         #tcp_nopush     on;
    
         keepalive_timeout  65;
    
         #gzip  on;
    
         include /etc/nginx/conf.d/*.conf;
     }
    
  2. default.conf

     server {
         server_name  my_domain.com;
    
         #access_log  /var/log/nginx/host.access.log  main;
         root /var/www/www.my_domain.com;
         index index.html index.php;
    
         location / {
             try_files $uri /index.html index.php =404;
         }
    
         # redirect server error pages to the static page /50x.html
         #
         error_page 500 502 503 504  /50x.html;
         location = /50x.html {
             root   /var/www/www.my_domain.com;
         }
    
         error_page 404 /40x.html;
         location = /40x.html {
             root   /var/www/www.my_domain.com;
         }
    
    
         # proxy the PHP scripts to Apache listening on 127.0.0.1:80
         #
         #location ~ \.php$ {
         #    proxy_pass   http://127.0.0.1;
         #}
    
         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
         #
         location ~ [^/]\.php(/|$) {
             fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
             fastcgi_split_path_info ^(.+\.php)(/.+)$;
             fastcgi_index index.php;
             fastcgi_param PHP_VALUE open_basedir="/var/www/www.my_domain.com/:/var/www/www.my_domain.com/php/";
             include fastcgi_params;
    
         }
         # SCRIPT_FILENAME parameter is used for PHP FPM determining
         #  the script name. If it is not set in fastcgi_params file,
         # i.e. /etc/nginx/fastcgi_params or in the parent contexts,
         # please comment off following line:
         #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
         location ~ /\. { # le "~" indique une regex que "/" démarre, ici tout ce qui a un "." autre que php ou html
             deny all;
             access_log off;
             log_not_found off;
         }
    
         listen 443 ssl; # managed by Certbot
         ssl_certificate /etc/letsencrypt/live/my_domain.com/fullchain.pem; # managed by Certbot
         ssl_certificate_key /etc/letsencrypt/live/my_domain.com/privkey.pem; # managed by Certbot
         include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
         ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
    
    
     }
    
     server {
             listen 80;
             server_name www.my_domain.com;
    
             return 301 https://$server_name$request_uri; # redirets http requests to https website
     }
    
     server {
            listen 80;
            listen 443 ssl;
            server_name my_domain.com;
            return 301 http://www.my_domain.com$request_uri;
     }
    

here is an ls -l of the root folder

-rw-r--r--  1 www-data www-data   507 Sep 21 20:03 40x.html
-rw-r--r--  1 www-data www-data   507 Sep 21 20:04 50x.html
drwxr-xr-x  6 www-data www-data  4096 Aug 26 23:45 assets
-rw-r--r--  1 www-data www-data 83243 Aug 27 02:19 favicon.ico
-rw-r--r--  1 www-data www-data 25942 Aug 27 02:19 favicon.png
drwxr-xr-x 13 www-data www-data  4096 Sep 21 17:34 ICE
-rw-r--r--  1 www-data www-data 63175 Sep 21 15:58 index.html
-rw-r--r--  1 www-data www-data    19 Sep 20 22:24 index.php
drwxr-xr-x  2 www-data www-data  4096 Aug 27 00:31 maintenance
drwxr-xr-x 15 www-data www-data  4096 Sep 21 16:08 pages
lrwxrwxrwx  1 root     root        12 Sep 21 21:36 php -> /var/www/php
drwxr-xr-x  6 www-data www-data  4096 Sep  8 16:13 sections

and of the /var/php folder

drwxr-xr-x 13 www-data www-data 4096 Sep 21 17:34 icecoder
-rw-r--r--  1 www-data www-data   19 Sep 21 21:39 index.php
lrwxrwxrwx  1 root     root       12 Sep 21 21:48 php -> /var/www/php
drwxr-xr-x  2 www-data www-data 4096 Sep 21 21:37 phpmyadmin

All my folders are in 755 and files inside in 644 mod.

Thanks for any help you can give me

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.