Symfony offline installation with composer

2020-07-23 08:35发布

I'm trying to install Symfony on a server, which has no connection to the internet. I copied composer on the server but when i try to install it i get this error

Connection Error [ERR_CONNECTION]: Unable to connect to getcomposer.org

Is there any possible way to install symfony without active connection to the internet; like download the framework, put it on the server and then run the composer offline? Or does it have too many dependencies, which would be included?

I've already googled but couldn't find a satisfying solution.

4条回答
▲ chillily
2楼-- · 2020-07-23 09:02

You can run composer on computer with connection to internet and copy all directory with files.

Composer to work mast make connection to internet, to check new version of package.

查看更多
可以哭但决不认输i
3楼-- · 2020-07-23 09:07

I've the same problem in symfony3.

Solution:

  1. Create archive of project - for safety.
  2. Copy project form server to computer with internet access (all files & directory): laptop.
  3. Run composer update on laptop.
  4. On server:

    rm -rf app/*
    rm -rf bin/*
    rm -rf var/cache/*
    rm -rf var/logs/*
    rm -rf var/sessions/*
    rm -rf vendor/*
    rm composer.json
    rm composer.lock

  5. Copy from laptop to server files to directory: app/, bin/, vendor/ and composer.json, composer.lock

Its work for me :-)

查看更多
Emotional °昔
4楼-- · 2020-07-23 09:09

Do

composer install -o

to install. Then do all preparations like clear cache in prod/dev build assets and dump them

   php app/console cache:clear && php app/console cache:clear -e prod --no-debug
   php app/console assetic:dump -e prod --no-debug
   php app/console assets:install web --symlink --relative

then push/ftp your project to a server. I highly recomend you to run

composer dumpautoload -o

in order to update autolaod files on the server

UPDATE:

You could (should) also run a symfony's after-install script (after dumping autoload) in order to edit/update your parameters.yml on the Server, since db-access, mailer_transport will be probably different than on your dev-machine

composer run-script post-install-cmd
php app/console cache:clear -e prod --no-debug

then just run

php/console list

if you'll get a list of all available commands => your symfony app was successfully installed and runs

查看更多
Juvenile、少年°
5楼-- · 2020-07-23 09:10

The short answer is yes and there are several ways to do that

As others have suggested the best choice is to build your project (install Symfony, install Composer, update dependencies) on a system that is connected to the internet and then just copy the project on the server.

Warning

The system where you build the project should be as similar as possible to the actual server (I mean PHP version, MySQL version, and so on) else the project may breaks.

You may want to build a Virtual Machine to make it really similar, which is good for development also. In that case you may take a look at tools like Ansible and Vagrant.

查看更多
登录 后发表回答