现在我需要在 Ubuntu 18.4 上为 PHP 7.3 安装 memcached 包。我有服务器 nginx、Yii2 框架和服务器块,但是无法工作。
我该怎么做?
server {
listen 80;
server_name dev.advanced.ru;
set $base_root /www/dev.advanced.ru;
root $base_root;
error_log /var/log/nginx/advanced.local.error.log warn;
access_log /var/log/nginx/advanced.local.access.log main;
charset UTF-8;
index index.php index.html;
location / {
root $base_root/frontend/web;
set $memcached_key "$uri?$args";
memcached_pass 127.0.0.1:11211;
error_page 404 502 504 = @fallback;
try_files $uri $uri/ /frontend/web/index.php$is_args$args;
location ~ ^/assets/.+\.php(/|$) {
deny all;
}
}
location /admin {
alias $base_root/backend/web/;
location = /admin {
try_files $uri /backend/web/index.php$is_args$args;
}
try_files $uri $uri/ /backend/web/index.php$is_args$args;
location ~ ^/admin/assets/.+\.php(/|$) {
deny all;
}
}
location ~ ^/.+\.php(/|$) {
rewrite (?!^/((frontend|backend)/web|admin))^ /frontend/web$uri break;
rewrite (?!^/backend/web)^/admin(/.+)$ /backend/web$1 break;
fastcgi_pass 127.0.0.1:9000; # proxy requests to a TCP socket
#fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(.*)$;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
try_files $fastcgi_script_name =404;
}
location ~ /\. {
deny all;
}
location @fallback {
proxy_pass http://admin;
}
}
答案1
您是否已在系统上成功安装 PHP Memcached 模块?如果没有:
sudo apt-get install -y php-memcached
此外,请记得在安装/更新完所有内容后重新启动 Apache 服务
sudo service apache2 restart
答案2
sudo apt-get install php7.1-dev (7.2, 7.3)
要求
sudo apt-get update
sudo apt-get install build-essential pkg-config make git g++ gcc
设置
sudo apt-get install libmemcached-dev libmsgpack-dev libmsgpackc2
clone and build php-memcached
git clone --depth 1 https://github.com/php-memcached-dev/php-memcached.git
cd php-memcached
phpize
./configure
make
sudo mv modules/ /usr/local/memcached/
使能够
echo 'extension=/usr/local/memcached/memcached.so' | \
sudo tee /etc/php/7.1/cli/conf.d/memcached.ini
echo 'extension=/usr/local/memcached/memcached.so' | \
sudo tee /etc/php/7.1/fpm/conf.d/memcached.ini
核实
php -m | grep "memcached" && php-fpm7.1 -m | grep "memcached"
Restart PHP-FPM
sudo systemctl status php7.1-fpm.service