安装laravel环境
服务器要求
- PHP >= 7.1.3
- OpenSSL PHP 扩展
- PDO PHP 扩展
- Mbstring PHP 扩展
- Tokenizer PHP 扩展
- XML PHP 扩展
- Ctype PHP 扩展
- JSON PHP 扩展
按照上一篇中php的安装,这些配置按道理应该是都符合吧。
安装Composer
curl -sS https://getcomposer.org/installer | php
移动 composer.phar
文件到 /usr/local/bin
目录下 ,使命令全局可用,并更换 Packagist 中国全量镜像
mv composer.phar /usr/local/bin/composer
composer config -g repo.packagist composer https://packagist.phpcomposer.com
设置 Nginx 配置文件
在conf.d/中新建域名对应的conf文件
server {
listen 80;
server_name www.xblog.site;
root /home/xxx/web/html/;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.html index.htm 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_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php-fpm/php7.2-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
其中,php-fpm.sock
文件就是让Nginx和PHP-FPM的进程间进行通信的文件。
修改php-fpm配置
/etc/php-fpm.d/www.conf
listen = /var/run/php-fpm/php7.2-fpm.sock
listen.owner = nginx
listen.group = nginx
listen.mode = 0660
重启php-fpm
systemctl restart php-fpm
测试
在nginx配置的root下,添加index.php
<?php
phpinfo();
访问www.xblog.site
创建laravel项目
composer create-project laravel/laravel laravel54 "5.4.*"
laravel有不依赖web容器的启动方式,直接在nginx中配置一下反向代理就行了,不用像上面那样搞得这么复杂,还要在nginx中配置php的各种设置。
php artisan serve
location / {
proxy_pass http://127.0.0.1:8080;
}