参照官方文档:Installation - Laravel - The PHP Framework For Web Artisans
把结论放到最前面吧:
现在差不多能下结论了,要通过docker安装larabel,安装脚本会去启动一个laravelsail/php81-composer的docker实例,这个实例不能设置composer的参数,默认会去Packagist 下载包,所以如果这个网址打不开的话,要么得科学上网,要么这种方式就安装不了。
以下是爬坑过程
执行完安装的命令后
curl -s https://laravel.build/example-app | bash
报错:Docker is not running.
解决方案参考:ubuntu安装laravel,Docker is not running._Jenking Wang的博客-CSDN博客
重新执行命令
sudo curl -s https://laravel.build/first_laravel5 | sudo bash
可以开始安装了,安装完毕后,执行
cd first_laravel5/./vendor/bin/sail up
报错:bash: ./vendor/bin/sail: 没有那个文件或目录
ls 查看一下,发现没有vendor目录。
安装输出的信息如下:
jenking@jenking-7836:~/php_source$ sudo curl -s https://laravel.build/first_laravel5 | sudo bash _ _| | | || | __ _ _ __ __ ___ _____| || | / _` | '__/ _` \ \ / / _ \ || |___| (_| | | | (_| |\ V / __/ ||______\__,_|_| \__,_| \_/ \___|_|Warning: TTY mode requires /dev/tty to be read/writable. Creating a "laravel/laravel" project at "./first_laravel5" Info from https://repo.packagist.org/: #StandWithUkraine Installing laravel/laravel (v9.1.10) - Downloading laravel/laravel (v9.1.10) - Installing laravel/laravel (v9.1.10): Extracting archive Created project in /opt/first_laravel5 > @php -r "file_exists('.env') || copy('.env.example', '.env');" Loading composer repositories with package information https://repo.packagist.org/ could not be fully loaded (curl error 28 while downloading https://repo.packagist.org//packages.json: Failed to connect to repo.packagist.org port 443: Connection timed out), package information was loaded from the local cache and may be out of date A connection timeout was encountered. If you intend to run Composer without connecting to the internet, run the command again prefixed with COMPOSER_DISABLE_NETWORK=1 to make Composer run in offline mode.[Composer\Downloader\TransportException] curl error 28 while downloading https://repo.packagist.org//p2/mockery/mockery.json: Failed to connect to repo.packagist.org port 443: Connection timed outcreate-project [-s|--stability STABILITY] [--prefer-source] [--prefer-dist] [--prefer-install PREFER-INSTALL] [--repository REPOSITORY] [--repository-url REPOSITORY-URL] [--add-repository] [--dev] [--no-dev] [--no-custom-installers] [--no-scripts] [--no-progress] [--no-secure-http] [--keep-vcs] [--remove-vcs] [--no-install] [--ignore-platform-req IGNORE-PLATFORM-REQ] [--ignore-platform-reqs] [--ask] [--] [] [] []Get started with: cd first_laravel5 && ./vendor/bin/sail up
看提示信息是 curl 访问 Packagist 这个域名出现了问题,用浏览器打开这个域名,打不开,看输出信息里有 #StandWithUkraine,不知道是不是跟这个有关系。
看信息是 Loading composer repositories with package information 这句之后开始timeout的,推想安装一下composer, 设置一下代理试试能不能解决。
sudo apt install composer
设置一下阿里云的代理试试:阿里云Composer镜像站-阿里云开发者社区
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
测试一下
composer -vvv require alibabacloud/sdk
不成功,报错:Warning from https://mirrors.aliyun.com/composer: Support for Composer 1 is deprecated and some packages will not be available. You should upgrade to Composer 2. See https://blog.packagist.com/deprecating-composer-1-support/
Composer 1已经废弃了,ubuntu通过apt安装的还是composer 1版本,需要升级到Composer 2,那就卸载重装吧
sudo apt autoremove composer
重新安装只能按照官网文档装了,Composer
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
结果又报错:PHP Warning: copy(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? in Command line code on line 1
根据 https 关键字,推测根SSL有关,PHP安装的时候是通过源码编译安装的,PHP: Nginx 1.4.x on Unix systems - Manual
编译的时候就用了两个参数
./configure --enable-fpm --with-mysqli
那就重新编译吧,把ssl扩展给加上,正好要重新编译,那就研究一下都有哪些扩展需要用的都加上吧, ./configure --help 可以列出所有的参数
这是我最终选择的编译参数,看着脸熟可能会用到的
./configure --enable-fpm --with-fpm-user=www-data --with-fpm-group=www-data --with-fpm-systemd --with-mysqli --with-pdo-mysql --with-openssl --with-zlib --enable-bcmath --with-curl --enable-gd --with-jpeg --enable-mbstring
中间会提示一堆的 configure error:Package requirements (openssl) were not met 各种包缺失,一一安装吧,我的安装了这些
sudo apt install libssl-devsudo apt install libcurl4-openssl-devsudo apt install libpng-devsudo apt install libjpeg-devsudo apt install libonig-dev
终于不报错了
接着就 make && make install 吧, 耐心等待一会...安装成功
接下来安装composer,从官网文档安装:Composer
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"php -r "if (hash_file('sha384', 'composer-setup.php') === '55ce33d7678c5a611085589f1f3ddf8b3c52d662cd01d4ba75c0ee0459970c2200a51f492d557530c71c15d8dba01eae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"php composer-setup.phpphp -r "unlink('composer-setup.php');"
没报什么错,安装成功:
有个小提示,编译PHP的时候没有编译zlib扩展,会减慢composer,介意这个的可以编译的时候再加上一个 --with-zlib 选项,我先不管,回头再弄这个。
将composer.phar移动到系统路径
sudo mv composer.phar /usr/local/bin/composercomposer --version
输出
composer安装成功。
设置阿里云的composer镜像,及测试
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/composer -vvv require alibabacloud/sdk
ok,通过。
接着回到安装laravel的命令
sudo curl -s https://laravel.build/first_laravel8 | sudo bash
还是不行,还是会连接 https://repo.packagist.org/
我把这个脚本打出来看了一下sudo curl -s https://laravel.build/first_laravel8
docker info > /dev/null 2>&1# Ensure that Docker is running...if [ $? -ne 0 ]; then echo "Docker is not running." exit 1fidocker run --rm \ -v "$(pwd)":/opt \ -w /opt \ laravelsail/php81-composer:latest \ bash -c "laravel new first_laravel8 && cd first_laravel8 && php ./artisan sail:install --with=mysql,redis,meilisearch,mailhog,selenium "cd first_laravel8CYAN='\033[0;36m'LIGHT_CYAN='\033[1;36m'WHITE='\033[1;37m'NC='\033[0m'echo ""if sudo -n true 2>/dev/null; then sudo chown -R $USER: . echo -e "${WHITE}Get started with:${NC} cd first_laravel8 && ./vendor/bin/sail up"else echo -e "${WHITE}Please provide your password so we can make some final adjustments to your application's permissions.${NC}" echo "" sudo chown -R $USER: . echo "" echo -e "${WHITE}Thank you! We hope you build something incredible. Dive in with:${NC} cd first_laravel8 && ./vendor/bin/sail up"fi
其中
docker run --rm \
-v "$(pwd)":/opt \
-w /opt \
laravelsail/php81-composer:latest \
bash -c "laravel new first_laravel8 && cd first_laravel8 && php ./artisan sail:install --with=mysql,redis,meilisearch,mailhog,selenium "
运行一个docker实例,这个实例要获取 laravelsail/php81-composer 这个image,网上查了一下没有这个实例方面的资料,然后我去docker hub上查了这个image,什么信息也没有,应该不能传递参数进去设置 mirror。
现在差不多能下结论了,要通过docker安装larabel,安装脚本会去启动一个laravelsail/php81-composer的docker实例,这个实例不能设置composer的参数,默认会去Packagist 下载包,所以如果这个网址打不开的话,要么得科学上网,要么这种方式就安装不了。
接下来我用composer方式安装吧。