Skip to content

Instantly share code, notes, and snippets.

@ebta
Last active April 11, 2023 10:47
Show Gist options
  • Save ebta/e11100d67b59c7decdf1e1851b14786e to your computer and use it in GitHub Desktop.
Save ebta/e11100d67b59c7decdf1e1851b14786e to your computer and use it in GitHub Desktop.
Install PHP Package and Other

Tips install PHP dan package-package

Ubuntu 20.04 ship with PHP 7.4

sudo apt install php php-cli php-fpm php-json php-pdo php-mysql \
php-zip php-gd  php-mbstring php-curl php-xml php-pear php-bcmath

Syntax alternatif

sudo apt install php php-{cli,fpm,json,pdo,mysql,zip,gd,mbstring,curl,xml,pear,bcmath}

Dengan Apache, general

sudo apt install libapache2-mod-php php php-cli php-fpm php-json php-pdo php-mysql \
php-zip php-gd  php-mbstring php-curl php-xml php-pear php-bcmath

Syntax alternatif

sudo apt install libapache2-mod-php php php-{cli,fpm,json,pdo,mysql,zip,gd,mbstring,curl,xml,pear,bcmath}

Tambah memcached dan apcu (versi default 5.1.18)

sudo apt install memcached php-memcached php-apcu

Install PECL Package from source

To install pecl package from pecl, for example apcu, redis, imagick. Yu must install php-pear and php developer package

sudo apt install php-pear php-dev build-essential -y

Install APCU (latest version available 5.1.20)

sudo pecl install apcu

Check if apcu.ini is already exists in /etc/php/7.4/mods-available/apcu.ini, if not add

echo "extension = apcu.so" | sudo tee -a /etc/php/7.4/mods-available/apcu.ini

Add symlink to php-fpm and php cli

sudo ln -s /etc/php/7.4/mods-available/apcu.ini /etc/php/7.4/fpm/conf.d/30-apcu.ini
sudo ln -s /etc/php/7.4/mods-available/apcu.ini /etc/php/7.4/cli/conf.d/30-apcu.ini

Install redis

sudo pecl install redis

Check if apcu.ini is already exists in /etc/php/7.4/mods-available/redis.ini, if not add

echo "extension = redis.so" | sudo tee -a /etc/php/7.4/mods-available/redis.ini

Add symlink to php-fpm and php cli

sudo ln -s /etc/php/7.4/mods-available/redis.ini /etc/php/7.4/fpm/conf.d/30-redis.ini
sudo ln -s /etc/php/7.4/mods-available/redis.ini /etc/php/7.4/cli/conf.d/30-redis.ini

Restart PHP-FPM service

sudo service php7.4-fpm restart

Install PHP 7.4 on Ubuntu 18.04/16.04

Step 1: Add PHP PPA Repository

sudo apt-get update
sudo apt -y install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt -y install php7.4 php7.4-{fpm,bcmath,bz2,intl,gd,mbstring,mysql,zip,xml}

Jika menggunakan Nginx, disable apache

sudo systemctl disable --now apache2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment