cytopia / devilbox

A modern Docker LAMP stack and MEAN stack for local development
http://devilbox.org
MIT License
4.38k stars 652 forks source link

Docs about Composer usage #48

Closed Vadiok closed 7 years ago

Vadiok commented 7 years ago

Could you please write the documentation section how to install & run Composer & also run another PHP & MySQL console commands.

cytopia commented 7 years ago

Hi @Vadiok,

could you give me an example of both: composer and mysql commands to run, so I better understand your goal.

In general:

Everything is available from outside the docker. (On your host computer)

Hope this makes sense, if not I might have misunderstood you here.

Vadiok commented 7 years ago

@cytopia thanks for answer.

could you give me an example of both: composer and mysql commands to run, so I better understand your goal.

Example of MySQL command (creation of DB dump): mysqldump -u homestead -psecret work_db_name | gzip -9 > dump.sql.gz

Example of Composer usage php composer require 'laravel/database'

Also how can I run migrations? php artisan migrate

cytopia commented 7 years ago

Example of MySQL command (creation of DB dump): mysqldump -u homestead -psecret work_db_name | gzip -9 > dump.sql.gz

Do you have mysqldump installed locally on your host? If yes, simply issue: mysqldump -h 127.0.0.1 -u homestead -psecret work_db_name | gzip -9 > dump.sql.gz Alternatively you can use the root user with its password as defined in the .env file: mysqldump -h 127.0.0.1 -u root -p work_db_name | gzip -9 > dump.sql.gz

Example of Composer usage php composer require 'laravel/database'

Do you have php installed locally on your host? If yes, simply go to your data directory and into your project dir (whereever your compose file resides) and issue: php composer require 'laravel/database'

Also how can I run migrations? php artisan migrate

Same as above if you have php installed locally. Simply issue this command in your project dir (on the docker host).

In case you do not have php/mysqldump installed on your host let me know.

Vadiok commented 7 years ago

I have some installed versions of PHP (v7.1) & MySQL (v5.7) but what if I'll have a Laravel project with docker MySQL DB & run migrations

php artisan migrate

Laravel will run php scripts with my local version of PHP, it will try to connect to local MySQL instead of docker MySQL. I think connection fails, but if not PHP script did not find proper db in my local version of MySQL to execute migration.

Also it is better to execute Composer with PHP version used by site & not local because Composer's behavior depends of PHP version.

cytopia commented 7 years ago

For mysql, you should set the connection all to host: 127.0.0.1. This will work from inside the container as well for the host. So db mirgrations should work.

For the other stuff, you can attach the php container and run the required commands. In case of php 7.1:

DID="$(docker ps | grep "cytopia/php-fpm-7.1" | awk '{print $1}')"
docker exec -it ${DID} env TERM=xterm /bin/bash -l

And then cd into /shared/httpd which is the directory where all the data is mounted. Also let me know all the software you need, I will probably have to rebuild the containers. You can also on the fly install the stuff (via yum or by source or ...)

Once everything works as expected I will provide scripts and some documentation about the usage.

alexd73 commented 7 years ago

Hello! I use drupal console and drush utilities. If I don't want to install composer, drupal console and drush on my host computer, have I any chance to Install this things on the docker container?

cytopia commented 7 years ago

Hi @alexd73 ,

I am currently working on this and it should come with the next release 0.9. It's a bit tricky to get it done properly. Open todos are:

  1. The docker container itself needs to have dns (or some other ways to access the vhosts on the www container).
  2. Get list of tools to install to php container
  3. Sync php uid/gid with host user uid/gid

So as a work-around for 2. and 3. is to follow the description in this issue: https://github.com/cytopia/devilbox/issues/53 and additionally add the tools to install to the docker file or do it manually after it has started.

For 1. you need a way to access the www container's vhost (by its domain) from the php container. I am not sure if you can simply edit the php containers /etc/hosts. If this does not work, you will have to wait for the next release.

So for the next release, please vote for the required tools here: https://github.com/cytopia/devilbox/issues/56

cytopia commented 7 years ago

Current work already started and can be seen here: https://github.com/cytopia/docker-php-fpm-5.4/pull/16

Will be applied to all php container once the PR is feature-complete and bug-free

cytopia commented 7 years ago

@alexd73 @Vadiok You can now enter the php container with ./bash.sh or ./root_bash.sh and perform operations directly inside. Some dev tools have already been pre-installed such as: node, npm, composer, drush, git, and more.