{"id":22347,"date":"2024-11-21T13:54:48","date_gmt":"2024-11-21T05:54:48","guid":{"rendered":"https:\/\/fwq.ai\/blog\/22347\/"},"modified":"2024-11-21T13:54:48","modified_gmt":"2024-11-21T05:54:48","slug":"%e5%a6%82%e4%bd%95%e5%b0%86laravel%e9%83%a8%e7%bd%b2%e5%88%b0linux%e6%9c%8d%e5%8a%a1%e5%99%a8%e4%b8%8a","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/22347\/","title":{"rendered":"\u5982\u4f55\u5c06Laravel\u90e8\u7f72\u5230Linux\u670d\u52a1\u5668\u4e0a"},"content":{"rendered":"<p>laravel\u662f\u4e00\u4e2a\u57fa\u4e8ephp\u7684mvc\u6846\u67b6\uff0c\u5b83\u63d0\u4f9b\u4e86\u8bb8\u591a\u4f18\u79c0\u7684\u529f\u80fd\u548c\u5de5\u5177\uff0c\u4f7f\u5f97web\u5e94\u7528\u7a0b\u5e8f\u7684\u5f00\u53d1\u53d8\u5f97\u66f4\u52a0\u5bb9\u6613\u548c\u9ad8\u6548\u3002\u5bf9\u4e8elaravel\u5f00\u53d1\u4eba\u5458\u800c\u8a00\uff0c\u90e8\u7f72laravel\u5e94\u7528\u7a0b\u5e8f\u662f\u81f3\u5173\u91cd\u8981\u7684\u4e00\u6b65\u3002\u5728\u6b64\uff0c\u7b14\u8005\u5c06\u4ecb\u7ecd\u5982\u4f55\u5c06laravel\u90e8\u7f72\u5230linux\u670d\u52a1\u5668\u4e0a\u3002<\/p>\n<p>\u4e00\u3001\u73af\u5883\u914d\u7f6e<\/p>\n<p>\u5728\u90e8\u7f72Laravel\u5e94\u7528\u7a0b\u5e8f\u4e4b\u524d\uff0c\u6211\u4eec\u9700\u8981\u786e\u4fdd\u670d\u52a1\u5668\u4e0a\u5df2\u7ecf\u5b89\u88c5\u4e86\u5fc5\u8981\u7684\u8f6f\u4ef6\u3002\u4e0b\u9762\u662f\u5b89\u88c5\u5fc5\u8981\u8f6f\u4ef6\u7684\u6b65\u9aa4\uff1a<\/p>\n<p>1.\u5b89\u88c5PHP<\/p>\n<p>\u5728Linux\u670d\u52a1\u5668\u4e0a\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5PHP\uff1a<\/p>\n<pre>sudo apt install php-fpm php-mysql php-curl php-mbstring php-xml php-zip<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>2.\u5b89\u88c5Web\u670d\u52a1\u5668<\/p>\n<p>Laravel\u5e94\u7528\u7a0b\u5e8f\u9700\u8981\u8fd0\u884c\u5728Web\u670d\u52a1\u5668\u4e0a\uff0c\u8fd9\u91cc\u6211\u4eec\u9009\u62e9Nginx\u3002<\/p>\n<p>\u5728Linux\u670d\u52a1\u5668\u4e0a\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5Nginx\uff1a<\/p>\n<pre>sudo apt install nginx<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>3.\u5b89\u88c5\u6570\u636e\u5e93<\/p>\n<p>Laravel\u652f\u6301\u591a\u79cd\u6570\u636e\u5e93\uff0c\u4f8b\u5982MySQL\u3001PostgreSQL\u3001SQLite\u7b49\u3002\u8fd9\u91cc\u6211\u4eec\u9009\u62e9MySQL\u4f5c\u4e3a\u6570\u636e\u5e93\u3002<\/p>\n<p>\u5728Linux\u670d\u52a1\u5668\u4e0a\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5MySQL\uff1a<\/p>\n<pre>sudo apt install mysql-server<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4e8c\u3001\u4e0a\u4f20Laravel\u5e94\u7528\u7a0b\u5e8f<\/p>\n<p>\u5728\u5b89\u88c5\u5b8c\u5fc5\u8981\u7684\u8f6f\u4ef6\u4e4b\u540e\uff0c\u6211\u4eec\u9700\u8981\u5c06Laravel\u5e94\u7528\u7a0b\u5e8f\u4e0a\u4f20\u5230\u670d\u52a1\u5668\u3002\u53ef\u4ee5\u901a\u8fc7FTP\u6216\u8005\u4f7f\u7528SCP\u7b49\u5de5\u5177\u8fdb\u884c\u6587\u4ef6\u4f20\u8f93\u3002<\/p>\n<p>\u5c06\u6240\u6709\u7684Laravel\u6587\u4ef6\u590d\u5236\u5230\u670d\u52a1\u5668\u4e0a\u7684\/var\/www\/laravel\u76ee\u5f55\u3002<\/p>\n<p>\u4e09\u3001\u914d\u7f6eNginx<\/p>\n<p>\u914d\u7f6eNginx\u662f\u5f88\u5173\u952e\u7684\u4e00\u6b65\uff0c\u56e0\u4e3aNginx\u9700\u8981\u5c06\u8bf7\u6c42\u4f20\u9012\u5230\u6b63\u786e\u7684\u6587\u4ef6\u5939\u4e0b\u3002<\/p>\n<p>1.\u5728Nginx\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\u8bbe\u7f6eLaravel\u5e94\u7528\u7a0b\u5e8f\u7684\u6839\u76ee\u5f55\u3002<\/p>\n<p>\u6253\u5f00Nginx\u7684\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n<pre>sudo nano \/etc\/nginx\/sites-available\/default<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5c06\u4e0b\u9762\u7684\u4ee3\u7801\u590d\u5236\u5230server\u7684\u5757\u4e2d\uff1a<\/p>\n<pre>root \/var\/www\/laravel\/public;\n\nlocation \/ {\n    try_files $uri $uri\/ \/index.php?$query_string;\n}\n\nlocation ~ .php$ {\n    fastcgi_split_path_info ^(.+.php)(\/.+)$;\n    fastcgi_pass unix:\/run\/php\/php7.4-fpm.sock;\n    fastcgi_index index.php;\n    include fastcgi_params;\n    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\n    fastcgi_param PATH_INFO $fastcgi_path_info;\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>2.\u91cd\u542fNginx<\/p>\n<p>\u91cd\u542fNginx\uff1a<\/p>\n<pre>sudo service nginx restart<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u56db\u3001\u914d\u7f6e\u6570\u636e\u5e93<\/p>\n<p>\u8981\u4f7fLaravel\u5e94\u7528\u7a0b\u5e8f\u80fd\u591f\u8bbf\u95eeMySQL\u6570\u636e\u5e93\uff0c\u9700\u8981\u8fdb\u884c\u76f8\u5e94\u7684\u914d\u7f6e\u3002<\/p>\n<p>\u6253\u5f00Laravel\u5e94\u7528\u7a0b\u5e8f\u6839\u76ee\u5f55\u4e0b\u7684.env\u6587\u4ef6\uff1a<\/p>\n<pre>nano \/var\/www\/laravel\/.env<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5c06\u4ee5\u4e0b\u4fe1\u606f\u586b\u5165.env\u6587\u4ef6\uff1a<\/p>\n<pre>DB_HOST=localhost\nDB_DATABASE=database_name\nDB_USERNAME=username\nDB_PASSWORD=password<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5c06\u6570\u636e\u5e93\u540d\u79f0\u3001\u7528\u6237\u540d\u548c\u5bc6\u7801\u66ff\u6362\u4e3a\u4f60\u5b9e\u9645\u4f7f\u7528\u7684\u4fe1\u606f\u3002<\/p>\n<p>\u4e94\u3001\u8fd0\u884cLaravel\u5e94\u7528\u7a0b\u5e8f<\/p>\n<p>\u5b8c\u6210\u4ee5\u4e0a\u6b65\u9aa4\u540e\uff0c\u6211\u4eec\u5df2\u7ecf\u6210\u529f\u5c06Laravel\u5e94\u7528\u7a0b\u5e8f\u90e8\u7f72\u5230Linux\u670d\u52a1\u5668\u4e0a\u3002<\/p>\n<p>\u5728\u6d4f\u89c8\u5668\u4e2d\u8f93\u5165\u670d\u52a1\u5668\u7684IP\u5730\u5740\u6216\u57df\u540d\u5373\u53ef\u8bbf\u95eeLaravel\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<p>\u603b\u7ed3<\/p>\n<p>\u90e8\u7f72Laravel\u5230Linux\u670d\u52a1\u5668\u4e0a\u9700\u8981\u8fdb\u884c\u4e00\u7cfb\u5217\u7684\u914d\u7f6e\u6b65\u9aa4\uff0c\u6d89\u53ca\u5230Nginx\u3001PHP\u548cMySQL\u7b49\u7ec4\u4ef6\u3002\u8fd9\u7bc7\u6587\u7ae0\u4ecb\u7ecd\u4e86\u4ece\u73af\u5883\u914d\u7f6e\u5230Laravel\u5e94\u7528\u7a0b\u5e8f\u4e0a\u4f20\u548c\u914d\u7f6e\u7684\u8be6\u7ec6\u6b65\u9aa4\u3002\u5e0c\u671b\u5bf9\u9700\u8981\u5728Linux\u670d\u52a1\u5668\u4e0a\u90e8\u7f72Laravel\u5e94\u7528\u7a0b\u5e8f\u7684\u5f00\u53d1\u4eba\u5458\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5c06Laravel\u90e8\u7f72\u5230Linux\u670d\u52a1\u5668\u4e0a\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>laravel\u662f\u4e00\u4e2a\u57fa\u4e8ephp\u7684mvc\u6846\u67b6\uff0c\u5b83\u63d0\u4f9b\u4e86\u8bb8\u591a\u4f18\u79c0\u7684\u529f\u80fd\u548c\u5de5\u5177\uff0c\u4f7f\u5f97web\u5e94\u7528\u7a0b\u5e8f\u7684\u5f00\u53d1\u53d8\u5f97\u66f4\u52a0\u5bb9\u6613\u548c\u9ad8\u6548\u3002\u5bf9\u4e8elaravel\u5f00\u53d1\u4eba\u5458\u800c\u8a00\uff0c\u90e8\u7f72laravel\u5e94\u7528\u7a0b\u5e8f\u662f\u81f3\u5173\u91cd\u8981\u7684\u4e00\u6b65\u3002\u5728\u6b64\uff0c\u7b14\u8005\u5c06\u4ecb\u7ecd\u5982\u4f55\u5c06laravel\u90e8\u7f72\u5230linux\u670d\u52a1\u5668\u4e0a\u3002 \u4e00\u3001\u73af\u5883\u914d\u7f6e \u5728\u90e8\u7f72Laravel\u5e94\u7528\u7a0b\u5e8f\u4e4b\u524d\uff0c\u6211\u4eec\u9700\u8981\u786e\u4fdd\u670d\u52a1\u5668\u4e0a\u5df2\u7ecf\u5b89\u88c5\u4e86\u5fc5\u8981\u7684\u8f6f\u4ef6\u3002\u4e0b\u9762\u662f\u5b89\u88c5\u5fc5\u8981\u8f6f\u4ef6\u7684\u6b65\u9aa4\uff1a 1.\u5b89\u88c5PHP \u5728Linux\u670d\u52a1\u5668\u4e0a\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5PHP\uff1a sudo apt install php-fpm php-mysql php-curl php-mbstring php-xml php-zip \u767b\u5f55\u540e\u590d\u5236 2.\u5b89\u88c5Web\u670d\u52a1\u5668 Laravel\u5e94\u7528\u7a0b\u5e8f\u9700\u8981\u8fd0\u884c\u5728Web\u670d\u52a1\u5668\u4e0a\uff0c\u8fd9\u91cc\u6211\u4eec\u9009\u62e9Nginx\u3002 \u5728Linux\u670d\u52a1\u5668\u4e0a\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5Nginx\uff1a sudo apt install nginx \u767b\u5f55\u540e\u590d\u5236 3.\u5b89\u88c5\u6570\u636e\u5e93 Laravel\u652f\u6301\u591a\u79cd\u6570\u636e\u5e93\uff0c\u4f8b\u5982MySQL\u3001PostgreSQL\u3001SQLite\u7b49\u3002\u8fd9\u91cc\u6211\u4eec\u9009\u62e9MySQL\u4f5c\u4e3a\u6570\u636e\u5e93\u3002 \u5728Linux\u670d\u52a1\u5668\u4e0a\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5MySQL\uff1a sudo apt install mysql-server \u767b\u5f55\u540e\u590d\u5236 \u4e8c\u3001\u4e0a\u4f20Laravel\u5e94\u7528\u7a0b\u5e8f \u5728\u5b89\u88c5\u5b8c\u5fc5\u8981\u7684\u8f6f\u4ef6\u4e4b\u540e\uff0c\u6211\u4eec\u9700\u8981\u5c06Laravel\u5e94\u7528\u7a0b\u5e8f\u4e0a\u4f20\u5230\u670d\u52a1\u5668\u3002\u53ef\u4ee5\u901a\u8fc7FTP\u6216\u8005\u4f7f\u7528SCP\u7b49\u5de5\u5177\u8fdb\u884c\u6587\u4ef6\u4f20\u8f93\u3002 \u5c06\u6240\u6709\u7684Laravel\u6587\u4ef6\u590d\u5236\u5230\u670d\u52a1\u5668\u4e0a\u7684\/var\/www\/laravel\u76ee\u5f55\u3002 \u4e09\u3001\u914d\u7f6eNginx \u914d\u7f6eNginx\u662f\u5f88\u5173\u952e\u7684\u4e00\u6b65\uff0c\u56e0\u4e3aNginx\u9700\u8981\u5c06\u8bf7\u6c42\u4f20\u9012\u5230\u6b63\u786e\u7684\u6587\u4ef6\u5939\u4e0b\u3002 1.\u5728Nginx\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\u8bbe\u7f6eLaravel\u5e94\u7528\u7a0b\u5e8f\u7684\u6839\u76ee\u5f55\u3002 \u6253\u5f00Nginx\u7684\u914d\u7f6e\u6587\u4ef6\uff1a sudo nano \/etc\/nginx\/sites-available\/default \u767b\u5f55\u540e\u590d\u5236 \u5c06\u4e0b\u9762\u7684\u4ee3\u7801\u590d\u5236\u5230server\u7684\u5757\u4e2d\uff1a root \/var\/www\/laravel\/public; location \/ { try_files $uri $uri\/ \/index.php?$query_string; } location ~ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-22347","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/22347","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=22347"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/22347\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=22347"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=22347"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=22347"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}