当前位置: 首页 > 知识库问答 >
问题:

MediaWiki关于PHP5-FPM和NginX的PHP会话

诸葛茂勋
2023-03-14

我已经尝试在我的nginx/php5 fpm堆栈上安装mediawiki大约一天了,我在这个堆栈上安装了许多其他框架,从Wordpress、Magento到OpenEMON,所有这些都工作得很好:

  • Ubuntu 12.04 LTS

如果你看这里:http://wiki.qubmc.co.uk/mw-config/index.php

按继续只会出现会话错误:您的会话数据丢失了!检查您的php.ini,并确保session.save_path设置为适当的目录。

会话是由PHP为这个应用程序和其他应用程序在/tmp/中创建的。

nginx配置:

# HTTP server
server {
        listen   8080;
        server_name  wiki.qubmc.co.uk;

    root /var/www/qubmc.co.uk/wiki;
    index index.html index.php;
    client_body_timeout     60;

#    Exclude all access from the cache directory
  location ^~ /cache/ { deny all; }

#    Prevent access to any files starting with a dot, like .htaccess
#    or text editor temp files
  location ~ /\. { access_log off; log_not_found off; deny all; }

#    Prevent access to any files starting with a $ (usually temp files)
  location ~ ~$ { access_log off; log_not_found off; deny all; }

#    Do not log access to robots.txt, to keep the logs cleaner
  location = /robots.txt { access_log off; log_not_found off; }

#    Do not log access to the favicon, to keep the logs cleaner
  location = /favicon.ico { access_log off; log_not_found off; }

#    Keep images and CSS around in browser cache for as long as possible,
#    to cut down on server load
  location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
      try_files $uri /index.php;
      expires max;
      log_not_found off;
  }

#    Mark all of these directories as "internal", which means that they cannot
#    be explicitly accessed by clients. However, the web server can still use
#    and serve the files inside of them. This keeps people from poking around
#    in the wiki's internals.
  location ^~ /bin/ { internal; }
  location ^~ /docs/ { internal; }
  location ^~ /extensions/ { internal; }
  location ^~ /includes/ { internal; }
  location ^~ /maintenance/ { internal; }
#    location ^~ /mw-config/ { internal; } #Uncomment after installation
  location ^~ /resources/ { internal; }
  location ^~ /serialized/ { internal; }
  location ^~ /tests/ { internal; }

#    Force potentially-malicious files in the /images directory to be served
#    with a text/plain mime type, to prevent them from being executed by
#    the PHP handler
  location ~* ^/images/.*.(html|htm|shtml|php)$ {
      types { }
      default_type text/plain;
  }

#    Redirect all requests for unknown URLs out of images and back to the
#    root index.php file
  location ^~ /images/ {
      try_files $uri /index.php;
  }

  location ~ \.php5?$ {
      try_files $uri =404;
      include fastcgi_params;
      fastcgi_pass php-daemon;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      fastcgi_intercept_errors on;
  }

  location ~ \.php?$ {
      try_files $uri =404;
      include fastcgi_params;
      fastcgi_pass php-daemon;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      fastcgi_intercept_errors on;
  }
}

php。伊尼

[Session]
; Handler used to store/retrieve data.
; http://php.net/session.save-handler
session.save_handler = files

; Argument passed to save_handler.  In the case of files, this is the path
; where data files are stored. Note: Windows users have to change this
; variable in order to use PHP's session functions.
;
; The path can be defined as:
;
;     session.save_path = "N;/path"
;
; where N is an integer.  Instead of storing all the session files in
; /path, what this will do is use subdirectories N-levels deep, and
; store the session data in those directories.  This is useful if you
; or your OS have problems with lots of files in one directory, and is
; a more efficient layout for servers that handle lots of sessions.
;
; NOTE 1: PHP will not create this directory structure automatically.
;         You can use the script in the ext/session dir for that purpose.
; NOTE 2: See the section on garbage collection below if you choose to
;         use subdirectories for session storage
;
; The file storage module creates files using mode 600 by default.
; You can change that by using
;
;     session.save_path = "N;MODE;/path"
;
; where N is an integer.  Instead of storing all the session files in
; /path, what this will do is use subdirectories N-levels deep, and
; store the session data in those directories.  This is useful if you
; or your OS have problems with lots of files in one directory, and is
; a more efficient layout for servers that handle lots of sessions.
;
; NOTE 1: PHP will not create this directory structure automatically.
;         You can use the script in the ext/session dir for that purpose.
; NOTE 2: See the section on garbage collection below if you choose to
;         use subdirectories for session storage
;
; The file storage module creates files using mode 600 by default.
; You can change that by using
;
;     session.save_path = "N;MODE;/path"
;
; where MODE is the octal representation of the mode. Note that this
; does not overwrite the process's umask.
; http://php.net/session.save-path
session.save_path = /tmp/

; Whether to use cookies.
; http://php.net/session.use-cookies
session.use_cookies = 1

; http://php.net/session.cookie-secure
;session.cookie_secure =

; This option forces PHP to fetch and use a cookie for storing and maintaining
; the session id. We encourage this operation as it's very helpful in combatting
; session hijacking when not specifying and managing your own session id. It is
; not the end all be all of session hijacking defense, but it's a good start.
; http://php.net/session.use-only-cookies
session.use_only_cookies = 1

; Name of the session (used as cookie name).
; http://php.net/session.name
session.name = PHPSESSID

; Initialize session on request startup.
; http://php.net/session.auto-start
session.auto_start = 0

; Lifetime in seconds of cookie or, if 0, until browser is restarted.
; http://php.net/session.cookie-lifetime
session.cookie_lifetime = 0

; The path for which the cookie is valid.
; http://php.net/session.cookie-path
session.cookie_path = /

; The domain for which the cookie is valid.
; http://php.net/session.cookie-domain
session.cookie_domain =

; Whether or not to add the httpOnly flag to the cookie, which makes it inaccessible to browser scripting languages such as JavaScript.
; http://php.net/session.cookie-httponly
session.cookie_httponly =

; Handler used to serialize data.  php is the standard serializer of PHP.
; http://php.net/session.serialize-handler
session.serialize_handler = php

关于这一点的任何建议都非常谨慎,因为所有其他框架似乎都没有会话问题,这让我发疯。

应要求:

root@web:~# ls -ahl /tmp/
total 3.9M
drwxrwxrwx  5 root  root     3.0M Feb  4 15:56 .
drwxr-xr-x 26 root  root     4.0K Jan  3 11:46 ..
drwxrwxrwt  2 root  root     4.0K Jan  6 21:16 .ICE-unix
-rw-------  1 [webuser] www-data   65 Feb  4 15:06 sess_08sv9bc2ct47u0j2l3m3b77sa1
-rw-------  1 [webuser] www-data   64 Feb  4 12:09 sess_0gflq74v80c0cdsajevvr386r0
-rw-------  1 [webuser] www-data   65 Feb  4 14:38 sess_0ind5lrk1i1n3kgl8cboqpm5n4

root@web:~# ls -ahl /var/www/qubmc.co.uk/wiki/
total 840K
drwxr-xr-x 14 [webuser] www-data 4.0K Feb  4 12:17 .
drwxr-xr-x  5 [webuser] www-data 4.0K Oct 27 19:00 ..
-rw-r--r--  1 [webuser] www-data 3.8K Jan 28 00:06 api.php
-rw-r--r--  1 [webuser] www-data  916 Jan 28 00:06 api.php5
drwxr-xr-x  2 [webuser] www-data 4.0K Jan 28 00:06 cache

共有2个答案

商华藏
2023-03-14

我遇到了完全相同的问题。这只不过是没有提供正确的路径和文件夹不存在;还需要对文件夹的权限。

我的解决方案:

>

  • 在目录中创建一个包含WiKi文件的文件夹,并将其命名为tmp

    如果使用Windows,则为新文件夹设置权限。如果你用的是Mac,那就用777。

    我使用了一个直接路径F:\var\www\mediawiki-1.26。2\tmp\

    重新加载Apache并再次尝试WiKi安装。

  • 东典
    2023-03-14

    根据Aaron Schulz的说法,不要使用默认会话处理,这是灾难性的。当您在同一台机器上运行其他PHP应用程序时,会话文件也可能相互干扰。

    由于已启用OPCache,请添加

    $wgMainCacheType = CACHE_ACCEL;
    $wgSessionsInObjectCache = true;
    

    本地设置中。php并让我们知道事情是否有所改善(他们肯定应该这样做)。

     类似资料:
    • 我使用的是Ubuntu13,我安装了nginx和php5 fpm;在此之前,我安装了PHP5和apache;我把它拿走了 /etc/php5/fpm/pool.d/www.conf nginx配置文件: 当我尝试 http://local.host/info.php 它下载信息。php文件,而不是执行该文件 但当我尝试时: http://my.ip.address/info.php 它显示了函数

    • 我想做一个完全dockerizedDrupal安装。我的第一步是让容器运行Nginx和php5-fpm,两者都是基于Debian的。我在CoreOS alpha频道(使用数字海洋) 我的DockerFile如下所示: Nginx: 这个容器构建并运行良好。我在我的服务器ip上看到默认的Nginx页面。 php5-fpm: 这个容器也没有任何问题,并且在启动时保持运行。 我首先使用以下命令启动php

    • 问题内容: 我的主题有误。服务器负载不高:大约15%的CPU,有几个Gb的内存,HDD并不忙。但是错误502大约会引发3%的情况。 程序:Debian 6,nginx / 0.7.62,php5-fpm(5.3.3-1)。 在nginx的error.log中是此错误: php5-fpm的状态通常是这样的: 我认为,这意味着负载不高。 我增加了积压参数:在sysctl中-net.core.somax

    • 配置 Ubuntu服务器11.10 64位 亚马逊AWS,Ec2,云端托管 t1。微实例 在我写任何其他东西之前,我想声明我已经检查了nginx 502坏网关和nginx PHP-FPM 502坏网关线程,不幸的是,这在这方面对我没有帮助。 这个问题似乎很常见:nginx或php fpm的错误配置可能导致错误,这是我一直无法解决的问题。请注意,即使在我转到我的域根目录时,也会出现这种情况,而不指定

    • 我用Ired邮件和两个网站成功地运行了Ubuntu服务器20.04,其中一个是WordPress。 我想安装Nextcloud,为此我必须重新安装php fpm以生成php7。4-fpm。短袜在这之后,Nextcloud工作了,但是我的其他网站停止了工作,出现了错误“502坏网关”。 所以至少可以说,我很困惑! 我根据本文安装了Nextcloud并设置了启用的站点。符合说明的conf文件:http

    • 这是我的设置细节 Nginx。形态 默认情况下,我的conf文件包含可用站点和已启用站点 当我按我的域运行html文件时,它工作正常。 但如果我转到php文件,例如 它给出了nginx的502坏网关错误 出现问题时,Php5 fpm正在运行