お久しぶりです☺️
Symfonyを使っているにもかかわらず、symfony
コマンド使ってないなー
と今更感じたので、この記事を書きます。
はじめに
私の場合、Symfony2,3で使っていたSymfony installerを削除する必要がありました。
symfony
というコマンド名でバッテングしてるので、Symfony4からdepricatedになったSymfony installerを削除→Symfony CLIをインストールという手順をしました。
(※ composerを使えば良い話なんですが、symfonyコマンド使ってみたかったので)
Symfony installerが入っている状態
$ symfony Symfony Installer (1.5.11) ========================== This is the official installer to start new projects based on the Symfony full-stack framework. ...
ここで、symfony new
でプロジェクトを作成しようとすると、
Symfony InstallerはSymfony4から互換性(compatible)なくなったよーって言われました。
また、Symfony4から代わりにcomposer create-project symfony/skeleton [my_project_name]
を使ってねーって言ってます。
$ symfony new my_project PHP Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in phar:///usr/local/bin/symfony/vendor/guzzlehttp/ringphp/src/Client/CurlFactory.php on line 363 PHP Stack trace: ... [RuntimeException] The Symfony Installer is not compatible with Symfony 4.x or newer versions. Run this other command to install Symfony using Composer instead: composer create-project symfony/skeleton my_project
一瞬、Symfony4からsymfony
コマンドなくなった?って思いましたが、Symfony4.4のBestPracticeでしっかり使っているので、少し混乱しました😅
参考:
- https://symfony.com/blog/the-end-of-the-symfony-installer
- https://symfony.com/doc/4.4/best_practices.html
- https://symfony.com/download
SymfonyInstallerを削除して、SymfonyCLIをinstallする。
あまり良くない消し方な気がしますが、以下の方法でSymfonyInstallerを消しました。
$ ls -al ~/.symfony total 0 drwxr-xr-x 3 watashi staff 96 4 4 20:51 . drwxr-xr-x+ 118 watashi staff 3776 4 20 18:45 .. drwxr-xr-x 3 watashi staff 96 4 21 09:23 bin $ ls -al /usr/local/bin/symfony -rwxr-xr-x 1 watashi staff 246243 7 4 2019 /usr/local/bin/symfony $ rm -rf ~/.symfony $ rm -rf /usr/local/bin/symfony $ symfony -V -bash: /usr/local/bin/symfony: No such file or directory
そして、SymfonyCLIをインストールします🚀
$ curl -sS https://get.symfony.com/cli/installer | bash Symfony CLI installer Environment check [*] cURL is installed [*] Gzip is installed [*] Git is installed [*] You architecture (amd64) is supported Download Finding the latest version (platform: "darwin_amd64")... Downloading version 4.14.1 (https://github.com/symfony/cli/releases/download/v4.14.1/symfony_darwin_amd64.gz)... % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 636 100 636 0 0 1311 0 --:--:-- --:--:-- --:--:-- 1311 100 7909k 100 7909k 0 0 878k 0 0:00:09 0:00:09 --:--:-- 1443k Uncompress binary... Making the binary executable... Installing the binary into your home directory... The binary was saved to: /Users/watashi/.symfony/bin/symfony The Symfony CLI v4.14.1 was installed successfully! Use it as a local file: /Users/watashi/.symfony/bin/symfony Or add the following line to your shell configuration file: export PATH="$HOME/.symfony/bin:$PATH" Or install it globally on your system: mv /Users/watashi/.symfony/bin/symfony /usr/local/bin/symfony Then start a new shell and run 'symfony' $ mv /Users/watashi/.symfony/bin/symfony /usr/local/bin/symfony
うぉー!Symfony CLIが入りましたー!!! 🎉
$ symfony Symfony CLI version v4.14.1 (c) 2017-2020 Symfony SAS Symfony CLI helps developers manage projects, from local code to remote infrastructure These are common commands used in various situations: Work on a project locally new Create a new Symfony project serve Run a local web server server:stop Stop the local web server security:check Check security issues in project dependencies composer Runs Composer without memory limit console Runs the Symfony Console (bin/console) for current project php, pecl, pear, php-fpm, php-cgi, php-config, phpdbg, phpize Runs the named binary using the configured PHP version Manage a project on Cloud login Log in with your SymfonyConnect account init Initialize a new project using templates link Link current git repository to a SymfonyCloud project projects List active projects envs List environments env:create Create an environment tunnel:open Open SSH tunnels to the app's services ssh Open an SSH connection to the app container deploy Deploy an environment domains List domains vars List variables user:add Add a user to the project Show all commands with symfony help, Get help for a specific command with symfony help COMMAND.
Symfony CLIを使ってみる
プロジェクトを作成してみます。
今回は、webアプリケーションを作ってみます。
composer create-project symfony/website-skeleton [project_name]
とgit init
をしていることがわかります。
$ symfony new symfony_command_test_web_app --full * Creating a new Symfony project with Composer (running /usr/local/bin/composer create-project symfony/website-skeleton /Users/watashi/symfony_command_test_web_app) * Setting up the project under Git version control (running git init /Users/watashi/symfony_command_test_web_app) [OK] Your project is now ready in /Users/watashi/symfony_command_test_web_app
symfony server:start
を使ってローカルサーバを立てて、ブラウザを確認してみると…いい感じにSymfony5.0.8のwelcomeページが表示されましたー!🍺
$ symfony server:start [WARNING] run "symfony server:ca:install" first if you want to run the web server with TLS support, or use "--no-tls" to avoid this warning Apr 29 11:13:01 |DEBUG| PHP Reloading PHP versions Apr 29 11:13:01 |DEBUG| PHP Using PHP version 7.3.11 (from default version in $PATH) Apr 29 11:13:01 |INFO | PHP listening path="/usr/sbin/php-fpm" php="7.3.11" port=55287 Apr 29 11:13:01 |DEBUG| PHP started Apr 29 11:13:01 |INFO | PHP 'user' directive is ignored when FPM is not running as root Apr 29 11:13:01 |INFO | PHP 'group' directive is ignored when FPM is not running as root Apr 29 11:13:01 |INFO | PHP fpm is running, pid 3483 Apr 29 11:13:01 |INFO | PHP ready to handle connections [OK] Web server listening The Web server is using PHP FPM 7.3.11 http://127.0.0.1:8000
symfony server:ca:install
をしたら、TLSで確認できるらしいので、入れてみる🔐
を「https://」になったー!ブラウザもちゃんとみれる👀
$ symfony server:start Apr 29 11:29:01 |DEBUG| PHP Reloading PHP versions Apr 29 11:29:02 |DEBUG| PHP Using PHP version 7.3.11 (from default version in $PATH) Apr 29 11:29:02 |INFO | PHP listening path="/usr/sbin/php-fpm" php="7.3.11" port=55368 Apr 29 11:29:02 |DEBUG| PHP started Apr 29 11:29:02 |INFO | PHP 'user' directive is ignored when FPM is not running as root Apr 29 11:29:02 |INFO | PHP 'group' directive is ignored when FPM is not running as root Apr 29 11:29:02 |INFO | PHP fpm is running, pid 12395 Apr 29 11:29:02 |INFO | PHP ready to handle connections [OK] Web server listening The Web server is using PHP FPM 7.3.11 https://127.0.0.1:8000
さいごに
今までは、composer
でプロジェクトを作って、php -S 127.0.0.1:8880 -t public/
でブラウザ確認をしていたので、symfony
コマンドの方が短いので使って楽したほうがいいなーと思いました。