Post

PHP Installation + Composer (Ubuntu)

PHP Installation + Composer (Ubuntu)
  • php-cli is the standalone tool for running a PHP scripts in the same way you would run it from the command line: php somescript.php. It seems you can also use it to base other images from.

    This variant contains the PHP CLI tool with default mods. If you need a web server, this is probably not the image you are looking for. It is designed to be used both as a throw away container (mount your source code and start the container to start your app), as well as a base from which to build other images.

  • php-fpm is the FastCGI server implementation of PHP which you would use with a FastCGI compliant web server such as Apache or Nginx.

    This variant contains PHP-FPM, which is a FastCGI implementation for PHP. See the PHP-FPM website for more information about PHP-FPM.

Add repo

1
2
3
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update

Install

PHP8.4

1
sudo apt -y install php8.4 php8.4-dev php8.4-fpm -y --allow-unauthenticated

Install some extensions

1
sudo apt install php8.4-{bcmath,curl,mbstring,mysql,zip,xml,bz2,intl,gd,tokenizer} -y --allow-unauthenticated

Verify

1
systemctl status php8.4-fpm

PHP.INI

1
sudo pluma /etc/php/8.4/cli/php.ini

OLDER PHP7

1
sudo apt -y install php7.4 php7.4-dev php7.4-fpm -y --allow-unauthenticated

Install some extensions

1
sudo apt install -y php7.4-{bcmath,curl,mbstring,mysql,zip,xml,bz2,intl,gd,tokenizer} -y --allow-unauthenticated

PHP.INI

1
sudo pluma /etc/php/8.4/fpm/php.ini

Switching PHP version

1
sudo update-alternatives --config php

Swith to 7.4

1
sudo update-alternatives --set php /usr/bin/php7.4

Switch to 8.3

1
sudo update-alternatives --set php /usr/bin/php8.4

OR

1
/usr/bin/php7.4 -S 127.0.0.1:8080 -t public

Jeśli pojawi się błąd Wymaga: libicu70, pobierz i zainstaluj ręcznie: libicu70_70.1-2_amd64.deb

Check the veriosn of PHP

1
php --version

Test file

1
echo "<?php phpinfo();" > index.php

run server

1
php -S 127.0.0.1:8080 index.php

NGINX

1
sudo pluma /etc/nginx/sites-enabled/default

uncomment and change

1
2
3
4
5
6
7
8
9
location ~ \.php$ {
    include snippets/fastcgi-php.conf;

    # With php-fpm (or other unix sockets):
    --- fastcgi_pass unix:/run/php/php7.4-fpm.sock;
    +++ fastcgi_pass unix:/var/run/php/php7.4-fpm.sock
    # With php-cgi (or other tcp sockets):
    fastcgi_pass 127.0.0.1:9000;
}

Composer

1
2
3
4
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'dac665fdc30fdd8ec78b38b9800061b4150413ff2e3b6f88543c636f7cd84f6db9189d43a81e5503cda447da73c7e5b6') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
This post is licensed under CC BY 4.0 by the author.

Trending Tags