{"id":1025,"date":"2025-01-18T12:02:33","date_gmt":"2025-01-18T04:02:33","guid":{"rendered":"https:\/\/www.laixuexila.com\/?p=1025"},"modified":"2025-01-18T12:02:33","modified_gmt":"2025-01-18T04:02:33","slug":"laravel-%e5%bc%80%e5%8f%91%e7%8e%af%e5%a2%83%e8%ae%be%e7%bd%ae%ef%bc%9a%e4%bb%8e%e5%ae%89%e8%a3%85%e5%88%b0%e9%85%8d%e7%bd%ae%ef%bc%8c%e5%bf%ab%e9%80%9f%e5%85%a5%e9%97%a8%e6%8c%87%e5%8d%97","status":"publish","type":"post","link":"https:\/\/www.laixuexila.com\/index.php\/2025\/01\/18\/laravel-%e5%bc%80%e5%8f%91%e7%8e%af%e5%a2%83%e8%ae%be%e7%bd%ae%ef%bc%9a%e4%bb%8e%e5%ae%89%e8%a3%85%e5%88%b0%e9%85%8d%e7%bd%ae%ef%bc%8c%e5%bf%ab%e9%80%9f%e5%85%a5%e9%97%a8%e6%8c%87%e5%8d%97\/","title":{"rendered":"Laravel \u5f00\u53d1\u73af\u5883\u8bbe\u7f6e\uff1a\u4ece\u5b89\u88c5\u5230\u914d\u7f6e\uff0c\u5feb\u901f\u5165\u95e8\u6307\u5357"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u5728\u5f00\u59cb Laravel \u5f00\u53d1\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u8bbe\u7f6e\u4e00\u4e2a\u9002\u5408\u7684\u5f00\u53d1\u73af\u5883\u3002Laravel \u662f\u57fa\u4e8e PHP \u7684\u6846\u67b6\uff0c\u56e0\u6b64\u4f60\u9700\u8981\u4e00\u4e9b\u57fa\u7840\u7684\u5f00\u53d1\u5de5\u5177\u548c\u73af\u5883\u914d\u7f6e\u3002\u4e0b\u9762\u662f\u8be6\u7ec6\u7684 <strong>Laravel \u5f00\u53d1\u73af\u5883\u8bbe\u7f6e<\/strong> \u6559\u7a0b\uff0c\u5e2e\u52a9\u4f60\u5feb\u901f\u5f00\u59cb\u5f00\u53d1\u3002<\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u5b89\u88c5 Composer<\/h3>\n\n\n\n<p>Laravel \u4f9d\u8d56\u4e8e Composer\uff0c\u8fd9\u662f\u4e00\u4e2a PHP \u7684\u4f9d\u8d56\u7ba1\u7406\u5de5\u5177\u3002\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u5b89\u88c5\u4e86 Composer\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u5b89\u88c5 Composer<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Windows<\/strong>: \u8bbf\u95ee <a href=\"https:\/\/getcomposer.org\/\">Composer \u5b98\u7f51<\/a> \u4e0b\u8f7d\u5e76\u5b89\u88c5\u3002<\/li>\n\n\n\n<li><strong>macOS<\/strong> \/ <strong>Linux<\/strong>:<br>\u6253\u5f00\u7ec8\u7aef\u5e76\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  curl -sS https:\/\/getcomposer.org\/installer | php\n  mv composer.phar \/usr\/local\/bin\/composer<\/code><\/pre>\n\n\n\n<p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u68c0\u67e5 Composer \u662f\u5426\u5b89\u88c5\u6210\u529f\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>composer --version<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u5b89\u88c5 PHP \u73af\u5883<\/h3>\n\n\n\n<p>Laravel \u9700\u8981 PHP 7.4 \u6216\u66f4\u9ad8\u7248\u672c\u3002\u5982\u679c\u4f60\u5df2\u7ecf\u5b89\u88c5\u4e86 PHP\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u68c0\u67e5 PHP \u7248\u672c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>php -v<\/code><\/pre>\n\n\n\n<p>\u5982\u679c\u6ca1\u6709\u5b89\u88c5 PHP\uff0c\u4f60\u53ef\u4ee5\u6309\u7167\u64cd\u4f5c\u7cfb\u7edf\u7684\u8981\u6c42\u5b89\u88c5\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Windows<\/strong>: \u5b89\u88c5 <a href=\"https:\/\/www.apachefriends.org\/zh_cn\/index.html\">XAMPP<\/a> \u6216 <a href=\"http:\/\/www.wampserver.com\/\">WAMP<\/a>\u3002<\/li>\n\n\n\n<li><strong>macOS<\/strong>: \u4f7f\u7528 <a href=\"https:\/\/brew.sh\/\">Homebrew<\/a> \u5b89\u88c5 PHP\uff1a<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  brew install php<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Linux<\/strong>:<br>\u901a\u8fc7\u5305\u7ba1\u7406\u5668\u5b89\u88c5 PHP\u3002\u4f8b\u5982\uff0c\u5728 Ubuntu \u4e0a\uff1a<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  sudo apt update\n  sudo apt install php php-cli php-fpm php-mbstring php-xml php-curl<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3. \u5b89\u88c5\u6570\u636e\u5e93<\/h3>\n\n\n\n<p>Laravel \u652f\u6301\u591a\u79cd\u6570\u636e\u5e93\uff0c\u5305\u62ec MySQL\u3001PostgreSQL\u3001SQLite \u548c SQL Server\u3002\u6839\u636e\u4f60\u9700\u8981\u7684\u6570\u636e\u5e93\u8fdb\u884c\u5b89\u88c5\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>MySQL<\/strong>:<\/li>\n\n\n\n<li><strong>Windows<\/strong>: \u5b89\u88c5 <a href=\"https:\/\/www.apachefriends.org\/zh_cn\/index.html\">XAMPP<\/a> \u6216 <a href=\"https:\/\/dev.mysql.com\/downloads\/installer\/\">MySQL Installer<\/a>.<\/li>\n\n\n\n<li><strong>macOS<\/strong>: \u4f7f\u7528 Homebrew \u5b89\u88c5\uff1a<br><code>bash brew install mysql<\/code><\/li>\n\n\n\n<li><strong>Linux<\/strong>: <code>sudo apt update sudo apt install mysql-server<\/code><\/li>\n\n\n\n<li><strong>SQLite<\/strong>: Laravel \u9ed8\u8ba4\u652f\u6301 SQLite\uff0c\u6240\u4ee5\u65e0\u9700\u989d\u5916\u5b89\u88c5\u6570\u636e\u5e93\uff0c\u53ea\u9700\u8981\u786e\u4fdd <code>php-sqlite3<\/code> \u6269\u5c55\u5df2\u542f\u7528\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">4. \u914d\u7f6e\u5f00\u53d1\u73af\u5883<\/h3>\n\n\n\n<p>Laravel \u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u6700\u5e38\u7528\u7684\u5de5\u5177\u662f <strong>Homestead<\/strong> \u548c <strong>Valet<\/strong>\uff0c\u8fd9\u4e24\u4e2a\u5de5\u5177\u7b80\u5316\u4e86\u5f00\u53d1\u73af\u5883\u7684\u8bbe\u7f6e\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">4.1 \u4f7f\u7528 Laravel Homestead<\/h4>\n\n\n\n<p>Laravel Homestead \u662f\u4e00\u4e2a\u5b98\u65b9\u7684 Vagrant \u5f00\u53d1\u73af\u5883\uff0c\u63d0\u4f9b\u4e86\u865a\u62df\u5316\u7684\u5f00\u53d1\u73af\u5883\uff0c\u9002\u7528\u4e8e Windows \u548c macOS \u7528\u6237\uff0cLinux \u7528\u6237\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u672c\u673a\u73af\u5883\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5b89\u88c5 <strong>Vagrant<\/strong> \u548c <strong>VirtualBox<\/strong>\uff08Homestead \u4f9d\u8d56\u8fd9\u4e9b\u5de5\u5177\uff09\uff1a<\/li>\n\n\n\n<li><a href=\"https:\/\/www.vagrantup.com\/\">Vagrant \u4e0b\u8f7d<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.virtualbox.org\/\">VirtualBox \u4e0b\u8f7d<\/a><\/li>\n\n\n\n<li>\u5b89\u88c5 Homestead<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  vagrant box add laravel\/homestead<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u521d\u59cb\u5316 Homestead<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  vagrant init laravel\/homestead<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u914d\u7f6e Homestead\uff1a\u4fee\u6539 <code>Homestead.yaml<\/code> \u914d\u7f6e\u6587\u4ef6\uff0c\u8bbe\u7f6e\u5171\u4eab\u6587\u4ef6\u5939\u548c\u865a\u62df\u673a\u7684\u7aef\u53e3\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">4.2 \u4f7f\u7528 Laravel Valet<\/h4>\n\n\n\n<p>\u5982\u679c\u4f60\u662f macOS \u7528\u6237\uff0cLaravel Valet \u63d0\u4f9b\u4e86\u4e00\u4e2a\u7b80\u5355\u5feb\u901f\u7684\u5f00\u53d1\u73af\u5883\uff0c\u5b83\u901a\u8fc7\u5c06\u4f60\u673a\u5668\u4e0a\u7684\u672c\u5730\u5f00\u53d1\u9879\u76ee\u7ed1\u5b9a\u5230 <code>.test<\/code> \u57df\u540d\u6765\u5de5\u4f5c\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5b89\u88c5 Valet\uff1a<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  composer global require laravel\/valet\n  valet install<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5728\u4f60\u672c\u5730\u7684\u5de5\u4f5c\u76ee\u5f55\u4e2d\u521b\u5efa\u4e00\u4e2a Laravel \u9879\u76ee\u5e76\u542f\u7528 Valet\uff1a<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  cd ~\/Sites\n  valet park<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u521b\u5efa\u4e00\u4e2a\u65b0\u7684 Laravel \u9879\u76ee\uff1a<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  composer create-project --prefer-dist laravel\/laravel blog<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5728\u6d4f\u89c8\u5668\u4e2d\u8bbf\u95ee\u9879\u76ee\uff1a<br>\u8bbf\u95ee <code>http:\/\/blog.test<\/code>\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">5. \u5b89\u88c5 Laravel<\/h3>\n\n\n\n<p>\u73b0\u5728\u4f60\u5df2\u7ecf\u5b89\u88c5\u597d\u4e86 PHP \u548c\u6570\u636e\u5e93\u73af\u5883\uff0c\u63a5\u4e0b\u6765\u5b89\u88c5 Laravel\u3002\u4f60\u53ef\u4ee5\u9009\u62e9\u901a\u8fc7 Composer \u6765\u5168\u5c40\u5b89\u88c5 Laravel \u6216\u8005\u76f4\u63a5\u521b\u5efa\u65b0\u9879\u76ee\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">5.1 \u5b89\u88c5 Laravel \u901a\u8fc7 Composer<\/h4>\n\n\n\n<p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u521b\u5efa\u4e00\u4e2a\u65b0\u7684 Laravel \u9879\u76ee\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>composer create-project --prefer-dist laravel\/laravel your-project-name<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">5.2 \u5b89\u88c5 Laravel \u4f7f\u7528 Laravel Installer\uff08\u53ef\u9009\uff09<\/h4>\n\n\n\n<p>\u5982\u679c\u4f60\u5b89\u88c5\u4e86 Laravel Installer\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u521b\u5efa\u65b0\u9879\u76ee\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>composer global require laravel\/installer\nlaravel new your-project-name<\/code><\/pre>\n\n\n\n<p>\u786e\u4fdd\u5c06 Composer \u7684 <code>bin<\/code> \u76ee\u5f55\u6dfb\u52a0\u5230\u7cfb\u7edf\u7684 <code>PATH<\/code> \u73af\u5883\u53d8\u91cf\u4e2d\u3002\u4f60\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u4e2d\u8fd0\u884c <code>laravel<\/code> \u547d\u4ee4\u6765\u521b\u5efa\u65b0\u7684\u9879\u76ee\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">6. \u914d\u7f6e .env \u6587\u4ef6<\/h3>\n\n\n\n<p>Laravel \u4f7f\u7528 <code>.env<\/code> \u6587\u4ef6\u6765\u7ba1\u7406\u73af\u5883\u53d8\u91cf\u3002\u8fd9\u4e2a\u6587\u4ef6\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\uff0c\u5305\u542b\u4e86\u6570\u636e\u5e93\u914d\u7f6e\u3001\u5e94\u7528\u5bc6\u94a5\u3001\u8c03\u8bd5\u6a21\u5f0f\u7b49\u4fe1\u606f\u3002\u5e38\u89c1\u914d\u7f6e\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>APP_NAME=Laravel\nAPP_ENV=local\nAPP_KEY=base64:yourkeyhere\nAPP_DEBUG=true\nAPP_URL=http:\/\/localhost\n\nDB_CONNECTION=mysql\nDB_HOST=127.0.0.1\nDB_PORT=3306\nDB_DATABASE=laravel\nDB_USERNAME=root\nDB_PASSWORD=<\/code><\/pre>\n\n\n\n<p>\u786e\u4fdd\u6839\u636e\u4f60\u7684\u5f00\u53d1\u73af\u5883\u4fee\u6539 <code>.env<\/code> \u6587\u4ef6\u4e2d\u7684\u914d\u7f6e\uff0c\u7279\u522b\u662f\u6570\u636e\u5e93\u8fde\u63a5\u4fe1\u606f\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">7. \u8fd0\u884c\u5f00\u53d1\u670d\u52a1\u5668<\/h3>\n\n\n\n<p>\u5b89\u88c5\u5b8c Laravel \u540e\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7 Laravel \u63d0\u4f9b\u7684 Artisan \u547d\u4ee4\u6765\u542f\u52a8\u5f00\u53d1\u670d\u52a1\u5668\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>php artisan serve<\/code><\/pre>\n\n\n\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cLaravel \u7684\u5f00\u53d1\u670d\u52a1\u5668\u5c06\u8fd0\u884c\u5728 <code>http:\/\/localhost:8000<\/code>\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">8. \u7ed3\u8bed<\/h3>\n\n\n\n<p>\u8bbe\u7f6e Laravel \u5f00\u53d1\u73af\u5883\u901a\u5e38\u6d89\u53ca\u5b89\u88c5 PHP\u3001Composer\u3001\u6570\u636e\u5e93\u3001\u5f00\u53d1\u5de5\u5177\uff08\u5982 Homestead \u6216 Valet\uff09\u7b49\u3002\u901a\u8fc7\u8fd9\u4e9b\u6b65\u9aa4\uff0c\u4f60\u53ef\u4ee5\u5feb\u901f\u5730\u642d\u5efa\u4e00\u4e2a Laravel \u9879\u76ee\u5e76\u5f00\u59cb\u5f00\u53d1\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u5f00\u59cb Laravel \u5f00\u53d1\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u8bbe\u7f6e\u4e00\u4e2a\u9002\u5408\u7684\u5f00\u53d1\u73af\u5883\u3002Laravel \u662f\u57fa\u4e8e PHP \u7684\u6846\u67b6\uff0c\u56e0\u6b64 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[62],"tags":[],"class_list":["post-1025","post","type-post","status-publish","format-standard","hentry","category-laravel"],"_links":{"self":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/1025","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/comments?post=1025"}],"version-history":[{"count":1,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/1025\/revisions"}],"predecessor-version":[{"id":1026,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/1025\/revisions\/1026"}],"wp:attachment":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/media?parent=1025"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/categories?post=1025"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/tags?post=1025"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}