{"id":20441716,"url":"https://github.com/mix-php/web-skeleton","last_synced_at":"2026-04-16T16:02:57.212Z","repository":{"id":57017812,"uuid":"385177666","full_name":"mix-php/web-skeleton","owner":"mix-php","description":"Web development skeleton","archived":false,"fork":false,"pushed_at":"2023-04-19T02:02:25.000Z","size":59,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-16T02:47:46.132Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mix-php.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-07-12T08:29:48.000Z","updated_at":"2022-04-15T15:32:26.000Z","dependencies_parsed_at":"2024-11-15T09:36:32.180Z","dependency_job_id":"f3f34db0-1349-4899-9ac2-b23467ff1392","html_url":"https://github.com/mix-php/web-skeleton","commit_stats":{"total_commits":38,"total_committers":3,"mean_commits":"12.666666666666666","dds":"0.23684210526315785","last_synced_commit":"1adb7543838536f424ca488ffbcfe31467704aae"},"previous_names":[],"tags_count":31,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mix-php%2Fweb-skeleton","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mix-php%2Fweb-skeleton/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mix-php%2Fweb-skeleton/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mix-php%2Fweb-skeleton/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mix-php","download_url":"https://codeload.github.com/mix-php/web-skeleton/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241989845,"owners_count":20053803,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-15T09:34:24.102Z","updated_at":"2026-04-16T16:02:57.136Z","avatar_url":"https://github.com/mix-php.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Web development skeleton\n\n帮助你快速搭建 Web 项目骨架，并指导你如何使用该骨架的细节，骨架默认开启了 SQL、Redis 日志，压测前请先关闭 `.env` 的 `APP_DEBUG`\n\n## 安装\n\n\u003e 需要先安装 [Swoole](https://wiki.swoole.com/#/environment) 或者 [WorkerMan](http://doc.workerman.net/install/requirement.html)\n\n```\ncomposer create-project --prefer-dist mix/web-skeleton web\n```\n\n## 快速开始\n\n启动 [cli-server](https://www.php.net/manual/zh/features.commandline.webserver.php) 开发服务 (零依赖)\n\n```\ncomposer run-script --timeout=0 cliserver:start\n```\n\n启动 Swoole 多进程服务\n\n```\ncomposer run-script --timeout=0 swoole:start\n```\n\n启动 Swoole 协程服务\n\n```\ncomposer run-script --timeout=0 swooleco:start\n```\n\n启动 Swow 协程服务\n\n\u003e 需自行安装 `composer require swow/swow:develop` 注意：swow 不支持 PHP 8.0 以下版本\n\n```\ncomposer run-script --timeout=0 swow:start\n```\n\n启动 WorkerMan 多进程服务\n\n```\ncomposer run-script --timeout=0 workerman:start\n```\n\n## 执行脚本\n\n- `composer run-script` 命令中的 `--timeout=0` 参数是防止 composer [执行超时](https://getcomposer.org/doc/06-config.md#process-timeout)\n- `composer.json` 定义了命令执行脚本，对应上面的执行命令\n\n```json\n\"scripts\": {\n    \"cliserver:start\": \"php -S localhost:8000 -t public\",\n    \"swoole:start\": \"php bin/swoole.php\",\n    \"swooleco:start\": \"php bin/swooleco.php\",\n    \"workerman:start\": \"php bin/workerman.php start\",\n    \"cli:clearcache\": \"php bin/cli.php clearcache\"\n}\n```\n\n当然也可以直接下面这样启动，效果是一样的，但是 `scripts` 能帮你记录到底有哪些可用的命令，同时在IDE中调试更加方便。\n\n```\nphp bin/swoole.php start\n```\n\n## 编写一个 Web 页面\n\n首先修改根目录 `.env` 文件的数据库信息\n\n然后在 `routes/index.php` 定义一个新的路由\n\n```php\n$vega-\u003ehandle('/', [new Hello(), 'index'])-\u003emethods('GET');\n```\n\n路由里使用了 `Hello` 控制器，我们需要创建他\n\n- 如何配置路由：[mix/vega](https://github.com/mix-php/vega#readme)\n\n```php\n\u003c?php\n\nnamespace App\\Controller;\n\nuse Mix\\Vega\\Context;\n\nclass Hello\n{\n\n    /**\n     * @param Context $ctx\n     */\n    public function index(Context $ctx)\n    {\n        $ctx-\u003eHTML(200, 'index', [\n            'title' =\u003e 'Hello, World!'\n        ]);\n    }\n\n}\n```\n\n在 `views` 目录创建 `index.php` 视图文件\n\n```php\n\u003chtml\u003e\n\u003ch1\u003e\n    \u003c?= $title ?\u003e\n\u003c/h1\u003e\n\u003c/html\u003e\n```\n\n重新启动服务器后方可测试新开发的接口\n\n\u003e 实际开发中使用 PhpStorm 的 Run 功能，只需要点击一下重启按钮即可\n\n```\n// 查找进程 PID\nps -ef | grep swoole\n\n// 通过 PID 停止进程\nkill PID\n\n// 重新启动进程\ncomposer run-script swoole:start\n\n// curl 测试\ncurl http://127.0.0.1:9501/\n```\n\n## 使用容器中的对象\n\n容器采用了一个简单的单例模式，你可以修改为更加适合自己的方式。\n\n- 数据库：[mix/database](https://github.com/mix-php/database#readme)\n\n```\nDB::instance()\n```\n\n- Redis：[mix/redis](https://github.com/mix-php/redis#readme)\n\n```\nRDS::instance()\n```\n\n- 日志：[monolog/monolog](https://seldaek.github.io/monolog/doc/01-usage.html)\n\n```\nLogger::instance()\n```\n\n- 配置：[hassankhan/config](https://github.com/hassankhan/config#getting-values)\n\n```\nConfig::instance()\n```\n\n## 部署\n\n- CLI\n\n线上部署启动时，修改 `shell/server.sh` 脚本中的绝对路径和参数\n\n```\nphp=/usr/local/bin/php\nfile=/project/bin/swoole.php\ncmd=start\nnumprocs=1\n```\n\n启动管理\n\n```\nsh shell/server.sh start\nsh shell/server.sh stop\nsh shell/server.sh restart\n```\n\n使用 `nginx` 或者 `SLB` 代理到服务器端口即可\n\n```\nserver {\n    server_name www.domain.com;\n    listen 80; \n    root /data/project/public;\n\n    location / {\n        proxy_http_version 1.1;\n        proxy_set_header Connection \"keep-alive\";\n        proxy_set_header Host $http_host;\n        proxy_set_header Scheme $scheme;\n        proxy_set_header X-Real-IP $remote_addr;\n        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n        if (!-f $request_filename) {\n             proxy_pass http://127.0.0.1:9501;\n        }\n    }\n}\n```\n\n- PHP-FPM\n\n和 Laravel、ThinkPHP 部署方法完全一致，将 `public/index.php` 在 `nginx` 配置 `rewrite` 重写即可\n\n```\nserver {\n    server_name www.domain.com;\n    listen 80;\n    root /data/project/public;\n    index index.html index.php;\n\n    location / {\n        if (!-e $request_filename) {\n            rewrite ^/(.*)$ /index.php/$1 last;\n        }\n    }\n\n    location ~ ^(.+\\.php)(.*)$ {\n        fastcgi_pass 127.0.0.1:9000;\n        fastcgi_split_path_info ^(.+\\.php)(.*)$;\n        fastcgi_param PATH_INFO $fastcgi_path_info;\n        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\n        include fastcgi_params;\n    }\n}\n```\n\n## License\n\nApache License Version 2.0, http://www.apache.org/licenses/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmix-php%2Fweb-skeleton","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmix-php%2Fweb-skeleton","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmix-php%2Fweb-skeleton/lists"}