You are not logged in.

#1 2013-12-30 14:39:34

friendofarch
Member
Registered: 2013-12-30
Posts: 59

Trying to setup PHP site (friendica) with nginx on localhost

Hi, just new here :-)

Started to use Arch a couple of month ago and sofar everything went fine thanks to the great documentation!

Now I tried to setup friendica on my computer for testing some modifications but I just fail on installing the required modules :-(

I already installed:

  • php

  • php-fpm

  • php-gd

  • php-cgi

  • php-mcrypt

  • mariadb

  • nginx

  • phpmyadmin

But I still get the following errors:

GD graphics PHP module 		(required)

    Error: GD graphics PHP module with JPEG support required but not installed.

OpenSSL PHP module 		(required)

    Error: openssl PHP module required but not installed.

mysqli PHP module 		(required)

    Error: mysqli PHP module required but not installed.

Generate encryption keys 		(required)

    Error: the "openssl_pkey_new" function on this system is not able to generate encryption keys
    If running under Windows, please see "http://www.php.net/manual/en/openssl.installation.php".

Command line PHP 		

    Could not find a command line version of PHP in the web server PATH.
    If you don't have a command line version of PHP installed on server, you will not be able to run background polling via cron. See 'Activating scheduled tasks'


    PHP executable path Enter full path to php executable. You can leave this blank to continue the installation.

Url rewrite is working 		(required)

    Url rewrite in .htaccess is not working. Check your server configuration.

My nginx.conf looks like this:

 #user http;
    worker_processes 1;

    error_log logs/error.log;
    #error_log logs/error.log notice;
    #error_log logs/error.log info;

    #pid logs/nginx.pid;


    events {
    worker_connections 1024;
    }


    http {
    include mime.types;
    default_type application/octet-stream;

    #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 logs/access.log main;

    sendfile on;

    keepalive_timeout 15;

    gzip on;
    gzip_comp_level 1;

    server {

    listen 80;
    server_name localhost;

    location ~ \.php {
    root /srv/http/project;
    fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;

    }

    location / {
    root /srv/http/project;
    index index.php;
    }
    }

    }

Can someone help me?

Offline

#2 2013-12-30 14:40:41

progandy
Member
Registered: 2012-05-17
Posts: 5,280

Re: Trying to setup PHP site (friendica) with nginx on localhost

Did you enable all necessary modules in your php.ini?
Then you'll have to create the rules in the .htaccess in the format nginx understands.
https://github.com/friendica/friendica/ … tall-Guide
http://jcsesecuneta.com/tome/labox/sett … -on-nginx/

Last edited by progandy (2013-12-30 14:47:24)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#3 2013-12-30 15:30:55

friendofarch
Member
Registered: 2013-12-30
Posts: 59

Re: Trying to setup PHP site (friendica) with nginx on localhost

Thanks for the quick answer!

progandy wrote:

Did you enable all necessary modules in your php.ini?

I had a look at /etc/php/php.ini but I can't find things (with my knwoledge) that seem to be important....

progandy wrote:

Then you'll have to create the rules in the .htaccess in the format nginx understands.

Haven't checked that yet...

This is quite complicated. Seems like I'd need to study  to understand it:-(

This one seemed clear I changed my nginx.xonf according to it:

server {
  listen 80;

  server_name localhost;
  root /srv/http/project;

  access_log off;                             # If you are using 'Analytics' type software for tracking, keep this 'off'
  log_not_found on;                          # Turn on if you want to track "not found" errors
  error_log /srv/http/project/logs/error.log info;          # valid values: debug, info, notice, warn, error, crit
  #rewrite_log on;                            # Uncomment if you want to debug your rewrites (then change 'crit' above to 'notice')

  # block stuff early
  # Do not log favicon.ico and robots.txt stuff
  location ~* /(favicon\.ico|robots\.txt) {
    allow all;
    access_log off;
    log_not_found off;
  }

  # Return error 444 for these files
  location ~* ^.+\.(bzr|git|log)$ {
    access_log off;
    log_not_found off;
    return 444;
  }

  # Deny public access to ~ (bak) files
  location ~* ~$ {
    access_log off;
    log_not_found off;
    return 444;
  }

  #############
  # Friendica #
  #############
  location / {
    try_files $uri $uri/ @friendicacleanurl;
  }

  location @friendicacleanurl {
    rewrite ^/(.*) /index.php?q=$uri last;
    break;
  }

  #######################
  # Security: Friendica #
  #######################
  # block public access to .htaccess and .htconfig.php
  location ~* /\.ht {
    access_log off;
    log_not_found off;
    return 444;
  }

  # block public access to .tpl files located in /view/ folder
  location ~* /view/(.*)\.tpl$ {
    access_log off;
    log_not_found off;
    return 444;
  }

  # block public access to /util/ folder
  location ^~ /util/ {
    access_log off;
    log_not_found off;
    return 444;
  }

  #################################
  # Deliver static files directly #
  #################################
  # images (Friendica)
  location ~* /(addon|images|library|spec|util|view)/(.*)\.(bmp|cur|gif|ico|j2k|jp2|jpe|jpeg|jpf|jpg|jpm|jpx|mj2|mng|png|svg|svgz|thm|tif|tiff|webp)$ {
    add_header Pragma "public";
    add_header Cache-Control "public";
    access_log off;
    log_not_found off;
    expires 28d;
  }

  ############################
  # redirect 50x error pages #
  ############################
  error_page 500 502 503 504 /50x.html;
  location = /50x.html {
    root /usr/share/nginx/html;
    internal;
  }

  ##############
  # enable PHP #
  ##############
  location ~ \.php$ {
    try_files $uri =404;

    fastcgi_split_path_info ^(.+\.php)(.*)$;

    fastcgi_pass 127.0.0.1:9000;                       # Comment if you want to use sock instead of tcp
    #fastcgi_pass unix:/var/run/php-fpm.sock;          # Uncomment to use sock instead of tcp

    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

    include /etc/nginx/fastcgi_params;
  }
}

but then nothing works anymore! When I try to restart nginx I get:

sudo systemctl status nginx.service
nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled)
   Active: active (running) (Result: exit-code) since Sa 2013-12-28 18:05:13 CET; 1 day 22h ago
  Process: 15591 ExecReload=/usr/bin/nginx -g pid /run/nginx.pid; daemon on; master_process on; -s reload (code=exited, status=1/FAILURE)
  Process: 318 ExecStart=/usr/bin/nginx -g pid /run/nginx.pid; daemon on; master_process on; (code=exited, status=0/SUCCESS)
  Process: 314 ExecStartPre=/usr/bin/nginx -t -q -g pid /run/nginx.pid; daemon on; master_process on; (code=exited, status=0/SUCCESS)
 Main PID: 320 (nginx)
   CGroup: /system.slice/nginx.service
           ├─  320 nginx: master process /usr/bin/nginx -g pid /run/nginx.pid; daemon on; master_process on;
           └─10295 nginx: worker process

Dez 30 14:59:10 thinker nginx[10294]: 2013/12/30 14:59:10 [notice] 10294#0: signal process started
Dez 30 14:59:10 thinker systemd[1]: Reloaded A high performance web server and a reverse proxy server.
Dez 30 16:12:58 thinker systemd[1]: Reloading A high performance web server and a reverse proxy server.
Dez 30 16:12:58 thinker nginx[15396]: 2013/12/30 16:12:58 [emerg] 15396#0: "server" directive is not allowed here in /etc/nginx/nginx.conf:1
Dez 30 16:12:58 thinker systemd[1]: nginx.service: control process exited, code=exited status=1
Dez 30 16:12:58 thinker systemd[1]: Reload failed for A high performance web server and a reverse proxy server.
Dez 30 16:15:33 thinker systemd[1]: Reloading A high performance web server and a reverse proxy server.
Dez 30 16:15:33 thinker nginx[15591]: 2013/12/30 16:15:33 [emerg] 15591#0: no "events" section in configuration
Dez 30 16:15:33 thinker systemd[1]: nginx.service: control process exited, code=exited status=1
Dez 30 16:15:33 thinker systemd[1]: Reload failed for A high performance web server and a reverse proxy server.

What's wrong?

Offline

#4 2013-12-30 15:39:35

friendofarch
Member
Registered: 2013-12-30
Posts: 59

Re: Trying to setup PHP site (friendica) with nginx on localhost

progandy wrote:

Then you'll have to create the rules in the .htaccess in the format nginx understands.

Ok, found a converter and converted it to:

# nginx configuration
 
location ~ "(^|/)\.git" {
   return 403; 
}
 
autoindex off;
 
location / {
   if (!-e $request_filename){
     rewrite ^(.*)$ /index.php?q=$1;
   }
}
 
location ~ \.(out|log)$ {
   deny all;
}

Offline

#5 2014-01-01 17:05:48

friendofarch
Member
Registered: 2013-12-30
Posts: 59

Re: Trying to setup PHP site (friendica) with nginx on localhost

But still the same problems...

Anyone else knows what I need to install or configure (and how)?

Offline

#6 2014-01-04 23:39:01

friendofarch
Member
Registered: 2013-12-30
Posts: 59

Re: Trying to setup PHP site (friendica) with nginx on localhost

Now I got a little bit further but I get this error message:

2014/01/05 00:34:34 [error] 323#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "localhost"

Ixquicking ;-) didn't bring any relevant help...

Any ideas?

Offline

#7 2014-03-05 21:16:50

ford prefect
Member
Registered: 2010-07-08
Posts: 43

Re: Trying to setup PHP site (friendica) with nginx on localhost

any progress on this story?
i failed to setup friendica and nginx as well.
did you have a look at the provided nginx config they ship with the friendica zip?


towel-day.com
nvidia ist keine Hautcreme

Offline

#8 2014-03-06 00:42:36

progandy
Member
Registered: 2012-05-17
Posts: 5,280

Re: Trying to setup PHP site (friendica) with nginx on localhost

I just tried to test the system check. All lights are green with the following steps:
Edit: My packages are nginx, mariadb, php, php-fpm, php-gd
- enable gd, mysqli, openssl, curl in php.ini
- put friendica in /srv/http, everything owned by user http, group http.
- add friendica.local to /etc/hosts
- add the following to nginx.conf

    server {
        listen 80;
        server_name friendica.local;
        root   /srv/http;

        location / {
            index  index.html index.php index.htm;
            try_files $uri $uri/ /index.php?q=$uri&$args;
        }

        location ~ [^/]\.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(.*)$;
            fastcgi_pass   unix:/run/php-fpm/php-fpm.sock;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include fastcgi_params;
            fastcgi_intercept_errors        on;
            fastcgi_ignore_client_abort     off;
            fastcgi_connect_timeout 60;
            fastcgi_send_timeout 180;
            fastcgi_read_timeout 180;
            fastcgi_buffer_size 128k;
            fastcgi_buffers 4 256k;
            fastcgi_busy_buffers_size 256k;
            fastcgi_temp_file_write_size 256k;
        }


        location ~ /.ht {
            deny all;
        }

    }

- start php-fpm and nginx with systemctl
- open friendica.local in your browser
Edit: I also set chdir to /srv/http in /etc/php/php-fpm.conf

Mix and merge that with the example nginx configuration. I guess you can use most of the example configuration, except the fastcgi stuff. Take that from me if necessary.

Last edited by progandy (2014-03-06 00:58:29)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#9 2014-03-06 09:08:19

friendofarch
Member
Registered: 2013-12-30
Posts: 59

Re: Trying to setup PHP site (friendica) with nginx on localhost

ford prefect wrote:

any progress on this story?

Since I didn't get any more replies I used apache instead ;-)

Offline

#10 2014-03-29 04:21:34

srf21c
Member
Registered: 2012-04-16
Posts: 24

Re: Trying to setup PHP site (friendica) with nginx on localhost

I'm trying to get Friendica running on a LEMP (Linux EngineX MariaDB PHP-FPM) stack as well. I used the sample nginx configuration provided here.

All system checks for the Friendica installer are green except for the last one, Url rewrite.

From what I gather, the apache centric rewrite rules in the Friendica .htaccess file must be modified to work with nginx. Can any nginx gurus confirm?

Last edited by srf21c (2014-03-29 04:27:46)

Offline

#11 2014-03-29 04:55:43

srf21c
Member
Registered: 2012-04-16
Posts: 24

Re: Trying to setup PHP site (friendica) with nginx on localhost

Turns out the .htaccess file does not need to be modified.  I was able to get past all the installer checks by using the nginx.conf file posted by progandy.

Now I will see if I can merge the working parts of progandy's nginx.conf with the sample one provided by the Friendica project so I can get TLS/HTTPS support working again.

Thank you everyone who contributed to this thread. I have been banging on this all day and was stuck until I came across the info here.

Offline

#12 2014-03-29 05:51:44

srf21c
Member
Registered: 2012-04-16
Posts: 24

Re: Trying to setup PHP site (friendica) with nginx on localhost

I did some more testing and discovered something interesting; The nginx config that progandy posted only works on my server for non-https connections using port 80.

If I change the nginx server port to 443, even though ssl remains disabled on the server, and the browser is making an unencrypted connection via an address such as http://friendica.local:443, the url rewrite check fails again.

I tried changing nginx.conf to have the server listen on some other ports, such as 81 & 8888  and got the same results. Once the port changes to anything other than 80, the url rewrite check fails.

Does anyone know why this is the case? Here's the nginx.conf that I'm using.

events {
    worker_connections  1024;
}
http {

server {
  listen 443;
  server_name friendica.local;
  root /srv/www/friendica;
  
  location / {
      index  index.html index.php index.htm;
      try_files $uri $uri/ /index.php?q=$uri&$args;
  }

  location ~ [^/]\.php$ {
      try_files $uri =404;
      fastcgi_split_path_info ^(.+\.php)(.*)$;
      fastcgi_pass   unix:/var/run/php-fpm.sock;
      fastcgi_index  index.php;
      fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
      include fastcgi_params;
      fastcgi_intercept_errors        on;
      fastcgi_ignore_client_abort     off;
      fastcgi_connect_timeout 60;
      fastcgi_send_timeout 180;
      fastcgi_read_timeout 180;
      fastcgi_buffer_size 128k;
      fastcgi_buffers 4 256k;
      fastcgi_busy_buffers_size 256k;
      fastcgi_temp_file_write_size 256k;
  }


  location ~ /.ht {
      deny all;
  }
}
}

Last edited by srf21c (2014-03-29 05:59:35)

Offline

Board footer

Powered by FluxBB