Laravel以其优雅的语法和开发人员友好的功能而闻名,使其成为构建Web应用程序的绝佳选择。另一方面,Manjaro Linux为开发人员提供了一个用户友好且功能强大的环境。
在曼扎罗山上安装 Laravel(英语:Laravel
第 1 步。在运行以下教程之前,请确保我们的系统是最新的:
<span class="pln">sudo pacman </span><span class="pun">-</span><span class="typ">Syu</span><span class="pln"> sudo pacman </span><span class="pun">-</span><span class="pln">S </span><span class="kwd">base</span><span class="pun">-</span><span class="pln">devel</span>
第 2 步。安装 PHP。
Manjaro 在其官方存储库中提供 PHP 包。您可以使用包管理器安装 PHP 和一些常见的扩展。为 Laravel 安装 PHP 和所需的扩展:pacman
<span class="pln">sudo pacman </span><span class="pun">-</span><span class="pln">S php php</span><span class="pun">-</span><span class="pln">fpm php</span><span class="pun">-</span><span class="pln">gd php</span><span class="pun">-</span><span class="pln">intl php</span><span class="pun">-</span><span class="pln">mbstring php</span><span class="pun">-</span><span class="pln">zip php</span><span class="pun">-</span><span class="pln">pdo php</span><span class="pun">-</span><span class="pln">mysql</span>
此命令将安装 PHP 及其扩展,使它们可用于您的 Laravel 项目。
启用和配置 PHP 扩展对于 Laravel 正常工作至关重要。打开文件进行编辑:php.ini
<span class="pln">sudo nano </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">php</span><span class="pun">/</span><span class="pln">php</span><span class="pun">.</span><span class="pln">ini</span>
取消注释(删除符号)或添加以下行以启用扩展:;
<span class="pln">extension</span><span class="pun">=</span><span class="pln">gd extension</span><span class="pun">=</span><span class="pln">intl extension</span><span class="pun">=</span><span class="pln">mbstring extension</span><span class="pun">=</span><span class="pln">zip extension</span><span class="pun">=</span><span class="pln">pdo_mysql</span>
保存并退出文本编辑器。
通过运行以下命令验证是否已安装 PHP:
<span class="pln">php </span><span class="pun">-</span><span class="pln">v</span>
第 3 步。正在安装作曲家。
作曲家是Laravel开发的重要工具,可让您有效地管理项目依赖项。使用以下命令全局安装编辑器:
<span class="pln">curl </span><span class="pun">-</span><span class="pln">sS https</span><span class="pun">:</span><span class="com">//getcomposer.org/installer -o composer-setup.php</span>
通过运行以下命令安装编辑器:
<span class="pln">sudo php composer</span><span class="pun">-</span><span class="pln">setup</span><span class="pun">.</span><span class="pln">php </span><span class="pun">--</span><span class="pln">install</span><span class="pun">-</span><span class="pln">dir</span><span class="pun">=</span><span class="str">/usr/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">bin </span><span class="pun">--</span><span class="pln">filename</span><span class="pun">=</span><span class="pln">composer</span>
通过运行以下命令验证是否已安装编辑器:
<span class="pln">composer </span><span class="pun">--</span><span class="pln">version</span>
第 4 步。设置数据库。
Laravel支持多种数据库系统,包括MySQL,PostgreSQL,SQLite和SQL Server。在本指南中,我们将重点介绍设置 MariaDB,由于其性能和与 MySQL 的兼容性,它是 Laravel 项目的热门选择。
使用以下命令安装 MariaDB:
<span class="pln">sudo pacman </span><span class="pun">-</span><span class="pln">S mariadb</span>
启动 MariaDB 服务并使其在启动时启动:
<span class="pln">sudo systemctl start mariadb sudo systemctl enable mariadb</span>
运行 MySQL 安全安装脚本以增强安全性:
<span class="pln">sudo mysql_secure_installation</span>
按照屏幕上的提示设置root密码并保护您的MariaDB安装。
要为您的Laravel项目创建专用数据库和用户,请执行以下步骤:
<span class="pln">sudo mysql </span><span class="pun">-</span><span class="pln">u root </span><span class="pun">-</span><span class="pln">p</span>
创建新数据库和用户:
<span class="pln">CREATE DATABASE yourdatabase</span><span class="pun">;</span><span class="pln"> CREATE USER </span><span class="str">'youruser'</span><span class="pun">@</span><span class="str">'localhost'</span><span class="pln"> IDENTIFIED BY </span><span class="str">'yourpassword'</span><span class="pun">;</span> <span class="typ">Grant</span> <span class="typ">Privileges</span><span class="pun">:</span> <span class="typ">Grant</span><span class="pln"> the user full privileges over the database</span><span class="pun">:</span><span class="pln"> GRANT ALL PRIVILEGES ON yourdatabase</span><span class="pun">.*</span><span class="pln"> TO </span><span class="str">'youruser'</span><span class="pun">@</span><span class="str">'localhost'</span><span class="pun">;</span><span class="pln"> FLUSH PRIVILEGES</span><span class="pun">;</span><span class="pln"> EXIT</span><span class="pun">;</span>
第5步。在曼扎罗山上安装拉拉维尔。
导航到要在其中创建Laravel项目的目录,然后运行以下命令:
<span class="pln">composer create</span><span class="pun">-</span><span class="pln">project </span><span class="pun">--</span><span class="pln">prefer</span><span class="pun">-</span><span class="pln">dist laravel</span><span class="pun">/</span><span class="pln">laravel your</span><span class="pun">-</span><span class="pln">project</span><span class="pun">-</span><span class="pln">name</span>
替换为所需的项目名称。your-project-name
Laravel使用环境文件进行配置。复制文件并命名:.env.example
.env
<span class="pln">cp </span><span class="pun">.</span><span class="pln">env</span><span class="pun">.</span><span class="pln">example </span><span class="pun">.</span><span class="pln">env</span>
使用以下命令生成唯一的应用程序密钥:
<span class="pln">php artisan key</span><span class="pun">:</span><span class="pln">generate</span>
接下来,打开项目目录中的文件并配置数据库连接设置。您可以使用 Nano 或 Vim 等文本编辑器来编辑文件:.env
<span class="pln">nano </span><span class="pun">.</span><span class="pln">env</span>
使用数据库详细信息更新以下变量:
<span class="pln">DB_CONNECTION</span><span class="pun">=</span><span class="pln">mysql DB_HOST</span><span class="pun">=</span><span class="lit">127.0</span><span class="pun">.</span><span class="lit">0.1</span><span class="pln"> DB_PORT</span><span class="pun">=</span><span class="lit">3306</span><span class="pln"> DB_DATABASE</span><span class="pun">=</span><span class="pln">yourdatabase DB_USERNAME</span><span class="pun">=</span><span class="pln">youruser DB_PASSWORD</span><span class="pun">=</span><span class="pln">yourpassword</span>
将 、 和替换为先前设置的数据库信息。yourdatabase
youruser
yourpassword
第 6 步。为 Laravel 配置 Web 服务器。
Laravel可以在各种Web服务器上运行,包括Apache和Nginx。选择最适合您需求的一种。在这里,我们将提供两者的说明。
如果您还没有,请在 Manjaro 系统上安装 Apache:
<span class="pln">sudo pacman </span><span class="pun">-</span><span class="pln">S apache</span>
启用 Apache 服务并启动它:
<span class="pln">sudo systemctl enable httpd sudo systemctl start httpd</span>
为您的Laravel项目创建一个Apache虚拟主机配置文件。替换为项目的域或 IP 地址:your-domain
<span class="pln">sudo nano </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">httpd</span><span class="pun">/</span><span class="pln">conf</span><span class="pun">/</span><span class="pln">extra</span><span class="pun">/</span><span class="pln">your</span><span class="pun">-</span><span class="pln">domain</span><span class="pun">.</span><span class="pln">conf</span>
添加以下内容,根据需要调整路径和域:
<span class="tag"><VirtualHost</span><span class="pln"> *:80</span><span class="tag">></span><span class="pln"> ServerAdmin webmaster@your-domain.com DocumentRoot "/path/to/your-project-name/public" ServerName your-domain.com ServerAlias www.your-domain.com </span><span class="tag"><Directory</span> <span class="atv">"/path/to/your-project-name/public"</span><span class="tag">></span><span class="pln"> AllowOverride All Require all granted </span><span class="tag"></Directory></span> <span class="tag"></VirtualHost></span>
启用虚拟主机配置:
<span class="pln">sudo a2ensite your</span><span class="pun">-</span><span class="pln">domain</span><span class="pun">.</span><span class="pln">conf</span>
重新加载 Apache 以应用更改:
<span class="pln">sudo systemctl restart httpd</span>
步骤 7.运行您的 Laravel 应用程序。
设置Laravel项目后,您可以通过内置开发服务器提供它来启动它。导航到项目目录并运行:
<span class="pln">php artisan serve</span>
此命令将启动本地开发服务器,允许您在 Web 浏览器中访问 Laravel 应用程序。http://localhost:8000
第8步。配置文件权限。
文件权限对于Laravel应用程序正常运行至关重要。确保 Web 服务器用户(通常为 或)具有读取和写入特定目录所需的权限。http
nginx
授予对目录的写入权限:storage
<span class="pln">sudo chmod </span><span class="pun">-</span><span class="pln">R </span><span class="lit">775</span><span class="pln"> storage</span>
设置目录的权限:bootstrap/cache
<span class="pln">sudo chmod </span><span class="pun">-</span><span class="pln">R </span><span class="lit">775</span><span class="pln"> bootstrap</span><span class="pun">/</span><span class="pln">cache</span>
感谢您使用本教程在Manjaro系统上安装最新版本的LaravelPHP框架。如需其他帮助或有用信息,我们建议您查看Laravel官方网站。