lnmp部署服務器

前言:部署項目上線

1、把項目代碼放到服務器上,這個地方就有多種選擇(下次找時間按整理一下),這裏選擇使用svn來管理代碼

  • 可以自己分別安裝lnmp環境,也可以找一鍵安裝方式
  • svn的搭建,注意一下這裏有三個代碼版本,本地項目代碼a,服務器上的svn倉庫版本代碼b,服務器上的線上訪問的代碼c;原理是a拉去上傳到b,c進行更新,保持與b同步

2、 配置nginx

server
    {
        listen 8083;#監聽端口號
        server_name  _;#域名
        index index.html index.htm index.php;#默認打開文件
        root  /home/wwwroot/smartcloud/public;#網站根目錄

        #定義變量
        set $root /home/wwwroot/smartcloud/public;

        location ~ [^/]\.php(/|$)
        {
            try_files $uri =404;
            fastcgi_pass  unix:/tmp/php-cgi.sock;
            fastcgi_index index.php;
            #設置PATH_INFO
            fastcgi_split_path_info ^((?U).+.php)(/?.+)$;
            fastcgi_param PATH_INFO $fastcgi_path_info;
            fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
            fastcgi_param SCRIPT_FILENAME $root$fastcgi_script_name;
            #引入fastcgi配置
            include fastcgi.conf;
        }

        #從URL中去掉index.php入口文件
        location /
        {
            if (!-e $request_filename) {
                rewrite  ^(.*)$  /index.php?s=/$1  last;
                break;
            }
        }

        #error_page   404   /404.html;
        # Deny access to PHP files in specific directory
        #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
        include enable-php.conf;

        location /nginx_status
        {
            stub_status on;
            access_log   off;
        }

        #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
        include enable-php.conf;

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /.well-known {
            allow all;
        }

        location ~ /\.
        {
            deny all;
        }

        access_log  /home/wwwlogs/access.log;
    }

3、系統可能出現的問題

  • 被禁止訪問:access denied
    • 解決辦法: 打開php.ini 把以下cgi.fix_pathinfo=0 改爲1 保存退出重啓lnmp
  • 服務器500
    • 解決辦法 : 把php.ini中的display_errors=Off 改爲ON 保存退出重啓lnmp
  • open_basedir錯誤
    • 解決辦法: 找到nginx/conf/下的fastcgi.conf 文件 註釋掉最後一行
  • workman 可能出現的問題 啓動如果報錯的話 stream_socket_server 被禁用
    • 解決辦法 把php.ini中的 disable_functions 最後的stream_socket_server刪掉

4.數據庫導入

  • 先把mysql配置爲外網可訪問 或者直接在進入mysql導入數據庫
  • 數據庫端口防火牆設置
  • 創建一個只讀賬戶
	進入sql修改
    grant all privileges on *.* to '用戶名'@'%' identified by '密碼' with grant option;
	創建只讀用戶
	GRANT select ON *.* to 'read_user'@'%' identified by 'apld#$%666';
	創建所有權限
	GRANT all privileges ON *.* to 'root'@'%' identified by '746382';
	刷新權限
	flush privileges;
  • 使用新建的這個賬戶連接數據庫,進行導入導出操作

5、關於一些運行時目錄給予777權限,比如runtime

6、再次運行,部署成功後,建議在screen 裏面進行一個項目網站的維護

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章