1 . 安装php、nginx、mysql等标配环境,或直接用lnmp
1
2
3
4
5
6
|
# 更新yum源
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
# 安装php7.1以及相关扩展
yum install php71w php71w-fpm php71w-cli php71w-common php71w-devel php71w-gd php71w-pdo php71w-mysql php71w-mbstring php71w-bcmath
|
注意
若要安装php7.0和对应的扩展,上面的命令可以改为
1
|
yum install php70w php70w-fpm php70w-cli php70w-common php70w-devel php70w-gd php70w-pdo php70w-mysql php70w-mbstring php70w-bcmath
|
2 . 安装php相关依赖
1
|
wget https://dl.laravel-china.org/composer.phar -O /usr/local/bin/composer
|
3 . 安装composer
1
|
wget https://dl.laravel-china.org/composer.phar -O /usr/local/bin/composer
|
4 . 生成laravel项目
- 方法一(不晓得是不是配置原因,没成功过): 指定path,直接用laravel命令 laravel new 项目名
- 方法二(推荐这个,能够指定版本和相关依赖): composer create-project laravel/laravel 项目名 –prefer-dist “5.7.*”
5 . composer install
将composer.js 中的配置下载安装,生成vendor目录 * 如果报错Your requirements could not be resolved to an installable set of packages. 这是因为不匹配composer.json要求的版本,可以用composer install –ignore-platform-reqs,忽略平台版本
6 . 配置nginx访问路径
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
{
listen 81 default_server;
listen [::]:81 default_server ipv6only=on;
# 设置根目录
root /home/wwwroot/laravel/test1/public/;
index index.html index.htm index.php;
# 服务器名称
server_name server_domain_or_IP;
location / {
try_files $uri $uri/ /index.php?$query_string;
#root /home/wwwroot;
# index index.html index.htm;
}
#location /laravel/test1 {
# index index.html index.htm index.php;
# try_files $uri $uri/ /index.php?$query_string;
#}
# PHP 支持
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/opt/remi/php71/run/php7-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
|
7 . 测试
1
2
3
4
|
vendor/bin/phpunit
# 报错Class 'DOMDocument' not found,很大可能是php的xml插件没装,先查看有没有装
php -m
yum install php71w-xml
|
出现 No application encryption key has been specified
若文件根目录下没有 .env
- .env.example 改名使用命令 copy 修改为 .env
- 使用命令 php artisan key:generate 获取密码,自动保存到 .env
1
2
|
composer install
composer dump-autoload
|