如何在 AlmaLinux 8 上安装 Laravel
admin
2023-08-01 08:41:43
0

Laravel 是一个 PHP Web 应用程序框架,具有富有表现力、优雅的语法。它具有精炼、简单和可读的语法,用于从头开始开发现代、健壮和强大的应用程序。Laravel 提供了强大的功能,包括 Artisan、MVC 架构、对象关系映射、模板引擎、单元测试和数据库迁移系统。laravel-logolaravel-logo

在 AlmaLinux 8 上安装 Laravel

第 1 步。首先,让我们首先确保您的系统是最新的。

sudo dnf clean all
sudo dnf install epel-release
sudo dnf update

步骤 2. 安装 LEMP 服务器。

需要 AlmaLinux LEMP 服务器。如果您没有安装 LEMP,您可以在此处按照我们的指南进行操作。

步骤 3. 安装 Composer。

现在我们使用以下命令安装 Composer(PHP 的依赖管理器)来安装所需的 Laravel 依赖项:

curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
chmod +x /usr/local/bin/composer

验证 Composer 版本:

composer --version

步骤 4. 在 AlmaLinux 8 上安装 Laravel。

默认情况下,Laravel 在 AlmaLinux 8 基础存储库中不可用。现在我们运行以下命令来使用 Composer 安装 Laravel:

cd /var/www/html/
composer create-project --prefer-dist laravel/laravel laravel

我们将需要更改一些文件夹权限:

chown -R nginx:nginx /var/www/html/laravel/
chown -R nginx:nginx /var/www/html/laravel/storage/
chown -R nginx:nginx /var/www/html/laravel/bootstrap/cache/
chmod -R 0777 /var/www/html/laravel/storage/
chmod -R 0775 /var/www/html/laravel/bootstrap/cache/

步骤 5. 配置 Nginx。

现在我们为 Laravel 创建一个 Nginx 配置文件:

nano /etc/nginx/conf.d/laravel.conf

添加以下行:

server {
       listen 80;
       server_name laravel.your-domain.com;
       root        /var/www/html/laravel/public;
       index       index.php;
       charset utf-8;
       gzip on;
	gzip_types text/css application/javascript text/javascript application/x-javascript  image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon;
        location / {
        	try_files $uri $uri/ /index.php?$query_string;
        }

        location ~ \\.php {
                include fastcgi.conf;
                fastcgi_split_path_info ^(.+\\.php)(/.+)$;
                fastcgi_pass unix:/run/php-fpm/www.sock;
        }
        location ~ /\\.ht {
                deny all;
        }
}

保存并关闭文件,然后重新启动 Apache 服务以使更改生效:

sudo systemctl restart php-fpm
sudo systemctl restart nginx

步骤 5. 配置防火墙。

AlmaLinux 默认启用了 firewalld,它会阻止来自其他试图访问我们 Laravel 服务的计算机的其他连接。我们必须打开适当的端口,以便其他机器可以访问 Laravel 资源:

sudo firewall-cmd --zone=public --permanent --add-service=http
sudo firewall-cmd --zone=public --permanent --add-service=https
sudo firewall-cmd --reload

步骤 6. 使用 Let\’s Encrypt SSL 免费证书保护 Nginx

首先,我们使用以下命令安装 Certbot:

sudo dnf install certbot python3-certbot-nginx

然后,为 Apache 安装 SSL 证书,如下所示:

sudo certbot --nginx -d laravel.your-domain.com

进入交互式提示并安装证书。如果安装了证书,您将看到以下祝贺消息:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://laravel.your-domain.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=laravel.your-domain.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/laravel.your-domain.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/laravel.your-domain.com/privkey.pem
   Your cert will expire on 2022-04-11. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the \"certonly\" option. To non-interactively renew *all* of
   your certificates, run \"certbot renew\"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let\'s Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

 - We were unable to subscribe you the EFF mailing list because your
   e-mail address appears to be invalid. You can try again later by
   visiting https://act.eff.org.

步骤 7. 访问 Laravel Web 界面。

成功安装后,打开您的网络浏览器并使用 URL 访问 MediaWiki 。您将被重定向到以下页面:https://laravel.your-domain.com

Laravel-DevlopmentLaravel-Devlopment

感谢您使用本教程在您的 AlmaLinux 8 系统上安装 Laravel PHP 框架。如需更多帮助或有用信息,我们建议您查看Laravel 官方网站。

相关内容

热门资讯

Windows 11 和 10... Windows 11/10 文件夹属性中缺少共享选项卡 – 已修复 1.检查共享选项卡是否可用 右键...
Radmin VPN Wind... Radmin VPN 是一款免费且用户友好的软件,旨在牢固地连接计算机以创建一个有凝聚力的虚拟专用网...
如何修复 Steam 内容文件... Steam 内容文件锁定是当您的 Steam 文件无法自行更新时出现的错误。解决此问题的最有效方法之...
事件 ID 7034:如何通过... 点击进入:ChatGPT工具插件导航大全 服务控制管理器 (SCM) 负责管理系统上运行的服务的活动...
Hive OS LOLMine... 目前不清退的交易所推荐: 1、全球第二大交易所OKX欧意 国区邀请链接: https://www.m...
在 Windows 11 中打... 什么是链路状态电源管理? 您可以在系统控制面板的电源选项中看到链接状态电源管理。它是 PCI Exp...
如何在 iPhone 14 P... Apple 的 iPhone 14 Pro 是第一款配备 48MP 传感器的 iPhone。所有以前...
如何在电报Telegram中隐... 点击进入:ChatGPT工具插件导航大全 在Android上的电报中隐藏您的电话号码 您可以通过切换...
在 iCloud 上关闭“查找... 如果您是 Apple 的长期用户,您肯定会遇到过 Find My 应用程序,它本机安装在 iPhon...
Hive OS 部署 PXE ... 目前不清退的交易所推荐: 1、全球第二大交易所OKX欧意 国区邀请链接: https://www.m...