1. XenForo 1.5.14 中文版——支持中文搜索!现已发布!查看详情
  2. Xenforo 爱好者讨论群:215909318 XenForo专区

Ubuntu低内存VPS架设Nginx+Php-Fpm+MariaDB+phpMyAdmin

本帖由 SHARED2014-02-16 发布。版面名称:应用交流

  1. SHARED

    SHARED VIP会员

    注册:
    2013-05-30
    帖子:
    37
    赞:
    9
    在lowendbox上看到一篇文章,讲的是如何在低内存的ubuntu上架设Nginx+Php-Fpm+MariaDB
    觉得不错收录下来,后面phpMyAdmin原文中是没有的。当然你还可以自行安装vsftpd。

    安装步骤如下:

    一、安装配置NGINX和PHP-FPM
    代码:
    sudo apt-get update
    sudo apt-get purge apache2* libapache2*
    sudo apt-get install nginx php5-fpm php5-mcrypt php5-curl
    打开 /etc/nginx/sites-available/default 文件看到如下内容
    代码:
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ .php$ {
    # fastcgi_split_path_info ^(.+.php)(/.+)$;
    # # NOTE: You should have “cgi.fix_pathinfo = 0;” in php.ini
    #
    # # With php5-cgi alone:
    # fastcgi_pass 127.0.0.1:9000;
    # # With php5-fpm:
    # fastcgi_pass unix:/var/run/php5-fpm.sock;
    # fastcgi_index index.php;
    # include fastcgi_params;
    #}
    修改为
    代码:
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ .php$ {
    fastcgi_split_path_info ^(.+.php)(/.+)$;
    # NOTE: You should have “cgi.fix_pathinfo = 0;” in php.ini
    
    # # With php5-cgi alone:
    # fastcgi_pass 127.0.0.1:9000;
    # With php5-fpm:
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    }
    打开 /etc/php5/fpm/pool.d/www.conf 文件

    代码:
    listen = 127.0.0.1:9000
    修改为
    代码:
    listen = /var/run/php5-fpm.sock
    之后重启php5-fpm和nginx
    代码:
    sudo service php5-fpm restart
    sudo service nginx restart
    二、安装配置MariaDB
    代码:
    sudo apt-get install python-software-properties
    sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
    sudo add-apt-repository 'deb http://ftp.osuosl.org/pub/mariadb/repo/10.0/ubuntu precise main'
    如果上面执行出现错误,请访问官网查找正确的命令。
    网站名称:MariaDB.org
    网站地址:https://downloads.mariadb.org/mariadb/repositories
    代码:
    sudo apt-get update
    sudo apt-get install mariadb-server php5-mysql
    返回的信息中会出现下面命令行中的版本提示「10.0.7」
    代码:
    sudo apt-get install mariadb-server libmysqlclient18=10.0.7+maria-1~precise mysql-common=10.0.7+maria-1~precise php5-mysql
    重启php5-fpm
    代码:
    sudo service php5-fpm restart
    三、安装配置phpMyAdmin
    代码:
    sudo apt-get install phpmyadmin
    之后选择lighttpd
    安装完成后执行
    代码:
    sudo ln -s /usr/share/phpmyadmin /usr/share/nginx/www
    四、nginx配置
    phpMyAdmin安装成功后你访问的话会出现403错误
    我们需要对nginx进行配置才能访问
    编辑 /etc/nginx/sites-available/default
    在server{}中添加
    代码:
    location /phpmyadmin/ {
    alias /usr/share/nginx/www/phpmyadmin/;
    index index.php;
    }
    我这里把WORDPRESS程序放在根目录/usr/share/nginx/www中了
    以此为例配置一下域名
    假使域名是 shared.cc
    在server{}中添加找到
    #listen 80; 去掉前面的#
    代码:
    listen 80;
    找到index index.html index.htm;
    添加修改为
    代码:
    index index.html index.php index.htm;
    找到server_name行修改为
    代码:
    server_name shared.cc www.shared.cc;
    修改
    代码:
    location / {
    # First attempt to serve request as file, then
    # as directory, then fall back to index.html
    try_files $uri $uri/ index.html;
    # Uncomment to enable naxsi on this location
    # include /etc/nginx/naxsi.rules
    }
    为(该规则适用于Wordpress)
    代码:
    location / {
    if (-d $request_filename){ rewrite ^/(.*)([^/])$ $1$2/ permanent; }
    if (-f $request_filename/index.html){ rewrite (.*) $1/index.hrml break; }
    if (-f $request_filename/index.php){ rewrite (.*) $1/index.php;}
    if (!-f $request_filename){ rewrite (.*) /index.php;}
    }
    五、重启NGINX
    代码:
    sudo service nginx restart
    转自分享地
    http://shared.cc/ubuntu-nginx-php-fpm-mariadb-phpmyadmin.html
     
    已获得 admin 的点赞。
正在加载...