永久化 alias 命令及相关笔记记录

Linux系统
424
0
0
2022-07-12

使用docker文档中的sail命令,文档中的:

alias sail='bash vendor/bin/sail'

关闭终端后,发现alias命令失效里。永久化alias命令需要中文件中写入alias命令。

首先建立 .bash_aliases文件

touch ~/.bash_aliases

然后把命令输入到该文件中

vi ~/.bash_aliases
alias sail='bash vendor/bin/sail'
alias co='cd /mnt/c/Code'

然后使用source使命令生效

source ~/.bashrc

co命令是定位项目文件夹,每次都需要跳转也挺麻烦的。

查看别名列表

alias -p

这样下次打开也能使用快捷命令了。


使用wsl虚拟机打开localhost感觉还是有点慢,跟homestead虚拟机没啥区别啊,能不能增加配置呢?在docker中说可以在配置文件中修改。

在我的文档目录中建立.wslconfig文件,然后添加配置信息:

[wsl2]
memory=8096MB
swap=8G
processors=8

分别说内存,交换区和核心数,但是这个配置是限制docker最大使用到的配置。百度了一下说,理论上wsl和docker能用到主机全部到物理性能,但子系统缓存文件不会主动释放?!会导致主机内存越来越小……

添加Bootstrap时,出错,要先安装composer,这个时候要添加Ubuntu到源,修改

vi /etc/apt/sources.list

使用以下内容:

deb https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse

deb https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse

deb https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse

deb https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
## Not recommended
# deb https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse

默认安装到composer是1.0版本到,需要升级

 composer self-update

出错说:

Command “self-update” is not defined.

需要重新安装最新到composer:

先是删除已有的版本:

sudo apt-get purge composer

然后:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');";

sudo php composer-setup.php --install-dir=/usr/bin --filename=composer;

使用这两条命令就按照最新到2.1.9版本的composer了。

安装 laravel/ui 时出错:

[InvalidArgumentException]
Could not find package laravel/ui. It was however found via repository search, which indicates a consistency issue
with the repository.

这是因为之前使用了国内到composer镜像,

将:

composer config -g repo.packagist composer https://packagist.phpcomposer.com

换成:

composer config -g repo.packagist composer https://packagist.org

这个时候出的错是:

Problem 1
- facade/ignition is locked to version 2.15.0 and an update of this package was not requested.
- facade/ignition 2.15.0 requires ext-curl * -> it is missing from your system. Install or enable PHP’s curl extension.
Problem 2
- phpunit/phpunit is locked to version 9.5.10 and an update of this package was not requested.
- phpunit/phpunit 9.5.10 requires ext-dom * -> it is missing from your system. Install or enable PHP’s dom extension.
Problem 3
- psr/log 2.0.0 requires php >=8.0.0 -> your php version (7.4.3) does not satisfy that requirement.
- laravel/framework v8.65.0 requires psr/log ^1.0 || ^2.0 -> satisfiable by psr/log[2.0.0].
- laravel/framework is locked to version v8.65.0 and an update of this package was not requested.
To enable extensions, verify that they are enabled in your .ini files:
- /etc/php/7.4/cli/php.ini
- /etc/php/7.4/cli/conf.d/10-opcache.ini
- /etc/php/7.4/cli/conf.d/10-pdo.ini
- /etc/php/7.4/cli/conf.d/20-calendar.ini
- /etc/php/7.4/cli/conf.d/20-ctype.ini
- /etc/php/7.4/cli/conf.d/20-exif.ini
- /etc/php/7.4/cli/conf.d/20-ffi.ini
- /etc/php/7.4/cli/conf.d/20-fileinfo.ini
- /etc/php/7.4/cli/conf.d/20-ftp.ini
- /etc/php/7.4/cli/conf.d/20-gettext.ini
- /etc/php/7.4/cli/conf.d/20-iconv.ini
- /etc/php/7.4/cli/conf.d/20-json.ini
- /etc/php/7.4/cli/conf.d/20-mbstring.ini
- /etc/php/7.4/cli/conf.d/20-phar.ini
- /etc/php/7.4/cli/conf.d/20-posix.ini
- /etc/php/7.4/cli/conf.d/20-readline.ini
- /etc/php/7.4/cli/conf.d/20-shmop.ini
- /etc/php/7.4/cli/conf.d/20-sockets.ini
- /etc/php/7.4/cli/conf.d/20-sysvmsg.ini
- /etc/php/7.4/cli/conf.d/20-sysvsem.ini
- /etc/php/7.4/cli/conf.d/20-sysvshm.ini
- /etc/php/7.4/cli/conf.d/20-tokenizer.ini
You can also run php --ini inside terminal to see which files are used by PHP in CLI mode.

需要在安装命令后面加 --ignore-platform-reqs

 composer require laravel/ui:^3.0 --dev --ignore-platform-reqs

然后出的错是:

PHP Parse error: syntax error, unexpected ‘|’, expecting variable (T_VARIABLE) in /mnt/c/Code/example-app/vendor/psr/log/src/LoggerInterface.php on line 30
PHP Fatal error: Exception thrown without a stack frame in Unknown on line 0
PHP Parse error: syntax error, unexpected ‘|’, expecting variable (T_VARIABLE) in /mnt/c/Code/example-app/vendor/psr/log/src/LoggerInterface.php on line 30
PHP Fatal error: Exception thrown without a stack frame in Unknown on line 0
Script [[@php](https://learnku.com/users/10050)](https://learnku.com/users/10050) artisan package:discover –ansi handling the post-autoload-dump event returned with error code 255
Installation failed, reverting ./composer.json and ./composer.lock to their original content.

找到vendor/psr/log/src/LoggerInterface.php这个文件,发现里面有 string|\Stringable 这样到代码,而不被识别,干脆把所有到|\Stringable都删除掉,再安装ui,就成功了。

引入 Bootstra 后,添加npm源

 npm config set registry=https://registry.npm.taobao.org

需要更新npm依赖包,

npm install

这个时候出错:

-bash: /mnt/c/Program Files/nodejs/npm: /bin/sh^M: bad interpreter: No such file or directory

想一想,到主机的根目录去更新。依赖包更新成功。

启动npm监视,出错:

    Additional dependencies must be installed. This will only take a moment.
    Running: npm install resolve-url-loader@^4.0.0 --save-dev --legacy-peer-deps
npm WARN loader@4.0.0"">resolve-url-loader@4.0.0 requires a peer of rework@1.0.1 but none is installed. You must install peer dependencies yourself.
npm WARN loader@4.0.0"">resolve-url-loader@4.0.0 requires a peer of visit@1.0.0"">rework-visit@1.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.2 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {“os”:”darwin”,”arch”:”any”} (current: {“os”:”win32”,”arch”:”x64”})

先输入命令:

npm install resolve-url-loader@^4.0.0 --save-dev --legacy-peer-deps

再启动监视成功

npm run watch-poll

迁移数据库出错,数据库的用户名和密码在配置文件中。

DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=example_app
DB_USERNAME=sail
DB_PASSWORD=password

使用迁移代码:

php artisan migrate

出错:

could not find driver (SQL: select * from information_schema.tables where table_schema = example_app and table_name = migrations and table_type = ‘BASE TABLE’)

需要安装驱动:

sudo apt-get install php-mysql

再迁移,出错:

SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known (SQL: select * from information_schema.tables where table_schema = example_app and table_name = migrations and table_type = ‘BASE TABLE’)

这是找不到host,先把配置文件里面的url修改:

APP_URL=http://127.0.0.1

还是不行,百度后尝试修改系统hosts文件:

# To allow the same kube context to work on the host and the container:
127.0.0.1 kubernetes.docker.internal
# End of section
# 增加以下这一行
127.0.0.1 mysql

然后迁移,竟然成功了?这是为什么?不理解!!!

2021-10-26

使用composer安装语言包,出现错误:

Problem 1
- facade/ignition is locked to version 2.15.0 and an update of this package was not requested.
- facade/ignition 2.15.0 requires ext-curl * -> it is missing from your system. Install or enable PHP’s curl extension.
Problem 2
- phpunit/phpunit is locked to version 9.5.10 and an update of this package was not requested.
- phpunit/phpunit 9.5.10 requires ext-dom * -> it is missing from your system. Install or enable PHP’s dom extension.
Problem 3
- psr/log 2.0.0 requires php >=8.0.0 -> your php version (7.4.3) does not satisfy that requirement.
- laravel/framework v8.65.0 requires psr/log ^1.0 || ^2.0 -> satisfiable by psr/log[2.0.0].
- laravel/framework is locked to version v8.65.0 and an update of this package was not requested.

需要添加后缀: --ignore-platform-reqs

composer require "overtrue/laravel-lang:~4.0"  --ignore-platform-reqs

更新后点击出错:

chmod(): Operation not permitted

过了一会儿,再打开,就正常了。

添加 app/helpers.php文件,修改database.php文件后,composer dump-autoload 命令出错,

Script @php artisan package:discover –ansi handling the post-autoload-dump event returned with error code 255

或者是php版本要求8.0,而当前是7.4等等,先把php自动升级到最新版本:

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get upgrade php

使用这三条命令,可以自动把php升级到最新版本,原理不清……

再使用命令 composer dump-autoload 还是出错,这个时候只能回滚,把 config/database.php 里面到代码还原,把 $db_config = get_db_config(); 命令删掉,就正常了……

2021-10-27


迁移数据库出错:

SQLSTATE[42S01]: Base table or view already exists: 1050 Table ‘articles’ already exists (SQL: create table articles (id bigint unsigned not null auto_increment primary key, created_at timestamp null, updated_at timestamp null) default character set utf8mb4 collate ‘utf8mb4_unicode_ci’)

发现没有简单到解决方法,只能删库重建数据库,然后再执行迁移命令:

 php artisan migrate:refresh --seed

2021-11-02

今天启动docker发现端口被占用,web服务启动不了了。

Ports are not available: listen tcp 0.0.0.0:6379

搜到了答案,使用管理员cmd

net stop winnat

然后再重启docker,再启动web实例,

net start winnat

就可以了