Home »  Linux » LNMP环境搭建

LNMP环境搭建

@(示例笔记本)[nginx|php|linux]

辅助工具

sudo apt-get install vim curl zsh

LNMP安装

sudo apt-get install nginx php5 php5-xdebug php5-gd php5-curl php5-memcached php5-mysql php5-fpm mysql-server mysql-client php-pear redis-server

升级 PHP 到 5.4

sudo apt-get update && sudo apt-get install python-software-properties

sudo add-apt-repository ppa:ondrej/php5-oldstable

sudo apt-get update && sudo apt-get dist-upgrade

安php-redis 扩展

pecl install redis

php.ini中加入配置

>两个文件 /etc/php5/fpm/php.ini and /etc/php5/cli/php.ini

extensition=redis.so

安装 memcached [按需要安装saas环境目前已经不需要]

sudo apt-get install memcached

安装依赖

mkdir ~/bin

curl -sS https://getcomposer.org/installer | php -- --install-dir=/home/mtao/bin

配置 Nginx

server {
    server_name www.mtao.aysaas.com;

    root /home/mtao/project/saas/public;

    error_log /var/log/nginx/www.mtao.aysaas.com-error.log error;

    access_log /var/log/nginx/www.mtao.aysaas.com-access.log combined;

    location /global/svgweb/ {
        break;
    }
    
    location /global/jquery/extend/uploadify/ {
        break;
    }

    location /global/pdf2swf/ {
        break;
    }

    location /form/render/ueditor/ {
        break;
    }

    location /favicon.ico {
        break;
        access_log off;
        log_not_found off;
    }

    location / {
        rewrite . /index.php;
    }

    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

server {
    server_name static.mtao.aysaas.com;

    root /home/mtao/project/saas/public;

    location ~* \.(eot|ttf|woff)$ {
        add_header Access-Control-Allow-Origin *;
    }
    location / {
        access_log off;
    }

    location ~ \.php$ {
        deny all;
    }
}

server {
    server_name fileio.mtao.aysaas.com;

    root /home/mtao/project/saas/public;

    error_log /var/log/nginx/www.mtao.aysaas.com-error.log error;

    access_log /var/log/nginx/www.mtao.aysaas.com-access.log combined;

    client_max_body_size 64m;

    location /crossdomain.xml {
        break;
    }

    location / {
        rewrite . /index.php;
    }

    location ~ \.php$ {
        fastcgi_pass    127.0.0.1:9000;
        fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include         fastcgi_params;
    }
}
server {
    server_name www.jmt.com;

    root /home/mtao/project/test;
    ##autoindex on;
    location / {
        ##autoindex on;
        index index.php index.html;
    }

    ## location ~ \.php$ {
    ##     fastcgi_pass   127.0.0.1:9000;
    ##     fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    ##     include        fastcgi_params;
    ## }

    location ~ ^(?<script>.+\.php)(?<path_info>.*)$ { ## 匹配  index.php/user
        include fastcgi_params;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$script;
        fastcgi_param SCRIPT_NAME $script;
        fastcgi_param PATH_INFO $path_info;
        fastcgi_pass 127.0.0.1:9000;
    }
}

启用配置

sudo ln -s /etc/nginx/sites-available/www.mtao.aysaas.com /etc/nginx/sites-enabled/

重启nginx

sudo /etc/init.d/nginx restart

添加 hosts

127.0.0.1 www.mtao.aysaas.com
127.0.0.1 static.mtao.aysaas.com
127.0.0.1 fileio.mtao.aysaas.com

说明

请把以上配置中的 mtao 替换成你实际的用户名

配置 PHP

修改 /etc/php5/fpm/php.ini 的以下配置

error_reporting = E_ALL
display_errors = On
html_errors = On
date.timezone = Asia/Shanghai

修改 /etc/php5/fpm/pool.d/www.conf 的以下配置

listen = 127.0.0.1:9000

重启 php-fpm

sudo /etc/init.d/php5-fpm restart

fileio 本地测试

在项目根目录建立相 upload 目录,及赋予相应的读写权限

cd ~/workspace/project/saas
mkdir upload
chmod 777 upload

队列(非必须)

安装

sudo apt-get install ruby1.9.3
sudo gem install resque
sudo apt-get install redis-server
resque-web -N AYSaaS

>访问 http://0.0.0.0:5678 可以查看队列状态

启动 worker

本地开发

VVERBOSE=1 QUEUE=* APP_INCLUDE=bootstrap.php php vendor/chrisboulton/php-resque/resque.php

服务器

sudo su -l www-data -c 'cd /var/www/project_path && ENV=production QUEUE=* APP_INCLUDE=bootstrap.php nohup php vendor/chrisboulton/php-resque/resque.php > log/queue.log 2>&1 &'

文档预览

依赖

sudo apt-get install libjpeg-dev libgif-dev libfreetype6-dev ttf-wqy-microhei ttf-wqy-zenhei

转换doc->pdf 安装 libreOffice (ubuntu 桌面版默认已经装好)

sudo apt-get install libreOffice

转换pdf->swf 安装 swftools

sudo add-apt-repository ppa:guilhem-fr/swftools
sudo apt-get update
sudo apt-get install swftools