在CentOS上运行Laravel项目需要完成以下几个步骤:
你可以使用以下命令来安装这些软件包:
sudo yum update
sudo yum install epel-release
sudo yum install php php-mbstring php-xml php-mysqlnd php-zip php-gd php-curl php-pear php-bcmath
sudo yum install nginx
sudo yum install mariadb-server mariadb
sudo composer global require laravel/installer
将Composer的全局二进制文件目录添加到系统的PATH变量中。编辑~/.bashrc或~/.bash_profile文件,添加以下行:
export PATH="$HOME/.composer/vendor/bin:$PATH"
保存文件并运行source ~/.bashrc或source ~/.bash_profile使更改生效。
laravel new your_project_name
将your_project_name替换为你的项目名称。
server {
listen 80;
server_name example.com; # 替换为你的域名或公网IP地址
root /path/to/your_project_name/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
index index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
将example.com替换为你的域名或公网IP地址,将/path/to/your_project_name替换为你的Laravel项目的实际路径。
storage和bootstrap/cache目录具有可写权限:sudo chown -R nginx:nginx /path/to/your_project_name/storage
sudo chown -R nginx:nginx /path/to/your_project_name/bootstrap/cache
将nginx:nginx替换为你的Web服务器用户和组。
sudo systemctl restart nginx
或者
sudo systemctl restart httpd
现在,你应该可以通过访问你的域名或公网IP地址来访问Laravel项目了。