一、安装composer,如果已经安装,请忽略。
1,下载composer
curl -sS https://getcomposer.org/installer | php
2,把composer.phar转移之bin目录以便全局使用
mv composer.phar /usr/local/bin/composer
3,切换国内源
composer config -g repo.packagist composer https://packagist.phpcomposer.com
4,输入composer验证,是否安装成功
[root@iZm5e8nyz28v9zr7lhb7moZ ~]# composer
______
/ ____/___ ____ ___ ____ ____ ________ _____
/ / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
/_/
Composer version 1.9.1 2019-11-01 17:20:17
Usage:
command [options] [arguments]
Options:
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
--profile Display timing and memory usage information
--no-plugins Whether to disable plugins.
-d, --working-dir=WORKING-DIR If specified, use the given directory as working directory.
--no-cache Prevent use of the cache
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Available commands:
二、安装laravel的坑
第1个坑:** Project directory test/ is not empty. *意思就是test这个文件夹不是空的,不能作为安装目录操作。
[root@iZm5e8nyz28v9zr7lhb7moZ test]# composer create-project --prefer-dist laravel/laravel test 5.5.*
Installing laravel/laravel (v5.5.28)
[InvalidArgumentException]
Project directory test/ is not empty.
第2个坑:“ The Process class relies on proc_open, which is not available on your PHP installation.”这也是最深的一个坑,实际上这个时候在“test”文件夹中已经有了blog这个项目了。
图中错误代码如下
[root@iZm5e8nyz28v9zr7lhb7moZ test]# composer create-project --prefer-dist laravel/laravel blog 5.5.*
Installing laravel/laravel (v5.5.28)
- Installing laravel/laravel (v5.5.28): Loading from cache
The Process class relies on proc_open, which is not available on your PHP installation.
The archive may contain identical file names with different capitalization (which fails on case insensitive filesystems)
Unzip with unzip command failed, falling back to ZipArchive class
Created project in blog
> @php -r "file_exists('.env') || copy('.env.example', '.env');"
[Symfony\Component\Process\Exception\RuntimeException]
The Process class relies on proc_open, which is not available on your PHP installation.
解决方案如下:
打开php.ini,并搜索disable_functions指令,从里面搜索“proc_open”,删除即可。
- 注意,要看我们一共安装了几个php,都要相应的删除掉。
1,进入php.ini输入命令:“vim /usr/local/php/etc/php.ini”,根据自己不同的路径查找。
从图中看到,共有两个php的版本,我们需要依次打开这两个php.ini文件,找到“disable_functions”删除“proc_open”。代码位置如下
disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server
2,重启所有版本php的php-fpm,这里重启php56-fpm,跟php-fpm,因为我装了两个php,php-fpm则是7.0。操作命令如下:
[root@iZm5e8nyz28v9zr7lhb7moZ test]# sudo /etc/init.d/php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
[root@iZm5e8nyz28v9zr7lhb7moZ test]# /etc/init.d/nginx start
Starting nginx: [ OK ]
[root@iZm5e8nyz28v9zr7lhb7moZ test]# sudo /etc/init.d/php56-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
3,重启Nginx服务器,/etc/init.d/nginx restart
[root@iZm5e8nyz28v9zr7lhb7moZ test]# /etc/init.d/nginx restart
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
Stopping nginx: [ OK ]
Starting nginx: [ OK ]
三,踩过二的坑,终于可以使用composer安装laravel了
1,输入命令:composer create-project --prefer-dist laravel/laravel blog 5.5.*,
- blog–项目名称
- 5.5.* --laravel5.5版本
- 注意:其他的命令都是固定写法,不予改变。只有:blog,5.5.*是可以自定义的。
2,使用 cd /data/wwwroot/test,切换到安装的目录,composer安装的时候会自动在test文件夹下面创建项目文件名称。
[root@iZm5e8nyz28v9zr7lhb7moZ test]# cd /data/wwwroot/test
[root@iZm5e8nyz28v9zr7lhb7moZ test]# composer create-project --prefer-dist laravel/laravel blog 5.5.*
3,执行安装,需要等待,因为是从外国服务器下载,时间较长。安装成功如下:
配置laravel的站点,service主机
1,vim /usr/local/nginx/conf/vhost/vhosts.conf打开service虚拟机vhost.conf文件,根据自己的配置文件路径,输入操作命令如下:
[root@iZm5e8nyz28v9zr7lhb7moZ ~]# vim /usr/local/nginx/conf/vhost/vhosts.conf
2,打开vhost.conf配置文件,配置laravel的service
server {
listen 80;
server_name 域名;
#charset koi8-r;
#access_log logs/host.access.log main;
root "/data/wwwroot/test/blog/public/";
location / {
index index.html index.htm index.php l.php;
try_files $uri $uri/ /index.php?$query_string;
autoindex off;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
# fastcgi_pass 127.0.0.1:9001; 9001端口是php5.6版本的。
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
4,重启Nginx服务/etc/init./nginx restart,以下代码中重启又两种方式。执行一种即可
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
Stopping nginx: [ OK ]
Starting nginx: [ OK ]
[root@iZm5e8nyz28v9zr7lhb7moZ ~]# sudo /etc/init.d/nginx restart
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
Stopping nginx: [ OK ]
Starting nginx: [ OK ]
打开浏览器输入域名,访问laravel项目,报 An error occurred
1,打开浏览器,输入配置好的域名,结果报错。
解决方案如下
注意:出现这中原因的因素有很多种,但是能确定的是不是Nginx配置文件的问题,在网上百度好多种,全部都说是Nginx服务器配置问题,要么就是service虚拟机的问题。这个时候就可以利用排除法,新建一个service,访问一下其他的项目,比如新建test.php脚本,输出echo phpinfo()。如果这个都不可以证明是Nginx配置或者service配置出现问题,如果这个可以,建议就从项目中的配置文件排查问题吧。
1,laravel项目里面的storage目录,需要拥有读写权限。设置命令如下:
[root@iZm5e8nyz28v9zr7lhb7moZ ~]# chmod -R 777 /data/wwwroot/test/blog/storage/
2,设置好目录权限,重启Nginx服务器/etc/init.d/nginx restart:操作命令如下
[root@iZm5e8nyz28v9zr7lhb7moZ ~]# /etc/init.d/nginx restart
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
Stopping nginx: [ OK ]
Starting nginx: [ OK ]
[root@iZm5e8nyz28v9zr7lhb7moZ ~]#
3,再次访问laravel,我们就看到大功告成了。