PHP Install

From ElectroDragon Wiki
Revision as of 00:45, 2 May 2020 by Chao (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Install

  • sudo apt-get update, sudo apt-get upgrade
  • PHP7.2 enable PPA, install and add gpg
apt install apt-transport-https lsb-release ca-certificates
apt install lsb-release apt-transport-https ca-certificates
wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
  • add to source list
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php7.0.list
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php7.3.list
  • update and install
apt update
apt install php7.4
apt install php7.2

Install PHP Modules

or

  • sudo apt-get install php7.3 php-pear php7.3-fpm php7.3-mysql
  • sudo apt-get install php7.3 php-pear
  • Install addtions - sudo apt-get install php7.3-{bcmath,bz2,intl,gd,mbstring,mysql,zip}
  • Install common php modules: apt install php7.2 php7.2-cli php7.2-common php7.2-json php7.2-opcache php7.2-mysql php7.2-zip php7.2-fpm php7.2-mbstring
  • sudo apt-get install php7.0-{bcmath,bz2,intl,gd,mbstring,mysql,zip}

Confirm Installation

  • check version php -v


other wrong method

  • apt-get install php7.0 php7.0-fpm php-fpm

Restart service

  • service php7.0-fpm restart

php5

  • apt-get install php5-common libapache2-mod-php5 php5-cli
  • sudo apt-get install php5-fpm php5-mysql
  • sudo nano /etc/php5/fpm/php.ini -> cgi.fix_pathinfo=0

or

  • apt-get install php5-cgi php5-cli php5-mysql
  • apt-get install php5-fpm php5-mysql

Restart service

  • service php5-fpm restart
  • sudo systemctl restart php5-fpm

Test Installation

Confirm installation

  • php -v
  • Create PHP test file
sudo nano /usr/share/nginx/html/info.php
nano /var/www/html/info.php
<?php
phpinfo();
?>