twn39 / code

:memo: 代码笔记,通过 issue 的方式记录日常遇到的问题和学习笔记
13 stars 1 forks source link

lemp #22

Open twn39 opened 9 years ago

twn39 commented 9 years ago

lemp stack

twn39 commented 9 years ago

Nginx

安装nginx:

sudo apt-get update
sudo apt-get install nginx
twn39 commented 9 years ago

MySQL

安装 Mysql

sudo apt-get install mysql-server mysql-client

安装数据库结构:

sudo mysql_install_db

进行一些安全设置:

sudo mysql_secure_installation
twn39 commented 9 years ago

PHP

安装php:

sudo apt-get install php5-fpm php5-mysql php5-cli

配置php进程

sudo nano /etc/php5/fpm/php.ini

cgi.fix_pathinfo设置为0

cgi.fix_pathinfo=0
sudo service php5-fpm restart

配置nginx与php:

sudo nano /etc/nginx/sites-available/default
server {
    listen 80;

    root /usr/share/nginx/html;
    index index.php index.html index.htm;

    server_name localhost;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}
sudo service nginx restart
twn39 commented 9 years ago

添加PHP 扩展

sudo apt-get install php5-curl php5-mcrypt php5-intl php5-apcu php5-redis php5-memcached php5-mongo
sudo php5enmod mcrypt
twn39 commented 9 years ago

配置域名

新建目录

/var/www下新建站点目录:

sudo mkdir -p /var/www/example.com/html

赋予权限:

sudo chown -R $USER:$USER /var/www/example.com/html
sudo chmod -R 755 /var/www

配置文件

sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/example.com

example.com

server {
    listen 80;

    root /var/www/example.com/html;
    index index.php index.html index.htm;

    server_name example.com www.example.com;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /var/www/example.com/html;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

启用站点:

sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/

移除默认站点:

sudo rm /etc/nginx/sites-enabled/default

配置:

sudo nano /etc/nginx/nginx.conf
server_names_hash_bucket_size 64;
sudo service nginx restart

更改hosts

twn39 commented 8 years ago

for php7.0 on Ubuntu 16.04 LTS

server {
    listen 80;

    root /usr/share/nginx/html/light;
    index index.php index.html index.htm;

    server_name light.dev;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}
twn39 commented 6 years ago
        gzip on;

         gzip_vary on;
         gzip_proxied any;
         gzip_comp_level 6;
         gzip_buffers 16 8k;
         gzip_http_version 1.1;
         gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;