使用GitLab Runner为基于Laravel的PHP项目进行部署

当使用GitLab Runner为基于Laravel的PHP项目进行部署时,你可以创建一个.gitlab-ci.yml文件来配置CI/CD流水线。下面是一个示例配置,你可以根据你的项目需求进行适当的修改:

stages:
  - build
  - deploy

variables:
  APP_ENV: production
  DB_HOST: your_database_host
  DB_DATABASE: your_database_name
  DB_USERNAME: your_database_username
  DB_PASSWORD: your_database_password

cache:
  paths:
    - vendor/

before_script:
  - apt-get update
  - apt-get install -y unzip
  - curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
  - cp .env.example .env
  - composer install --no-interaction --prefer-dist --no-suggest
  - php artisan key:generate
  - php artisan config:cache

build:
  stage: build
  script:
    - php artisan route:cache
    - php artisan view:cache
    - php artisan optimize

deploy_production:
  stage: deploy
  script:
    - ssh deploy@your_server 'cd /var/www/html && git pull origin master'
    - ssh deploy@your_server 'cd /var/www/html && composer install --no-dev --optimize-autoloader'
    - ssh deploy@your_server 'cd /var/www/html && php artisan migrate --force'
    - ssh deploy@your_server 'cd /var/www/html && php artisan config:cache'
    - ssh deploy@your_server 'cd /var/www/html && php artisan route:cache'
    - ssh deploy@your_server 'cd /var/www/html && php artisan view:cache'

请注意,上述配置假设你已经在服务器上设置了适当的部署用户(deploy)和相关权限。确保将your_database_hostyour_database_nameyour_database_usernameyour_database_password替换为实际的数据库连接信息。

此配置文件的关键点如下:

  1. before_script阶段,我们安装依赖、生成密钥并进行配置缓存。
  2. build阶段用于优化Laravel项目。
  3. deploy_production阶段连接到你的服务器,执行必要的操作,例如从Git拉取代码、安装依赖、运行数据库迁移,并缓存配置、路由和视图。

请根据你的具体要求进行适当的调整和自定义。

装个服务器

yum install https://mirrors.tuna.tsinghua.edu.cn/remi/enterprise/remi-release-9.rpm

yum install php81-php php81-php-process supervisor tar unzip php81-php-pecl-zip php81-php-gd redis php81-php-mysqlnd php81-php-pecl-redis5

systemctl start redis

/usr/bin/python3 /usr/bin/supervisord -c /etc/supervisord.conf

php81 -r “copy(‘https://install.phpcomposer.com/installer’, ‘composer-setup.php’);”

php81 composer-setup.php

mv composer.phar /usr/local/bin/composer

* * * * * cd /data/isseymiyake-main && php81 artisan schedule:run >> /dev/null 2>&1

python -m ensurepip –upgrade

python -m pip install –upgrade pip

pip install requests

pip install beautifulsoup4

docker-compose up -d –build

主题手册

Welcome to the WordPress Theme Developer Handbook, your resource for learning all about the exciting world of WordPress themes. 

欢迎来到WordPress主题开发人员手册,这是您学习WordPress主题令人兴奋的世界的资源。

The Theme Developer Handbook is a repository for all things WordPress themes. Whether you’re new to WordPress themes, or you’re an experienced theme developer, you should be able to find the answer to many of your theme-related questions right here.

主题开发手册是WordPress主题的所有内容的存储库。无论您是WordPress主题的新手,还是经验丰富的主题开发人员,您都应该能够在这里找到许多主题相关问题的答案。

In this section, you can learn how to build the classic or block themes. The classic theme is the original theme that primarily uses PHP. The block theme is a newer theme that is built mainly using HTML. The block theme is composed entirely of blocks allowing users to take full advantage of the full site editor.

在本节中,您可以学习如何构建经典主题或块主题。经典主题是主要使用PHP的原始主题。块主题是主要使用HTML构建的较新主题。块主题完全由块组成,允许用户充分利用完整的站点编辑器。

Head over to the Block Editor Handbook if you are interested in learning about the block theme.

如果您有兴趣了解块主题,请参阅块编辑器手册。

Continue reading if you are interested in building the classic theme.

如果您对构建经典主题感兴趣,请继续阅读。

  1. If you’re new to developing WordPress themes, start with section 1, where you can find out what a theme is, learn about WordPress’ licenseset up your development environment, and build your first theme.
  2. Once you’re through the introduction, the Theme Basics section will introduce you to the building blocks of a WordPress theme.
  3. The Theme Functionality section will show you all of the different types of functionality you can make use of in your theme.
  4. If you’re looking to give flexibility and yet protect your users, head over to the Customizer and Security sections
  5. If you’ve got to grips with the basics of themes, check out the Advanced Theme Topics to learn about child themes, best UI practices, theme testing and more.
  6. Once you’ve got your theme ready for the world, the final section will cover releasing your theme, teaching you some best practices for theme distribution, and for getting it ready for the WordPress.org theme directory.

Tip:If you want to learn about block themes go to the Block Editor Handbook.

The WordPress Theme Developer Handbook is created by the WordPress community, for the WordPress community. We are always looking for more contributors; if you’re interested stop by the docs team blog to find out more about getting involved.

使用Let’s Encrypt的acme.sh申请泛域名证书

自已的网站如果使用https的话,要不然用阿里的一年免费证书,但是只能一个一个的申请没有办法用泛域名,如果申请收费的话,太贵了,我们这次用Let’s Encrypt的acme.sh来处理泛域名的https证书的问题

acme的github地址是https://github.com/acmesh-official/acme.sh,安装说明有中文版,所以以实例说明

背景:常用的一个开发域名hidev.cn,里面有code,sonar,还有和小程序对接的api等,这些都需要https的证书,哪么我们需要这么干

一、安装acme

curl https://get.acme.sh | sh

安装的时候,经会干这么几件事:

1、安装acme

2、创建一个crontabe,每天0点执行检查

二、DNSPOD配置域名

在dnspod的管理界面,右上角的头象,点一下,然后点击密钥管理(2020年11月11日版本),然后创建一个密钥出来,保存一下

三、配置证书

export DP_Id=”11111″

export DP_Key=”11111″

.acme.sh/acme.sh –issue –dns dns_dp -d *.haoxiaokai.com -d haoxiaokai.com

.acme.sh/acme.sh –install-cert -d *.haoxiaokai.com –key-file /etc/nginx/conf.d/haoxiaokaifull.key –fullchain-file /etc/nginx/conf.d/haoxiaokaifull.cer –reloadcmd “service nginx force-reload”

acme会自动的记录下来你执行的命令,然后每天判断证书有没有过期,如果有过期,就会帮你执行

Git 默认不区分大小写

Git默认是不区分大小写的,造成了不同环境对于大小写区分/不区分造成了问题。

可以通过git config –get core.ignorecase 查看默认配置

通过git config core.ignorecase false设置为区分大小写

然后git status 就可以看到变动

然后push到远程服务器

git增量更新打包

有两种方法,都使用了git diff的命令特性

一、使用管道命令进行打包

git diff 5fa8cc3140b4 10c5ff6bd05c –name-only | xargs tar -zcvf update.tar.gz

git diff出两个版本之间变化的文件,然后用管道命令,对他们进行打包

二、使用git archive命令进行导出

git archive -o update.tar.gz HEAD $(git diff 5fa8cc3140b4 10c5ff6bd05c –name-only )

特殊说明,如果两个版本之间有删除文件的操作,哪么两条命令都会出错,因为对应的文件找不到,这个时需要用到git diff的–diff-filter 参数,把删除的文件排除掉

所以以上两条命令会是

git diff –diff-filter=ACMR 5fa8cc3140b4 10c5ff6bd05c –name-only | xargs tar -zcvf update.tar.gz

git archive -o update.tar.gz HEAD $(git diff –diff-filter=ACMR 5fa8cc3140b4 10c5ff6bd05c –name-only )