Windows install php and composer

Introduction#

Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.

Dependency management#

Composer is not a package manager in the same sense as Yum or Apt are. Yes, it deals with «packages» or libraries, but it manages them on a per-project basis, installing them in a directory (e.g. vendor ) inside your project. By default, it does not install anything globally. Thus, it is a dependency manager. It does however support a «global» project for convenience via the global command.

This idea is not new and Composer is strongly inspired by node’s npm and ruby’s bundler.

  1. You have a project that depends on a number of libraries.
  2. Some of those libraries depend on other libraries.
  1. Enables you to declare the libraries you depend on.
  2. Finds out which versions of which packages can and need to be installed, and installs them (meaning it downloads them into your project).
  3. You can update all your dependencies in one command.

See the Basic usage chapter for more details on declaring dependencies.

Читайте также:  Font awesome react typescript

System Requirements#

Composer in its latest version requires PHP 7.2.5 to run. A long-term-support version (2.2.x) still offers support for PHP 5.3.2+ in case you are stuck with a legacy PHP version. A few sensitive php settings and compile flags are also required, but when using the installer you will be warned about any incompatibilities.

Composer needs several supporting applications to work effectively, making the process of handling package dependencies more efficient. For decompressing files, Composer relies on tools like 7z (or 7zz ), gzip , tar , unrar , unzip and xz . As for version control systems, Composer integrates seamlessly with Fossil, Git, Mercurial, Perforce and Subversion, thereby ensuring the application’s smooth operation and management of library repositories. Before using Composer, ensure that these dependencies are correctly installed on your system.

Composer is multi-platform and we strive to make it run equally well on Windows, Linux and macOS.

Installation — Linux / Unix / macOS#

Downloading the Composer Executable#

Composer offers a convenient installer that you can execute directly from the command line. Feel free to download this file or review it on GitHub if you wish to know more about the inner workings of the installer. The source is plain PHP.

There are, in short, two ways to install Composer. Locally as part of your project, or globally as a system wide executable.

Locally#

To install Composer locally, run the installer in your project directory. See the Download page for instructions.

The installer will check a few PHP settings and then download composer.phar to your working directory. This file is the Composer binary. It is a PHAR (PHP archive), which is an archive format for PHP which can be run on the command line, amongst other things.

Now run php composer.phar in order to run Composer.

You can install Composer to a specific directory by using the —install-dir option and additionally (re)name it as well using the —filename option. When running the installer when following the Download page instructions add the following parameters:

php composer-setup.php --install-dir=bin --filename=composer

Now run php bin/composer in order to run Composer.

Globally#

You can place the Composer PHAR anywhere you wish. If you put it in a directory that is part of your PATH , you can access it globally. On Unix systems you can even make it executable and invoke it without directly using the php interpreter.

After running the installer following the Download page instructions you can run this to move composer.phar to a directory that is in your path:

mv composer.phar /usr/local/bin/composer

If you like to install it only for your user and avoid requiring root permissions, you can use ~/.local/bin instead which is available by default on some Linux distributions.

Note: If the above fails due to permissions, you may need to run it again with sudo .

Note: On some versions of macOS the /usr directory does not exist by default. If you receive the error «/usr/local/bin/composer: No such file or directory» then you must create the directory manually before proceeding: mkdir -p /usr/local/bin .

Note: For information on changing your PATH, please read the Wikipedia article and/or use your search engine of choice.

Now run composer in order to run Composer instead of php composer.phar .

Installation — Windows#

Using the Installer#

This is the easiest way to get Composer set up on your machine.

Download and run Composer-Setup.exe. It will install the latest Composer version and set up your PATH so that you can call composer from any directory in your command line.

Note: Close your current terminal. Test usage with a new terminal: This is important since the PATH only gets loaded when the terminal starts.

Manual Installation#

Change to a directory on your PATH and run the installer following the Download page instructions to download composer.phar .

Create a new composer.bat file alongside composer.phar :

C:\bin> echo @php "%~dp0composer.phar" %*>composer.bat
PS C:\bin> Set-Content composer.bat '@php "%~dp0composer.phar" %*'

Add the directory to your PATH environment variable if it isn’t already. For information on changing your PATH variable, please see this article and/or use your search engine of choice.

Close your current terminal. Test usage with a new terminal:

Composer version 2.4.0 2022-08-16 16:10:48

Docker Image#

Composer is published as Docker container in a few places, see the list in the composer/docker README.

docker pull composer/composer docker run --rm -it -v "$(pwd):/app" composer/composer install

To add Composer to an existing Dockerfile you can simply copy binary file from pre-built, low-size images:

# Latest release COPY --from=composer/composer:latest-bin /composer /usr/bin/composer # Specific release COPY --from=composer/composer:2-bin /composer /usr/bin/composer

Read the image description for further usage information.

Note: Docker specific issues should be filed on the composer/docker repository.

Note: You may also use composer instead of composer/composer as image name above. It is shorter and is a Docker official image but is not published directly by us and thus usually receives new releases with a delay of a few days. Important: short-aliased images don’t have binary-only equivalents, so for COPY —from approach it’s better to use composer/composer ones.

Using Composer#

Now that you’ve installed Composer, you are ready to use it! Head on over to the next chapter for a short demonstration.

Found a typo? Something is wrong in this documentation? Fork and edit it!

Composer and all content on this site are released under the MIT license.

Источник

Installing PHP 7 and Composer on Windows 10, Natively

Note: If you want to install and use PHP 7 and Composer within the Windows Subsystem for Linux (WSL) using Ubuntu, I wrote a guide for that, too!

I am working a lot on Composer-based Drupal projects lately (especially gearing up for DrupalCon Nashville and my joint workshop on Drupal and Composer with Matthew Grasmick), and have been trying to come up with the simplest solutions that work across macOS, Linux, and Windows. For macOS and Linux, getting PHP and Composer installed is fairly quick and easy. However, on Windows there seem to crop up little issues here and there.

Since I finally spent a little time getting the official version of PHP for native Windows installed, I figured I’d document the process here. Note that many parts of this process were learned from the concise article Install PHP7 and Composer on Windows 10 from the website KIZU 514.

Install PHP 7 on Windows 10

PHP 7 running in Windows 10 in PowerShell

  1. Install the Visual C++ Redistributable for Visual Studio 2015—this is linked in the sidebar of the PHP for Windows Download page, but it’s kind of hidden. If you don’t do this, you’ll run into a rather cryptic error message, VCRUNTIME140.DLL was not found , and php commands won’t work.
  2. Download PHP for Windows. I prefer to use 7.1.x (current release — 1), so I downloaded the latest Non-thread-safe 64-bit version of 7.1.x. I downloaded the .zip file version of the VC14 x64 Non Thread Safe edition, under the PHP 7.1 heading.
  3. Expand the zip file into the path C:\PHP7 .
  4. Configure PHP to run correctly on your system:
    1. In the C:\PHP7 folder, rename the file php.ini-development to php.ini .
    2. Edit the php.ini file in a text editor (e.g. Notepad++, Atom, or Sublime Text).
    3. Change the following settings in the file and save the file:
      1. Change memory_limit from 128M to 1G (because Composer can use lots of memory!)
      2. Uncomment the line that reads ; extension_dir = «ext» (remove the ; so the line is just extension_dir = «ext» ).
      3. In the section where there are a bunch of extension= lines, uncomment the following lines:
        1. extension=php_gd2.dll
        2. extension=php_curl.dll
        3. extension=php_mbstring.dll
        4. extension=php_openssl.dll
        5. extension=php_pdo_mysql.dll
        6. extension=php_pdo_sqlite.dll
        7. extension=php_sockets.dll
        1. Open the System Control Panel.
        2. Click ‘Advanced System Settings’.
        3. Click the ‘Environment Variables. ‘ button.
        4. Click on the Path row under ‘System variables’, and click ‘Edit. ‘
        5. Click ‘New’ and add the row C:\PHP7 .
        6. Click OK, then OK, then OK, and close out of the System Control Panel.

        At this point, you should see output like:

        Windows PowerShell
        Copyright (C) Microsoft Corporation. All rights reserved.

        PS C:\Users\jgeerling> php -v
        PHP 7.0.29 (cli) (built: Mar 27 2018 15:23:04) ( NTS )
        Copyright (c) 1997-2017 The PHP Group
        Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies

        This means PHP is working, yay!

        Install Composer on Windows 10

        Composer running in Windows 10 in PowerShell

        Next, we’re going to install Composer by downloading it and moving it into place so we can run it with just the composer command:

        1. Download the Windows Installer for Composer and run it.
        2. Note that the Windows Installer for Composer might ask to make changes to your php.ini file. That’s okay; allow it and continue through the setup wizard.
        3. Close out of any open PowerShell or other terminal windows, and then open a new one.
        4. Run the composer command, and verify you get a listing of the Composer help and available commands.

        That’s it! Now you have PHP 7 and Composer running natively on your Windows 10 PC. Next up, dominate the world with some new PHP projects!

        Источник

        How to Install Composer and PHP on Windows 10

        How to Install Composer and PHP on Windows 10

        In this guide we will install Composer and PHP on Windows 10 so that we can install dependencies for our web apps directly from Windows command line.

        1. Download and Install Visual C++

        In order to run PHP on Windows 10, you will need to install Visual C++ Redistributable for Visual Studio. You can download it from the Windows Download page or click the direct link below.

        Once downloaded, run the installer and click Install.

        Install Visual C++ Redistributable for Visual Studio 2015

        2. Download and Extract PHP

        Go to the Windows PHP download page and download the .zip of the version of PHP you require. In this guide, we are installing PHP 7.4 VC15 x64 Non Thread Safe, which is the latest version as of writing (Jan 2020).

        Once downloaded, create a new folder in c:\php7 (or wherever you prefer) and extract your PHP zip to it.

        PHP7 for Windows extracted

        3. Download and Install Composer

        In the second step of Composer Setup, make sure the correct path to php.exe is set and click Next.

        Installing Composer PHP Windows 10

        If Setup prompts to create php.ini, allow it and click Next.

        Skip the Proxy URL settings, just click Next then click Install.

        Click Finish once install is complete.

        4. Test PHP

        If you have any Command Prompt windows currently open, close them now.

        Open Command Prompt, type php -v and press Enter. You should now see the PHP version.

        Windows 10 PHP 7 in Command Prompt

        If it returns a PHP version, you can skip to Step 6 to test Composer.

        If you get an error “‘php’ is not recognized as an internal or external command,
        operable program or batch file.”, you may need to Add a Path Environment Variable.

        5. Add Path Environment Variable

        Composer setup usually does this for you, but if for whatever reason it didn’t, you can set one up manually.

        So that you don’t have to type the whole path to php.exe every time you run a PHP command, you should add c:\php7 as a path environment variable.

        Open System Properties by clicking the start menu and typing sysdm.cpl and press Enter.

        Windows 10 view advanced system settings

        In System Properties, click Environment Variables.

        Windows 10 System Properties

        In System Variables, click Path and then click Edit.

        Click New, type the path to your PHP folder ( c:\php7 ) and click OK.

        Add new path environment variable Windows 10

        Close the System Properties dialogue by clicking OK.

        6. Test Composer

        Open up Command Prompt and type composer -V (that’s uppercase V).

        If all was installed correctly, you should see a version number.

        Composer in Windows 10 command prompt

        Hurrah! You can now run Composer and PHP on Windows 10.

        Let me know if this helped. Follow me on Twitter, Facebook and YouTube, or 🍊 buy me a smoothie.

        p.s. I increased my AdSense revenue by 200% using AI 🤖. Read my Ezoic review to find out how.

        Источник

Оцените статью