Skip to content

totadavid95/PhpComposerInstaller

Repository files navigation

Automated PHP, Xdebug, Composer installer

The latest release can be downloaded by clicking the button:

Download latest

Kattints ide a MAGYAR nyelvű dokumentációért! (Click here for HUNGARIAN documentation.)

  • Always extract the downloaded .zip file, then run the extracted PhpComposerInstall.exe executable. DO NOT EXECUTE DIRECTLY FROM THE ARCHIVE!
  • The installer requires .NET 4.7.2 to run. (This requirement is fulfilled on Windows 10 and 11 systems by default.)

This documentation always applies to the latest release only, previous versions can be viewed in the GitHub history.

Table of contents:

Project description

This installer was primarily created for the students of Server-side web programming course taught also by me at Eötvös Loránd Univerity in Hungary as a utility that provides a straightforward way to install and set up PHP, Xdebug and Composer under Windows.

The installer does not require administrative privileges since it only installs for the logged in Windows user, therefore it can be executed on the lab computers. This saves us a lot of wasted time and unnecessary headaches.

The installer downloads the latest releases of the aforementioned software, then installs and configures them. If an installation has already been completed, the existing installation is removed first, and a clean installation of the latest version is performed. This mechanism can also be used to fix a broken installation or to perform an update.

The installer does not require administrative privileges since it only installs for the logged in Windows user.

Command line switches

To view the available command line switches, execute the installer with the --help switch:

PhpComposerInstaller.exe --help

Frequent issues

If the installer or any of the installed software doesn't work properly, the culprit could be one of the following:

  • Some antivirus software mistakenly classify one of the installation steps (usually Composer) as malware (also known as a false positive alarm). If you use such software, try suspending its protection and running the installer again. The installer is not "viral", the source code can be found here on GitHub.
  • It is possible that some kind of "fluctuation" occurred on your network and the download was interrupted. Try running the installer again, possibly at a later time.
  • Using non-English characters in your Windows username may lead to errors in some cases, typically when using Tinker. There is already a video on fixing this issue (in Hungarian).

Bug report

If your issue is still unresolved after reading the above, see the Help and support section.

Manual installation (on Windows)

The installer performs the following steps programmatically.

Installing PHP

  • The official PHP webpage contains the currently supported versions of PHP: https://windows.php.net/download
  • Download the x86 / x64 Non Thread Safe version of your choice (preferably the latest one). Use the x86 version on 32-bit operating systems and the x64 version for a 64-bit OS.
  • Extract the downloaded .zip archive.
  • PHP requires a configuration file named php.ini which is not included in the archive by default. Create a duplicate of the included php.ini-development (which serves as an example configuration) and rename it php.ini.
  • Open php.ini and perform the following changes:
    • Find the following row: ;extension_dir = "ext", and remove the ; (comment sign) from the beginning. This will make PHP look for its extensions in its own directory. (Since PHP was installed locally, it would not look for the extensions in the right place by default.)
    • Next we will need to enable some extensions which will be required to run Composer, Laravel, etc properly later. Uncomment the following lines, thereby enabling the given extensions:
      ;extension=curl
      ;extension=fileinfo
      ;extension=mbstring
      ;extension=openssl
      ;extension=pdo_mysql
      ;extension=pdo_sqlite
  • Save the php.ini file when you're done.
  • Copy the contents of the php folder to: %LOCALAPPDATA%\Programs\php (create the php folder in Programs if it does not exist yet).

Hint: copy %LOCALAPPDATA%\Programs to the address bar of your file explorer.

Installing Visual C++ Redistributable

The installation requirements specify the Visual C++ Redistributable is needed to run PHP on Windows systems. If PHP gives a "dll error" on first execution, download the appropriate (32 or 64 bit depending on your OS architecture) version of the Visual C++ runtime:

Installing Xdebug for PHP

  • Select the Xdebug version corresponding your installed PHP version from https://xdebug.org/download from the Windows binaries section.
  • Download Xdebug as a file named php_xdebug.dll.
  • Copy the downloaded php_xdebug.dll file to the ext directory of your PHP installation.
  • Open php.ini. The ini file follows this structure:
    [section_name]
    property_name = property_value
    • First enable Xdebug as a Zend extension under the [PHP] section of the file:
      [PHP]
      ; Here you will find lots of settings and comment, but just 
      ; insert this at the botton of the section before the next [section] begins:
      zend_extension = xdebug
    • Then configure the settings related to Xdebug by inserting a new [xdebug] section at the very bottom of your php.ini file:
      [xdebug]
      xdebug.cli_color = 1
      xdebug.client_host = localhost
      xdebug.client_port = 9003
  • Save the php.ini file.
  • If a PHP process was running on the machine bound to this PHP configuration, then the process needs to be restarted in order to load the new PHP configuration.

Install Composer

  • Download the latest Composer v2 release be clicking here: https://getcomposer.org/download/latest-2.x/composer.phar
  • Copy the downloaded composer.phar file to: %LOCALAPPDATA%\Programs\composer (create the composer folder in Programs if it does not exist yet).
  • Since this is a PHP archive (PHAR - PHp ARchive), Windows is not able to execute it directly (like it executes php.exe). We need to create a command file which will make the OS execute this PHAR in the PHP interpreter when opened. This will make the composer command available in the command line, so calling Composer will basically execute this bat file. Create a composer.bat file the composer directory which contains the following one line:
    @php "%~dp0composer.phar" %*
  • This will make the composer.bat call PHP to run Composer (which is a PHP archive) forwarding the parameters as well (hence %).

Adding the installation to the Path environment variable

At this point the installation is almost done, but currently you can only call PHP and Composer by knowing their absolute path.

To make php and composer simply callable from any open command line, we need to add the two folders created inside %localappdata/Programs to the Path environment variable.

This is most easily done by typing "Edit environment variables for your account" into the Search bar. Alternatively you can press Win+R and execute rundll32 sysdm.cpl,EditEnvironmentVariables.

It is important to note that you only need to work in the upper part of the dialog, since those are the environment variable of the current user, and you are not able to modify the system-level properties on the lab machines anyway.

You'll need to close any previously opened command prompts for the changes to take effect.

Testing the installed tools

You can test whether your installations were successful by executing php -v and composer -V. In both cases you should be able to see the version number of the installed product, and the PHP version command should also display some information about Xdebug.

You may get some more details about your PHP installation by copying the following code into a PHP file (e.g text.php):

<?php
    // display all information about the PHP installation
    phpinfo();

    // display all information about the Xdebug installation
    xdebug_info();
?>

Now open a command line in the directory of the created test.php file (or use cd to get there and) and execute:
php -S localhost:3000 test.php

You may now view http://localhost:3000/ in a browser. This will display a through report about your PHP environment (including version number and the enabled extensions). Don't forget to close the command line. This will also stop the development server, of course.

There two tests can also be executed using the tools included in the InstallTest folder of the installer.

Manual installation (on Linux)

Our automatic installer only works under Windows systems, but this guide may help you perform the same on Linux operating systems. The process is based on this tutorial and has been tested under Xubuntu 20.04.

  1. Update the package repository:

    sudo apt update
  2. Install a package which helps manage PPAs:

    sudo apt install software-properties-common -y 
  3. Add a new PPA package repository which manages PHP version:

    sudo add-apt-repository ppa:ondrej/php 
  4. Now the system can find how to install PHP, so we can start by installing the PHP interpreter itself. The version number must be entered, but it is also possible to deviate from the version number shown here as an example (at the time of writing the description, 8.1 is the latest), it must be used consistently, and the same must be entered afterwards everywhere.

    sudo apt install php8.1
  5. Install the needed extensions for PHP 8.1. These are basically the following, but you can install additional ones if you want:

    sudo apt install php8.1-cli php8.1-xml php8.1-curl php8.1-fileinfo php8.1-mbstring php8.1-sqlite3 php8.1-xdebug
  6. Check if PHP works using this command:

    php -v
    • As a result, you should see an output similar to the one below (naturally not with these exact version numbers):
      PHP 8.1.2 (cli) (built: Jan 24 2022 10:42:33) (NTS)
      Copyright (c) The PHP Group
      Zend Engine v4.1.2, Copyright (c) Zend Technologies
          with Zend OPcache v8.1.2, Copyright (c), by Zend Technologies
          with Xdebug v3.1.2, Copyright (c) 2002-2021, by Derick Rethans
      
  7. Install Composer. At this point PHP CLI is available, so you can use the solution provided by the Composer homepage to execute this installer script:

    #!/bin/sh
    
    EXPECTED_CHECKSUM="$(php -r 'copy("https://composer.github.io/installer.sig", "php://stdout");')"
    php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
    ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', 'composer-setup.php');")"
    
    if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ]
    then
      >&2 echo 'ERROR: Invalid installer checksum'
      rm composer-setup.php
      exit 1
    fi
    
    php composer-setup.php --quiet
    RESULT=$?
    rm composer-setup.php
    exit $RESULT
    • Save the script (for example as composer.sh), set the execute priviledge and execute it.
  8. The previous step has created the composer.phar file which is not available everywhere yet. To make Composer globally available on your machine, copy this newly created file to the bin folder:

    sudo mv composer.phar /usr/local/bin/composer
  9. Check your Composer installation using the following command:

    composer -V

Help and support

If you have any questions about the installer, feel free to ask me and I'll gladly help (totadavid95@inf.elte.hu or Teams chat). If you have a GitHub account, you can also open an issue.

Contributing

Here is a quick guide on how to contribute to this project.

  1. Fork the repository on GitHub.
  2. Clone your fork from GitHub to your local machine.
  3. Download the latest version of Dotnet from here.
  4. You can use any IDE you like. I recommend the lightweight Visual Studio Code with the C# extension installed.
  5. Make your changes.
  6. Create a build by running dotnet build in the root directory. This will compile the code to PhpComposerInstaller/bin/Debug/PhpComposerInstaller.exe.
  7. Test your changes by running the modified installer.
  8. If everything works as expected, structure your changes into commits and push them to your fork.
  9. Create a pull request on GitHub from your fork to the original repository. Describe your changes and why you think they should be merged.

Releasing a new version

If you are a maintainer of this project, you can create a new release simply by pushing a new v* tag to the repository. GitHub Actions will automatically builds the installer from the source code and creates a new release. The release will contain the installer executable and the test files.