Ubuntu部署tp項目和部署定時任務

1.前提是: 使用的是阿里雲的Ubuntu鏡像的服務器,系統搭建了lnmp環境,這個不多說網上教程找。。
nginx服務使用的時發行版本的,php使用php7.1.33, (sudo service php7.1-fpm restart
重啓php-fpm的方法)
在nginix.conf配置下打開一項擴展配置,這樣就不用都在nginx裏去配置項目了,

在這裏插入圖片描述
這樣會自動加載sites-enabled下的所有項目配置。。。。

開始部署:

把項目通過xshell或者putty等其他方式上傳到/var/www/目錄下,然後composer intsall…
配置nginx, 如果正式服務器也有138.rk.com這個域名的話,去解析下就可以,
本地測試現在host文件下添加

cd /etc/nginx/sites-available
vim  138.rk.com

複製一下內容:

server{
            listen 80;
            root /var/www/xxx/; //xxx--項目名
            index index.html index.php;  //加載文件順序
            server_name 138.rk.com;//虛擬域名
            client_max_body_size 200m;
            location / {
			//僞靜態
               if (!-e $request_filename) {
                        rewrite ^(.*)$ /index.php?s=$1 last;
                         #rewrite  ^(.*)$  /index.php/?/$1  last;
                         break;
                }
                 index  index.html index.htm index.php;
                try_files $uri $uri/ /index.php?$args;
                add_header Access-Control-Allow-Origin *;
                add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
                add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization,token,secretKey,ApiKey';

         }

            location ~ \.php$ {
            fastcgi_pass unix:/run/php/php7.1-fpm.sock;
            include snippets/fastcgi-php.conf;
            add_header Access-Control-Allow-Origin *;

            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
            add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization,token,secretKey,ApiKey';

        }
        access_log /var/log/nginx/api_access.log;
        error_log /var/log/nginx/api_error.log;

}

配置完成後保存。。。。 Esc Ctrl+zz 快捷鍵
然後軟連到/etc/nginx/sites-enabled

 ln -s /etc/nginx/sites-available/138.rk.com  /etc/nginx/sites-enabled/138.rk.com
 nginx -t //測試
 service nginx restart//重啓

2.導入數據庫

選擇數據庫 source +sql文件路徑 導入即可

先給項目中需要的操作權限給到指定文件夾
chmod -R 777 thinkphp/
runtime也給下 如果項目使用了緩存

查看下項目擴展是否開啓

php -m

沒有的話安裝需要的擴展即可

如果項目跑起來了

部署下定時任務即可。。。。

我這裏使用的sh文件

30  7  * * *  bash /var/www/xxx/crond.sh >> /tmp/crm.log 2>&1 

service cron restart
#!/bin/bash
PATH=/usr/local/php/bin:/opt/someApp/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
cd /var/www/xxx&&php think Task

這樣開發好的任務就可以定時去執行了

定時任務開發可以參考 定時任務開發

發佈了31 篇原創文章 · 獲贊 6 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章