Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add php install/uninstall script #87

Merged
merged 1 commit into from
Jun 13, 2024

Conversation

florentdestremau
Copy link
Contributor

@florentdestremau florentdestremau commented Jun 11, 2024

Fixes #73

  • install PHP using apt, with some common extensions (e.g. all 3 main db drivers)
  • install composer (package manager)
  • [RFC: bonus] install the symfony binary
  • uninstall script following uninstall codestyle

According to Laravel docs, the initial setup has all tools included (namely the artisan console). I'm not Laravel dev so I can't guarantee it's sufficient.

@florentdestremau florentdestremau force-pushed the feature/add-php branch 2 times, most recently from c7fddf7 to 80845e2 Compare June 11, 2024 13:20
@florentdestremau florentdestremau changed the title Add php install script Add php install/uninstall script Jun 11, 2024
@tonysm
Copy link
Contributor

tonysm commented Jun 11, 2024

They're using Mise to install Node, Ruby, and Go, can we just use that instead? I've been using ASDF for ages myself, so Mise should just work. It should automatically install Composer too. IMO, the PHP setup should be similar to what they did for Go here. So:

  • Install PHP via Mise
  • Enable the LazyVIM extras for PHP development (docs)
  • Install the VSCode extensions for folks that want to use VSCode (I guess only the main ones for Laravel/Symfony development?)

Now, we might need some extra stuff for Laravel, though. The PHP extras are too verbose for my taste and it doesn't seem to cover Blade (Laravel's template engine syntax).

@florentdestremau
Copy link
Contributor Author

I don't see any php docs for Mise. I've been developping for 10 years in PHP and apt install was more than enough, I don't see any solution having a large adoption other than Docker-based setups. FrankenPHP is moving up tho, but still early days to make it a default.

I agree I could add the lazyvim extras + vscode. I use phpstorm, in my PHP/Symfony circles this seems to be the default, so I'm not very familiar with other IDE / editors. I have a personal fork with PhpStorm configured but I figure it's maybe too much here

@tonysm
Copy link
Contributor

tonysm commented Jun 11, 2024

Mise seems to rely on ASDF plugins, so we might be able to mise use --global php@latest (or mise use --global php@8.3 for a specific version) and it should work.

Omakub seems to be either Neovim or VSCode, so other IDEs would have to be installed separately. It's about getting a good experience out of the box with Neovim and VSCode for PHP development too (for the mainstream frameworks, like Laravel and Symfony).

@florentdestremau
Copy link
Contributor Author

florentdestremau commented Jun 11, 2024

The asdf package for php doesn't seem very active to me.

When trying to install with mise I get this error output:

configure: error: re2c 1.0.3 is required to generate PHP lexers.
[ERROR] ~/.local/share/mise/plugins/php/bin/install failed
Error: 
   0: ~/.local/share/mise/plugins/php/bin/install exited with non-zero status: exit code 1

Location:
   src/plugins/script_manager.rs:178

Version:
   2024.6.3 linux-x64 (f01cc8d 2024-06-10)

  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ BACKTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
                                ⋮ 2 frames hidden ⋮                               
   3: mise::plugins::script_manager::ScriptManager::run_by_line::hce4bd13bb47001c1
      at <unknown source file>:<unknown line>
   4: <mise::backend::asdf::Asdf as mise::backend::Backend>::install_version_impl::hd8ddf3de6b021ea7
      at <unknown source file>:<unknown line>
   5: mise::backend::Backend::install_version::h31783059b441f187
      at <unknown source file>:<unknown line>
   6: std::sys_common::backtrace::__rust_begin_short_backtrace::h554f9ad47502887c
      at <unknown source file>:<unknown line>
   7: core::ops::function::FnOnce::call_once{{vtable.shim}}::he7b0f19ed095a00d
      at <unknown source file>:<unknown line>
   8: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h19b9e642d37e7272
      at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/alloc/src/boxed.rs:2020
   9: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h97265befc434d3ae
      at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/alloc/src/boxed.rs:2020
  10: std::sys::pal::unix::thread::Thread::new::thread_start::h420dad5cf01a9f35
      at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/sys/pal/unix/thread.rs:108
  11: start_thread<unknown>
      at ./nptl/pthread_create.c:447
  12: __GI___clone3<unknown>
      at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78

Run with COLORBT_SHOW_HIDDEN=1 environment variable to disable frame filtering.
Run with RUST_BACKTRACE=full to include source snippets.

Honnestly this really feels like shoehorning a mediocre solution that isn't quite needed: PHP installs perfectly fine with apt packages, that's how servers are configured, that's how Dockerfiles are configured...why try to force Mise ?

As for the editor I totally undestand that vscode and neovim are to be preferred, that's why I'm not including phpstorm here

@tonysm
Copy link
Contributor

tonysm commented Jun 11, 2024

I just switched from ASDF to Mise here, looks like it works:

mise use -y -g php@8.3

But I had it installed via ASDF, so I guess I had all the dependencies installed already (here, as mentioned in the docs).

@gcavanunez
Copy link

Yeah I'd also +1 opting to use mise over apt given it's what is being used for the other languages (Ruby, Node, and Go )

For extras specific to Laravel, aside from adding lazyvim.plugins.extras.lang.php (in configs/neovim/lazyvim.json), since Alpine.js is often used, we might be able to get some extras goodies by including the following.

From tree-sitter-blade discussion
nvim/after/queries/html/injections.scm

;; extends

; AlpineJS attributes
(attribute
  (attribute_name) @_attr
    (#lua-match? @_attr "^x%-%l")
  (quoted_attribute_value
    (attribute_value) @injection.content)
  (#set! injection.language "javascript"))

However since I think we're aiming at keeping config low, we may be able to upstreaming to LazyVim, since it looks like the extras for php has been added recently.

@roelandxyz
Copy link
Contributor

The composer install will stop working if there is a new version.

WARNING: Please do not redistribute the install code. It will change with every version of the installer. Instead, please link to this page or check how to install Composer programmatically.

@osbre
Copy link

osbre commented Jun 12, 2024

The installation should also include composer bin directory path so that the globally installed CLI apps work.

composer global require laravel/installer

I.e. this package would make the laravel command available in the system provided that composer bin path is properly setup.

@roelandxyz
Copy link
Contributor

roelandxyz commented Jun 13, 2024

The installation should also include composer bin directory path so that the globally installed CLI apps work.

composer global require laravel/installer

I.e. this package would make the laravel command available in the system provided that composer bin path is properly setup.

It already does. I tested Laravel and Symfony with sucess. Only the php version should be added.

@csfh
Copy link

csfh commented Jun 13, 2024

Will definitely review in the morning ET.

Updated sqlite extension name

Added uninstall script

Removed ppa for PHP as 24.04 is already at latest

Updated composer install script

Added back ondrej/ppa and fixed uninstaller

Revert back to using ondrej/php
@florentdestremau
Copy link
Contributor Author

I squashed all commits into one. With this we have the minimal setup for any PHP project, without opiniated choice regarding Symfony / Laravel.

@osbre
Copy link

osbre commented Jun 13, 2024

@roelandmoors I was referring about having this line in ~/.bashrc:

export PATH="$PATH:$HOME/.config/composer/vendor/bin"

Or this one in ~/.zshrc :

export PATH=~/.composer/vendor/bin:$PATH

I don't understand how globally installed composer CLI packages would work without having composer's directory in path. And the Symfony CLI you mentioned wouldn't qualify for this test, as it can't be installed via Composer. (unlike Laravel, thus check the the previous composer command usage example)

@csfh
Copy link

csfh commented Jun 13, 2024

I do believe we need to add the composer bin to PATH.

@roelandxyz
Copy link
Contributor

It is already moved to /usr/local/bin:
php composer-setup.php --quiet && sudo mv composer.phar /usr/local/bin/composer

I tested an earlier version of this PR so maybe I'm wrong, but this seems enough te me?

@osbre
Copy link

osbre commented Jun 13, 2024

@roelandmoors but that's the composer installation itself, not adding vendor/bin to PATH (different thing)

@csfh
Copy link

csfh commented Jun 13, 2024

Yes.

We need the composer executable it self, the .phar file, in $PATH which is done with the mv.

After that we need to add export PATH=$(composer global config bin-dir --absolute --quiet):$PATH to ~/.bashrc as far as I can tell.

Now we can do all of this:

$ composer global require laravel/installer
$ laravel new new-project

@csfh
Copy link

csfh commented Jun 13, 2024

I should have included this but I guess this means something like

echo "export PATH=$(composer global config bin-dir --absolute --quiet):$PATH" >> $HOME/.bashrc" in the installation script, and subsequently, a sed or similar to remove it on uninstall.

@roelandxyz
Copy link
Contributor

@roelandmoors but that's the composer installation itself, not adding vendor/bin to PATH (different thing)

Sorry, you are correct. The first PR version also installed the Symfony cli and moved it to a different path.

@florentdestremau
Copy link
Contributor Author

yeah composer is already in the shell path. composer bin, on the other hand, should not be included by default IMO. But that's a matter of preference. I can add that line @csfh if you think it's useful.

@csfh
Copy link

csfh commented Jun 13, 2024

yeah composer is already in the shell path. composer bin, on the other hand, should not be included by default IMO. But that's a matter of preference. I can add that line @csfh if you think it's useful.

Hey. I'm not sure why not add it but I would like to hear why you think not be included. It's not up to me at all, but very interesting discussion.

Copy link

@csfh csfh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can proceed?

Leave it up to the user how they want to manage composer and global composer installations, such as the laravel command.

When we build out the documentation, steps such as the ones we discussed about adding composer global bin dir to $PATH can be added there.

@florentdestremau
Copy link
Contributor Author

I would rather leave the $PATH clear of this on install especially when we're in the middle of tens of other installs. I don't really use global composer so didn't think about using it. I agree it could be documented for the php docs here

@dhh
Copy link
Member

dhh commented Jun 13, 2024

Great work here! Can someone give me a short playbook on the steps I'd have to take with this setup to get "hello world" in Laravel?

@csfh
Copy link

csfh commented Jun 13, 2024

@dhh

After you've install PHP using this script, you should be able to run composer create-project laravel/laravel example-app. For Laravel, at least locally, there is no need for cgi/apache and so on.

When done, you can cd into example-app and run php artisan serve.

If you end up using the Laravel installer script instead of the composer-create hook, it'll give you a better and interactive setup and installation guide.

For your convenience: https://laravel.com/docs/11.x#creating-a-laravel-project

@dhh dhh merged commit 47e9b71 into basecamp:master Jun 13, 2024
@roelandxyz
Copy link
Contributor

I think Laravel is a bit more like Rails, bit if you would like to test Symfony, you can download the cli like this:

wget https://get.symfony.com/cli/installer -O - | bash

After that command you get instructions on how to run the Symfony binary or you can just run it like this ~/.symfony5/bin/symfony

You can then create a complete web app (with importmap/stimulus/turbo as default) like this:
symfony new --webapp my_project

Inside the my_project folder you can start symfony server:start

@dhh
Copy link
Member

dhh commented Jun 13, 2024

Great. I changed this to run inside the new select-dev-env script, but otherwise left all the same. Tested getting a Laravel hello world. Excellent!

Would be nice to get PHP properly supported by mise, though. This just hardcodes PHP 8.3.

@florentdestremau
Copy link
Contributor Author

florentdestremau commented Jun 14, 2024

Thanks for merging 😃 For symfony the symfony cli, although very useful, is not required, you can do pretty much the same as for laravel to get a hello world.

composer create-project symfony/skeleton symfony_app
cd symfony_app
composer require webapp
php -S localhost:8000 -t public

As for mise, I discovered it with this project, will try to look at it. I've heard more about nix than for mise for setting up PHP envs.

@florentdestremau florentdestremau deleted the feature/add-php branch June 14, 2024 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add default setup for PHP
7 participants