- Recently I was working on upgrading PHPthe version, and by the way I upgraded the version at https://github.com/seth-shi/monday-shop
Contents
Already have a plan
- If you are willing to spend money, you can consider using https://laravelshift.com/
- You can also use this project to quickly compare the areas that need to be changed https://laravel-upgrade-helper.github.io/
Upgrade process
Project preparation
- Suppose my current project is called/var/www/monday-shop
- monday-shopCreate a new project within the project (- laravelconvenient to copy and paste files within the same project)- composer create-project laravel/laravel=10.* laravel10
- At this time, there is one more in the project/var/www/monday-shop/laravel10
 
Dependency handling
- Update dependencies
- Update the and parts to /var/www/monday-shop/laravel10/composer.json( note to delete the parts of the old version)requirerequire-dev/var/www/monday-shop/composer.json
- delete/var/www/monday-shop/composer.lock
 
- Update the and parts to 
- Install dependencies
- composer installWhen running , many errors will occur. You can only continue to update dependencies according to the errors reported.
- If the error is similar to the following, githubfindramsey/uuidthe configured version, modifycomposer.jsonthe file, and repeat steps 1 and 2.composer install No composer.lock file present. Updating dependencies to latest instead of installing from lock file. See https://getcomposer.org/install for more information. Loading composer repositories with package information Updating dependencies Your requirements could not be resolved to an installable set of packages. Problem 1 – laravel/framework[v10.10.0, …, v10.48.4] require ramsey/uuid ^4.7 -> found ramsey/uuid[4.7.0, …, 4.7.5] but it conflicts with your root composer.json require (^3.8).
 
- After upgrading, if you are not sure whether this dependency is useful, execute it composer depends xxx/xxxxto see if it is useful. If not, just delete it.
File changes
- Copy /var/www/monday-shop/laravel10the base file to/var/www/monday-shop/├─app │ ├─Console │ ├─Exceptions │ ├─Http │ │ ├─Controllers │ │ └─Middleware │ ├─Models │ └─Providers ├─bootstrap │ └─cache ├─config ├─database │ ├─factories │ ├─migrations │ └─seeders ├─public ├─resources │ ├─css │ ├─js │ └─views ├─routes ├─storage │ ├─app │ ├─framework │ └─logs ├─tests │ ├─Feature │ └─Unit
- For example app/Exceptions/Handler.php,app/Http/Kernel.phpwait, when copying the content of these files, you need to carefully compare whether you have modified them.
- When I process it, I usually process it one folder at a time, such as starting from app/Consolethe beginning
- Delete the directory after processing app/Console(deleting the directory is/var/www/monday-shop/laravel10)
- For the next directory app/Exceptions, repeat steps 1 and 2 until/var/www/monday-shop/laravel10the directory is empty.
Handle error reports
- Run the service:php artisan serve
- If there are any errors after running, solve them as needed. After starting the service, check storage/logsthe directory errors and solve them as needed.
- laravelThe function that may be encountered- helpersdoes not exist for execution- composer require laravel/helpers
Containerization
- After the upgrade is completed, the operating plan of https://github.com/hhxsv5/laravel-s is no longer needed.
- Change to the official permanent memory solution https://github.com/laravel/octane
composer require laravel/octane
- Containerization solution operation https://github.com/exaco/laravel-octane-dockerfile
- through supervisorctlmanagement process
- Support queue operation
- Support scheduled tasks
 
- through 
- File reference content
.rr.yaml
- If this occurs: RoadRunner can’t communicate with the worker
- Please modify it .rr.yamlto the following configuration. The mainlogs.channelsconfiguration is standard output.version: ‘3’ rpc: listen: ‘tcp://127.0.0.1:6001’ server: command: “” relay: pipes http: middleware: [ “static”, “gzip”, “headers” ] max_request_size: 20 access_logs: false static: dir: “public” forbid: [ “.php”, “.htaccess” ] uploads: forbid: [“.php”, “.exe”, “.bat”, “.sh”] address: “0.0.0.0:2114” pool: allocate_timeout: 10s destroy_timeout: 10s supervisor: max_worker_memory: 256 exec_ttl: 60s ## 这里注意如果要输出标准输出必须在 channels 才会写 stdout logs: mode: production level: debug encoding: console output: stderr err_output: stderr channels: http: mode: production level: panic encoding: console output: stdout err_output: stderr server: mode: production level: info encoding: json output: stdout err_output: stdout rpc: mode: production level: debug encoding: console output: stderr err_output: stdout status: address: localhost:2114
Dockerfile
FROM composer:latest AS vendor
FROM php:8.2-cli-bookworm AS base
ARG TZ=PRC
ENV DEBIAN_FRONTEND=noninteractive \
  TERM=xterm-color \
  OCTANE_SERVER=roadrunner \
  ROOT=/var/www \
  COMPOSER_FUND=0 \
  COMPOSER_MAX_PARALLEL_HTTP=24
WORKDIR ${ROOT}
SHELL ["/bin/bash", "-eou", "pipefail", "-c"]
RUN ln -snf /usr/share/zoneinfo/${TZ} /etc/localtime\
  && echo ${TZ} > /etc/timezone
################################################################################################
## Install dependencies
################################################################################################
ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
RUN apt-get update; \
  apt-get upgrade -yqq; \
  apt-get install -yqq --no-install-recommends --show-progress \
  apt-utils \
  curl \
  wget \
  nano \
  ncdu
  ca-certificates \
  supervisor \
  libsodium-dev \
  # Install PHP extensions
  && install-php-extensions \
  bz2\
  pcntl \
  mbstring \
  bcmath \
  sockets \
  pgsql \
  pdo_pgsql \
  opcache \
  exif \
  pdo_mysql \
  zip \
  intl \
  gd \
  redis \
  rdkafka\
  memcached \
  igbinary \
  ldap \
  && apt-get -y autoremove \
  && apt-get clean \
  && docker-php-source delete \
  && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
  && rm /var/log/lastlog /var/log/faillog
################################################################################################
## Copy code files and deployment files
################################################################################################
COPY  . .
COPY deployment/supervisord.*.conf /etc/supervisor/conf.d/
COPY deployment/php.ini ${PHP_INI_DIR}/conf.d/99-octane.ini
COPY deployment/start-container /usr/local/bin/start-container
################################################################################################
## Install dependencies
################################################################################################
COPY --from=vendor /usr/bin/composer /usr/bin/composer
RUN composer install \
  --no-dev \
  --no-interaction \
  --no-ansi
RUN if composer show | grep spiral/roadrunner-cli >/dev/null; then \
  ./vendor/bin/rr get-binary; else \
  echo "`spiral/roadrunner-cli` package is not installed. Exiting..."; exit 1; \
  be
################################################################################################
## Permission directory settings
################################################################################################
RUN chmod +x rr /usr/local/bin/start-container
RUN mkdir -p \
  storage/framework/{sessions,views,cache,testing} \
  storage/logs \
  bootstrap/cache && chmod -R a+rw storage
ENTRYPOINT ["start-container"]
HEALTHCHECK --start-period=5s --interval=2s --timeout=5s --retries=8 CMD php artisan octane:status || exit 1
php.ini
[PHP] post_max_size = 100M upload_max_filesize = 100M expose_php = 0 realpath_cache_size = 16M realpath_cache_ttl = 360 ;; 使用 roadrunner 开不开 opcache 影响不大 [Opcache] opcache.enable = 1 opcache.enable_cli = 0 opcache.memory_consumption = 128M opcache.use_cwd = 0 opcache.max_file_size = 0 opcache.max_accelerated_files = 32531 opcache.validate_timestamps = 0 opcache.file_update_protection = 0 opcache.interned_strings_buffer = 16 opcache.file_cache = 60 [JIT] opcache.jit_buffer_size = 64M opcache.jit = function opcache.jit_prof_threshold = 0.001 opcache.jit_max_root_traces = 2048 opcache.jit_max_side_traces = 256 [zlib] zlib.output_compression = On zlib.output_compression_level = 9
start.container
#!/usr/bin/env bash
set -e
container_mode=${CONTAINER_MODE:-http}
octane_server=${OCTANE_SERVER}
echo "Container mode: $container_mode"
initialStuff() {
    php artisan config:cache;
}
if [ "$1" != "" ]; then
    exec "$@"
elif [ ${container_mode} = "http" ]; then
    echo "Octane Server: $octane_server"
    initialStuff
    exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.roadrunner.conf
elif [ ${container_mode} = "scheduler" ]; then
    initialStuff
    exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.scheduler.conf
elif [ ${container_mode} = "worker" ]; then
    initialStuff
    exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.worker.conf
else
    echo "Container mode mismatched."
    exit 1
be
supervisord.roadrunner.conf
[supervisord] nodaemon=true user=root logfile=/dev/stdout logfile_maxbytes=0 pidfile=/var/run/supervisord.pid [supervisorctl] serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL for a unix socket [unix_http_server] file=/var/run/supervisor.sock ; (the path to the socket file) chmod=0700 ; sockef file mode (default 0700) [program:octane] process_name=%(program_name)s_%(process_num)02d command=php %(ENV_ROOT)s/artisan octane:start --server=roadrunner --host=0.0.0.0 --port=8080 --rpc-port=6001 --workers=4 --log-level=warn --max-requests=0 --rr-config=%(ENV_ROOT)s/deployment/.rr.yaml autostart=true autorestart=true environment=LARAVEL_OCTANE="1" stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 stderr_logfile=/dev/stderr stderr_logfile_maxbytes=0
Finish
- Then you can run it happily

