Laravel 是一个风行的 PHP 开辟框架,它简化了开辟流程,进步了开辟效力。CentOS 是一个牢固、坚固的 Linux 发行版,常用于效劳器安排。本文将具体介绍如何在 CentOS 上安排 Laravel 情况,并供给实战教程,帮助你轻松上手。
更新体系:
sudo yum update
安装须要的软件:
sudo yum install -y git nginx mysql-server php php-fpm php-mysqlnd
设置 Nginx:
创建 Nginx 设置文件:
sudo vi /etc/nginx/conf.d/default.conf
修改设置文件内容,增加以下内容:
server {
listen 80;
server_name localhost;
root /var/www/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
重启 Nginx 效劳:
sudo systemctl restart nginx
sudo yum install -y composer
composer global require laravel/installer
laravel new myproject
cd myproject
.env
文件,修改数据库设置:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=myproject
DB_USERNAME=root
DB_PASSWORD=root
mysql -u root -p
CREATE DATABASE myproject;
php artisan migrate
设置虚拟主机:
创建 Nginx 设置文件:
sudo vi /etc/nginx/conf.d/myproject.conf
修改设置文件内容,增加以下内容:
server {
listen 80;
server_name myproject.com;
root /var/www/html/myproject/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
重启 Nginx 效劳:
sudo systemctl restart nginx
设置 DNS:
myproject.com
剖析到你的效劳器 IP 地点。经由过程以上步调,你可能在 CentOS 上成功安排 Laravel 情况。在现实开辟过程中,你可能根据项目须要停止响应的设置跟优化。祝你开辟高兴!