Laravel 是一个 PHP Web 应用程序框架,具有富有表现力、优雅的语法。它具有精炼、简单和可读的语法,用于从头开始开发现代、健壮和强大的应用程序。Laravel 提供了强大的功能,包括 Artisan、MVC 架构、对象关系映射、模板引擎、单元测试和数据库迁移系统。
在 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
感谢您使用本教程在您的 AlmaLinux 8 系统上安装 Laravel PHP 框架。如需更多帮助或有用信息,我们建议您查看Laravel 官方网站。
原创文章,作者:校长,如若转载,请注明出处:https://www.yundongfang.com/Yun224270.html