Mac搭建php的laravel开发环境

2024-01-03  本文已影响0人  liurongming

一、环境准备

上线用云服务器、开发用Mac系统。

# 直接登录
 ssh -p 22 -i /Users/neilliu/ssh_key/ss_cvm_root.pem root@xxx.xxx.xxx.xxx

# 添加免登录key
 ssh-add -k /Users/neilliu/ssh_key/ss_cvm_root.pem
# 官方下载地址
https://iterm2.com/documentation.html
image.png
# 官方地址
https://herd.laravel.com
image.png
所有项目都会使用该镜像地址:
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
取消配置:
composer config -g --unset repos.packagist
仅修改当前工程配置,仅当前工程可使用该镜像地址:
composer config repo.packagist composer https://mirrors.aliyun.com/composer/
取消配置:
composer config --unset repos.packagist

 {
  "repositories": [
       {
           "description": "阿里云镜像",
           "type": "composer",
            "url": "https://mirrors.aliyun.com/composer/",
           "canonical": false
         }
    ]
}
image.png

二、创建laravel项目

根据官网介绍操作,安装完成后,用phpstorm打开即可。

neilliu@NeilLiudeMac php % composer create-project laravel/laravel example-app
Creating a "laravel/laravel" project at "./example-app"
Installing laravel/laravel (v10.3.1)
  - Downloading laravel/laravel (v10.3.1)
  - Installing laravel/laravel (v10.3.1): Extracting archive
Created project in /Users/neilliu/Desktop/php/example-app
> @php -r "file_exists('.env') || copy('.env.example', '.env');"
Loading composer repositories with package information
Updating dependencies
Lock file operations: 111 installs, 0 updates, 0 removals
  - Locking brick/math (0.11.0)
  - Locking carbonphp/carbon-doctrine-types (2.1.0)
  - Locking dflydev/dot-access-data (v3.0.2)
  - Locking doctrine/inflector (2.0.8)
  - Locking doctrine/lexer (3.0.0)
  - Locking dragonmantank/cron-expression (v3.3.3)
  - Locking egulias/email-validator (4.0.1)
  - Locking fakerphp/faker (v1.23.0)
  - Locking filp/whoops (2.15.4)
  - Locking fruitcake/php-cors (v1.2.0)
  - Locking graham-campbell/result-type (v1.1.2)
  - Locking guzzlehttp/guzzle (7.8.1)
  - Locking guzzlehttp/promises (2.0.1)
  - Locking guzzlehttp/psr7 (2.6.2)
  - Locking guzzlehttp/uri-template (v1.0.2)
  - Locking hamcrest/hamcrest-php (v2.0.1)
  - Locking laravel/framework (v10.38.2)
  - Locking laravel/pint (v1.13.6)
  - Locking laravel/prompts (v0.1.13)
  - Locking laravel/sail (v1.26.3)
  - Locking laravel/sanctum (v3.3.2)
  - Locking laravel/serializable-closure (v1.3.3)
  - Locking laravel/tinker (v2.8.2)
  - Locking league/commonmark (2.4.1)
  - Locking league/config (v1.2.0)
  - Locking league/flysystem (3.22.0)
  - Locking league/flysystem-local (3.23.0)
  - Locking league/mime-type-detection (1.13.0)
  - Locking mockery/mockery (1.6.6)
  - Locking monolog/monolog (3.5.0)
  - Locking myclabs/deep-copy (1.11.1)
  - Locking nesbot/carbon (2.72.1)
  - Locking nette/schema (v1.2.5)
  - Locking nette/utils (v4.0.2)
  - Locking nikic/php-parser (v4.18.0)
  - Locking nunomaduro/collision (v7.10.0)
  - Locking nunomaduro/termwind (v1.15.1)
  - Locking phar-io/manifest (2.0.3)
  - Locking phar-io/version (3.2.1)
  - Locking phpoption/phpoption (1.9.2)
  - Locking phpunit/php-code-coverage (10.1.11)
  - Locking phpunit/php-file-iterator (4.1.0)
  - Locking phpunit/php-invoker (4.0.0)
  - Locking phpunit/php-text-template (3.0.1)
  - Locking phpunit/php-timer (6.0.0)
  - Locking phpunit/phpunit (10.5.5)
  - Locking psr/clock (1.0.0)
  - Locking psr/container (2.0.2)
  - Locking psr/event-dispatcher (1.0.0)
  - Locking psr/http-client (1.0.3)
  - Locking psr/http-factory (1.0.2)
  - Locking psr/http-message (2.0)
  - Locking psr/log (3.0.0)
  - Locking psr/simple-cache (3.0.0)
  - Locking psy/psysh (v0.11.22)
  - Locking ralouphie/getallheaders (3.0.3)
  - Locking ramsey/collection (2.0.0)
  - Locking ramsey/uuid (4.7.5)
  - Locking sebastian/cli-parser (2.0.0)
  - Locking sebastian/code-unit (2.0.0)
  - Locking sebastian/code-unit-reverse-lookup (3.0.0)
  - Locking sebastian/comparator (5.0.1)
  - Locking sebastian/complexity (3.2.0)
  - Locking sebastian/diff (5.0.3)
  - Locking sebastian/environment (6.0.1)
  - Locking sebastian/exporter (5.1.1)
  - Locking sebastian/global-state (6.0.1)
  - Locking sebastian/lines-of-code (2.0.2)
  - Locking sebastian/object-enumerator (5.0.0)
  - Locking sebastian/object-reflector (3.0.0)
  - Locking sebastian/recursion-context (5.0.0)
  - Locking sebastian/type (4.0.0)
  - Locking sebastian/version (4.0.1)
  - Locking spatie/backtrace (1.5.3)
  - Locking spatie/flare-client-php (1.4.3)
  - Locking spatie/ignition (1.12.0)
  - Locking spatie/laravel-ignition (2.3.3)
  - Locking symfony/console (v6.4.2)
  - Locking symfony/css-selector (v7.0.0)
  - Locking symfony/deprecation-contracts (v3.3.0)
  - Locking symfony/error-handler (v6.4.0)
  - Locking symfony/event-dispatcher (v7.0.0)
  - Locking symfony/event-dispatcher-contracts (v3.4.0)
  - Locking symfony/finder (v6.4.0)
  - Locking symfony/http-foundation (v6.4.2)
  - Locking symfony/http-kernel (v6.4.2)
  - Locking symfony/mailer (v6.4.2)
  - Locking symfony/mime (v6.4.0)
  - Locking symfony/polyfill-ctype (v1.28.0)
  - Locking symfony/polyfill-intl-grapheme (v1.28.0)
  - Locking symfony/polyfill-intl-idn (v1.28.0)
  - Locking symfony/polyfill-intl-normalizer (v1.28.0)
  - Locking symfony/polyfill-mbstring (v1.28.0)
  - Locking symfony/polyfill-php72 (v1.28.0)
  - Locking symfony/polyfill-php80 (v1.28.0)
  - Locking symfony/polyfill-php83 (v1.28.0)
  - Locking symfony/polyfill-uuid (v1.28.0)
  - Locking symfony/process (v6.4.2)
  - Locking symfony/routing (v6.4.2)
  - Locking symfony/service-contracts (v3.4.0)
  - Locking symfony/string (v7.0.2)
  - Locking symfony/translation (v6.4.2)
  - Locking symfony/translation-contracts (v3.4.1)
  - Locking symfony/uid (v6.4.0)
  - Locking symfony/var-dumper (v6.4.2)
  - Locking symfony/yaml (v6.4.0)
  - Locking theseer/tokenizer (1.2.1)
  - Locking tijsverkoyen/css-to-inline-styles (v2.2.7)
  - Locking vlucas/phpdotenv (v5.5.0)
  - Locking voku/portable-ascii (2.0.1)
  - Locking webmozart/assert (1.11.0)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 111 installs, 0 updates, 0 removals
  - Downloading spatie/ignition (1.12.0)
  - Installing doctrine/inflector (2.0.8): Extracting archive
  - Installing doctrine/lexer (3.0.0): Extracting archive
  - Installing symfony/polyfill-ctype (v1.28.0): Extracting archive
  - Installing webmozart/assert (1.11.0): Extracting archive
  - Installing dragonmantank/cron-expression (v3.3.3): Extracting archive
  - Installing symfony/deprecation-contracts (v3.3.0): Extracting archive
  - Installing psr/container (2.0.2): Extracting archive
  - Installing fakerphp/faker (v1.23.0): Extracting archive
  - Installing symfony/polyfill-php80 (v1.28.0): Extracting archive
  - Installing symfony/polyfill-php83 (v1.28.0): Extracting archive
  - Installing symfony/polyfill-mbstring (v1.28.0): Extracting archive
  - Installing symfony/http-foundation (v6.4.2): Extracting archive
  - Installing fruitcake/php-cors (v1.2.0): Extracting archive
  - Installing psr/http-message (2.0): Extracting archive
  - Installing psr/http-client (1.0.3): Extracting archive
  - Installing ralouphie/getallheaders (3.0.3): Extracting archive
  - Installing psr/http-factory (1.0.2): Extracting archive
  - Installing guzzlehttp/psr7 (2.6.2): Extracting archive
  - Installing guzzlehttp/promises (2.0.1): Extracting archive
  - Installing guzzlehttp/guzzle (7.8.1): Extracting archive
  - Installing guzzlehttp/uri-template (v1.0.2): Extracting archive
  - Installing laravel/pint (v1.13.6): Extracting archive
  - Installing symfony/polyfill-intl-normalizer (v1.28.0): Extracting archive
  - Installing symfony/polyfill-intl-grapheme (v1.28.0): Extracting archive
  - Installing symfony/string (v7.0.2): Extracting archive
  - Installing symfony/service-contracts (v3.4.0): Extracting archive
  - Installing symfony/console (v6.4.2): Extracting archive
  - Installing voku/portable-ascii (2.0.1): Extracting archive
  - Installing phpoption/phpoption (1.9.2): Extracting archive
  - Installing graham-campbell/result-type (v1.1.2): Extracting archive
  - Installing vlucas/phpdotenv (v5.5.0): Extracting archive
  - Installing symfony/css-selector (v7.0.0): Extracting archive
  - Installing tijsverkoyen/css-to-inline-styles (v2.2.7): Extracting archive
  - Installing symfony/var-dumper (v6.4.2): Extracting archive
  - Installing symfony/polyfill-uuid (v1.28.0): Extracting archive
  - Installing symfony/uid (v6.4.0): Extracting archive
  - Installing symfony/routing (v6.4.2): Extracting archive
  - Installing symfony/process (v6.4.2): Extracting archive
  - Installing symfony/polyfill-php72 (v1.28.0): Extracting archive
  - Installing symfony/polyfill-intl-idn (v1.28.0): Extracting archive
  - Installing symfony/mime (v6.4.0): Extracting archive
  - Installing psr/event-dispatcher (1.0.0): Extracting archive
  - Installing symfony/event-dispatcher-contracts (v3.4.0): Extracting archive
  - Installing symfony/event-dispatcher (v7.0.0): Extracting archive
  - Installing psr/log (3.0.0): Extracting archive
  - Installing egulias/email-validator (4.0.1): Extracting archive
  - Installing symfony/mailer (v6.4.2): Extracting archive
  - Installing symfony/error-handler (v6.4.0): Extracting archive
  - Installing symfony/http-kernel (v6.4.2): Extracting archive
  - Installing symfony/finder (v6.4.0): Extracting archive
  - Installing ramsey/collection (2.0.0): Extracting archive
  - Installing brick/math (0.11.0): Extracting archive
  - Installing ramsey/uuid (4.7.5): Extracting archive
  - Installing psr/simple-cache (3.0.0): Extracting archive
  - Installing nunomaduro/termwind (v1.15.1): Extracting archive
  - Installing symfony/translation-contracts (v3.4.1): Extracting archive
  - Installing symfony/translation (v6.4.2): Extracting archive
  - Installing psr/clock (1.0.0): Extracting archive
  - Installing carbonphp/carbon-doctrine-types (2.1.0): Extracting archive
  - Installing nesbot/carbon (2.72.1): Extracting archive
  - Installing monolog/monolog (3.5.0): Extracting archive
  - Installing league/mime-type-detection (1.13.0): Extracting archive
  - Installing league/flysystem (3.22.0): Extracting archive
  - Installing league/flysystem-local (3.23.0): Extracting archive
  - Installing nette/utils (v4.0.2): Extracting archive
  - Installing nette/schema (v1.2.5): Extracting archive
  - Installing dflydev/dot-access-data (v3.0.2): Extracting archive
  - Installing league/config (v1.2.0): Extracting archive
  - Installing league/commonmark (2.4.1): Extracting archive
  - Installing laravel/serializable-closure (v1.3.3): Extracting archive
  - Installing laravel/prompts (v0.1.13): Extracting archive
  - Installing laravel/framework (v10.38.2): Extracting archive
  - Installing symfony/yaml (v6.4.0): Extracting archive
  - Installing laravel/sail (v1.26.3): Extracting archive
  - Installing laravel/sanctum (v3.3.2): Extracting archive
  - Installing nikic/php-parser (v4.18.0): Extracting archive
  - Installing psy/psysh (v0.11.22): Extracting archive
  - Installing laravel/tinker (v2.8.2): Extracting archive
  - Installing hamcrest/hamcrest-php (v2.0.1): Extracting archive
  - Installing mockery/mockery (1.6.6): Extracting archive
  - Installing filp/whoops (2.15.4): Extracting archive
  - Installing nunomaduro/collision (v7.10.0): Extracting archive
  - Installing sebastian/version (4.0.1): Extracting archive
  - Installing sebastian/type (4.0.0): Extracting archive
  - Installing sebastian/recursion-context (5.0.0): Extracting archive
  - Installing sebastian/object-reflector (3.0.0): Extracting archive
  - Installing sebastian/object-enumerator (5.0.0): Extracting archive
  - Installing sebastian/global-state (6.0.1): Extracting archive
  - Installing sebastian/exporter (5.1.1): Extracting archive
  - Installing sebastian/environment (6.0.1): Extracting archive
  - Installing sebastian/diff (5.0.3): Extracting archive
  - Installing sebastian/comparator (5.0.1): Extracting archive
  - Installing sebastian/code-unit (2.0.0): Extracting archive
  - Installing sebastian/cli-parser (2.0.0): Extracting archive
  - Installing phpunit/php-timer (6.0.0): Extracting archive
  - Installing phpunit/php-text-template (3.0.1): Extracting archive
  - Installing phpunit/php-invoker (4.0.0): Extracting archive
  - Installing phpunit/php-file-iterator (4.1.0): Extracting archive
  - Installing theseer/tokenizer (1.2.1): Extracting archive
  - Installing sebastian/lines-of-code (2.0.2): Extracting archive
  - Installing sebastian/complexity (3.2.0): Extracting archive
  - Installing sebastian/code-unit-reverse-lookup (3.0.0): Extracting archive
  - Installing phpunit/php-code-coverage (10.1.11): Extracting archive
  - Installing phar-io/version (3.2.1): Extracting archive
  - Installing phar-io/manifest (2.0.3): Extracting archive
  - Installing myclabs/deep-copy (1.11.1): Extracting archive
  - Installing phpunit/phpunit (10.5.5): Extracting archive
  - Installing spatie/backtrace (1.5.3): Extracting archive
  - Installing spatie/flare-client-php (1.4.3): Extracting archive
  - Installing spatie/ignition (1.12.0): Extracting archive
  - Installing spatie/laravel-ignition (2.3.3): Extracting archive
42 package suggestions were added by new dependencies, use `composer suggest` to see details.
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi

   INFO  Discovering packages.

  laravel/sail .......................................................... DONE
  laravel/sanctum ....................................................... DONE
  laravel/tinker ........................................................ DONE
  nesbot/carbon ......................................................... DONE
  nunomaduro/collision .................................................. DONE
  nunomaduro/termwind ................................................... DONE
  spatie/laravel-ignition ............................................... DONE

83 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
> @php artisan vendor:publish --tag=laravel-assets --ansi --force

   INFO  No publishable resources for tag [laravel-assets].

No security vulnerability advisories found
> @php artisan key:generate --ansi

   INFO  Application key set successfully.

neilliu@NeilLiudeMac php %

此时,可用看到Herd界面中,已经出现访问域名。


image.png

Expose可共享给公网访问:


image.png

直接浏览器,访问“http://example-app.test”即可。点击安全锁,可一键开启https协议,省去很多配置。

image.png

至此,环境搭建完成。

三、云服务器部署常见问题

1.Permission denied The exception occurred while attempting to log
执行sudo chown -R www-data:www-data storage

The stream or file "/var/www/shop/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log: The stream or file

2.执行sudo apt install php-xml解决

Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - laravel/pint[v1.0.0, ..., v1.13.6] require ext-xml * -> it is missing from your system. Install or enable PHP's xml extension.
    - Root composer.json requires laravel/pint ^1.0 -> satisfiable by laravel/pint[v1.0.0, ..., v1.13.6].

3.执行sudo apt-get install php-curl解决

our requirements could not be resolved to an installable set of packages.

  Problem 1
    - spatie/laravel-ignition[2.0.0, ..., 2.3.3] require ext-curl * -> it is missing from your system. Install or enable PHP's curl extension.
    - Root composer.json requires spatie/laravel-ignition ^2.0 -> satisfiable by spatie/laravel-ignition[2.0.0, ..., 2.3.3].

To enable extensions, verify that they are enabled in your .ini files:

4.解决:Your Composer dependencies require a PHP version ">= 8.2.0".

Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.2.0".
 "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true,
        "allow-plugins": {
            "pestphp/pest-plugin": true,
            "php-http/discovery": true
        },
        "platform-check": false
    },
上一篇下一篇

猜你喜欢

热点阅读