如何在Linux托管上使用PHP Composer

发布于 2025-02-12 04:44:55 字数 162 浏览 1 评论 0原文

我有Linux主机使用PHP代码。我正在开发示例PHP页面,并想将其转换为PDF文件。

当我进行一些研究时,我会遇到“作曲家需要DOMPDF/DOMPDF”样式方法。

但是,我不知道如何在Linux托管中使用Composer,如何在此处安装此插件。如果您能为此提供帮助,我会很高兴。

I have linux hosting to code with php. I am developing sample php page and I want to convert it to pdf file.

When I do some research, I come across 'composer require dompdf/dompdf' style usage methods.

However, I don't know how to use composer in linux hosting, how to install this plugin there. I would be very happy if you could help with this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

古镇旧梦 2025-02-19 04:44:55

这只是意味着您可以在服务器上安装DOMPDF,您可以使用Composer安装它并具有自动加载,也可以手动安装DOMPDF并需要文件。

为了做到这一点,您需要首先将作曲器安装到服务器上,请参阅

https://getcomposer.org/download/

安装作曲家后,您需要创建一个Composer.json文件(在线查找示例)和Composer.json文件。需要部分。

完成后,您需要在服务器上运行“作曲家安装”以安装DOMPDF。

这是我的一个项目之一的样本composer.json文件,这可能会根据您使用的框架(如果有)来有所不同:

    {
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "require": {
        "php": "^7.3|^8.0",
        "dompdf/dompdf": "^1.2",
        "fruitcake/laravel-cors": "^2.0",
        "guzzlehttp/guzzle": "^7.0.1",
        "laravel/breeze": "^1.4",
        "laravel/framework": "^8.65",
        "laravel/sanctum": "^2.11",
        "laravel/tinker": "^2.5",
        "aws/aws-sdk-php" : "3.222.16"
    },
    "require-dev": {
        "facade/ignition": "^2.5",
        "fakerphp/faker": "^1.9.1",
        "laravel/sail": "^1.0.1",
        "mockery/mockery": "^1.4.4",
        "nunomaduro/collision": "^5.10",
        "phpunit/phpunit": "^9.5.10"
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Database\\Factories\\": "database/factories/",
            "Database\\Seeders\\": "database/seeders/"
        },
        "files": [
            "app/Http/Helpers.php" 
        ]
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-update-cmd": [
            "@php artisan vendor:publish --tag=laravel-assets --ansi"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "minimum-stability": "dev",
    "prefer-stable": true
}

This just means that dompdf is not installed on the server you can either use composer to install it and have it autoload or you can manually install dompdf and require the files.

In order to do this you need to first install composer onto the server, see

https://getcomposer.org/download/

Once you have composer installed you need to create a composer.json file (look online for examples) and inside the composer.json file you need to add dompdf within the require section.

Once thats done you need to run "composer install" on the server to install dompdf.

Heres a sample composer.json file i have for one of my projects this can vary based on what framework (if any) your using:

    {
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "require": {
        "php": "^7.3|^8.0",
        "dompdf/dompdf": "^1.2",
        "fruitcake/laravel-cors": "^2.0",
        "guzzlehttp/guzzle": "^7.0.1",
        "laravel/breeze": "^1.4",
        "laravel/framework": "^8.65",
        "laravel/sanctum": "^2.11",
        "laravel/tinker": "^2.5",
        "aws/aws-sdk-php" : "3.222.16"
    },
    "require-dev": {
        "facade/ignition": "^2.5",
        "fakerphp/faker": "^1.9.1",
        "laravel/sail": "^1.0.1",
        "mockery/mockery": "^1.4.4",
        "nunomaduro/collision": "^5.10",
        "phpunit/phpunit": "^9.5.10"
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Database\\Factories\\": "database/factories/",
            "Database\\Seeders\\": "database/seeders/"
        },
        "files": [
            "app/Http/Helpers.php" 
        ]
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-update-cmd": [
            "@php artisan vendor:publish --tag=laravel-assets --ansi"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "minimum-stability": "dev",
    "prefer-stable": true
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文