在Linux上面使用composer安装laravel那些坑

一、安装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,我们就看到大功告成了。
在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
安装 Laravel 框架并配置 OpenSSL 需要遵循一些步骤,因为 Laravel 是一个 PHP Web 开发框架,而 OpenSSL 是一个用于加密和安全通信的库。下面是安装 Laravel 和配置 OpenSSL 的一般过程: 1. 安装 PHP 和 Composer: 确保你的系统上已经安装了 PHP,并且更新到最新版本。Composer是 PHP 的依赖管理工具,使用它来安装 Laravel。 2. 安装 Laravel: 打开终端或命令提示符,通过 Composer 创建一个新的 Laravel 项目: ``` composer create-project --prefer-dist laravel/laravel project-name ``` 这将创建一个名为 `project-name` 的新 Laravel 项目。 3. 安装 OpenSSL 支持: 如果你的 PHP 版本没有内置 OpenSSL 支持,你需要安装 OpenSSL。在 Linux 上,你可以使用包管理器(如 apt-get 或 yum)安装: ```sh sudo apt-get install php-openssl ``` 在 macOS 或者用 Homebrew 安装的话: ```sh brew install php@8.1 --with-openssl ``` 4. 配置 Laravel: 在新项目中,找到 `.env` 文件,确保 `APP_KEY` 字段的生成包含 OpenSSL。如果你已经生成了一个密钥,可以手动编辑,否则运行 `php artisan key:generate` 命令。 5. 重启服务器: 重新启动你的 PHP 服务器,让新的 OpenSSL 配置生效。 6. 测试 OpenSSL: 在 Laravel 控制台,你可以使用 `openssl` 函数进行测试,例如生成一个数字签名: ```sh php artisan tinker ``` 然后输入 `openssl_sign($data, $signature, $key)`,看看是否能正常执行。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值