我正在参加「豆包MarsCode初体验」php环境(mysql+redis)

507 阅读2分钟

替换镜像源debian11版本

sudo vi /etc/apk/sources.list
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free

deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free

deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free

# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
deb https://security.debian.org/debian-security bullseye-security main contrib non-free
# deb-src https://security.debian.org/debian-security bullseye-security main contrib non-free

执行更新

sudo apt-get update

添加php源

怎么找key参考 多版本php

`

sudo apt-get install ca-certificates apt-transport-https software-properties-common -y

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 14AA40EC0831756756D7F66C4F4EA0AAE5267A6C

sudo add-apt-repository ppa:ondrej/php

sudo apt-get update -y
sudo apt-get install php8.1 php8.1-swoole -y

`

记得改为 focal

cat /etc/apt/sources.list.d/ondrej-ubuntu-php-oracular.list
deb http://ppa.launchpad.net/ondrej/php/ubuntu focal main

codename.png

5ca1cce4-ba58-4374-b793-b0f191edb945.png

安装composer 下载说明

`

cd ~
sudo php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'dac665fdc30fdd8ec78b38b9800061b4150413ff2e3b6f88543c636f7cd84f6db9189d43a81e5503cda447da73c7e5b6') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
mv ./composer.phar /usr/local/bin/composer
#配置镜像
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/

`

QQ20240628-233141@2x.png

初始化laravel 项目

#安装laravel 需要扩展
sudo apt-get install -y php8.1-opcache php8.1-mysql php8.1-ctype php8.1-exif php8.1-fileinfo php8.1-curl php8.1-xml
composer create-project laravel/laravel laravel-db-redis
php artisan serve --host=0.0.0.0

server.png QQ20240628-234407@2x.png

安装redis

sudo apt-get install -y redis-server
# redis需要手动启动 因为不能通过systemctl start 启动
redis-server 

安装maridb

启动service 文件 因为不能通过systemctl start 启动
/etc/systemd/system/multi-user.target.wants/mariadb.service  /lib/systemd/system/mariadb.service

/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld
#启动mariadb 
/usr/sbin/mariadbd 
#进入数据库
sudo mariadb

mariadb.png

配置数据库

根据提示配置数据库密码

sudo mysql_secure_installation
mysql -uroot -p 进数据库(密码:上一步设置的密码)
create database laravel

peizhi.png

peizhi2.png

测试数据库 连通性

配置laravel项目.env

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=123456

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

php artisan migrate 执行成功说明 testdb.png

测试redis 连通性

php artisan make:command RedisTestCommand
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Redis;


class RedisTestCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'app:redis-test-command';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Execute the console command.
     */
    public function handle()
    {
        //
        Redis::set('test', 'test', 3600);
        $value = Redis::get('test');
        echo ($value);
    }
}

kuozhan.png

经常需要构建dockerfile 不想跳出到浏览器 到腾讯 coding, 阿里云ecr 可用docker buildx 插件配置远程构建