Skip to content

Instantly share code, notes, and snippets.

@nd3w
Last active April 23, 2025 01:39
Show Gist options
  • Save nd3w/b8a336ced3cce0efb999e50303e015e2 to your computer and use it in GitHub Desktop.
Save nd3w/b8a336ced3cce0efb999e50303e015e2 to your computer and use it in GitHub Desktop.
Install Apache2, PostgreSQL and PHP-FPM on Ubuntu 20.04

Install Apache2, PostgreSQL and PHP-FPM 8.2 on Ubuntu 20.04

Install Apache

sudo apt install apache2

sudo ufw app list

sudo ufw allow in "Apache"

sudo ufw status

sudo a2enmod headers deflate rewrite expires

Install PostgreSQL

PostgreSQL 12 is use as default version on Ubuntu 20.04

sudo apt install postgresql postgresql-contrib -y

sudo -i -u postgres

Now change admin's password

ALTER USER postgres WITH PASSWORD 'SECRETPASSWORd';

Change postgres' user type to match password changing

sudo vi /etc/postgresql/14/main/pg_hba.conf

Change this line

local	all		postgres	peer

to

local	all		postgres	md5
sudo service postgresql restart

psql -U postgres

CREATE DATABASE db_name

Install PHP-FPM version 8.2

We use Ondrej's PPA in order if we use another version in the future.

sudo add-apt-repository ppa:ondrej/php

sudo apt update

sudo apt install -y php8.2 php8.2-fpm php8.2-curl php8.2-gd php8.2-mbstring php8.2-mysql php8.2-opcache php8.2-xml php8.2-xmlrpc php8.2-common php8.2-imagick php8.2-pgsql php8.2-xdebug

sudo service php8.2-fpm start

sudo a2enconf php8.2-fpm

sudo service apache2 restart
@christopherblosfeld
Copy link

opa, testei por aqui. Porém em docker, mais mesmo assim nao consigo rodar o php info.

@nd3w
Copy link
Author

nd3w commented Jan 15, 2025

opa, testei por aqui. Porém em docker, mais mesmo assim nao consigo rodar o php info.

What was the error message?

@christopherblosfeld
Copy link

Deu certo meu amigo.
Montei um passo a passo para quem queira instalar em docker, vou deixar anexado aqui caso alguém precise no futuro Ok?
Agradeço muito a sua contribuição em compartilhar o seu conhecimento.

Passos para instalar o servidor WEB completo no Docker com Driver Postgre e PHP

Primeiro passo:
Instalar essa imagem:

Em seguida digitar no terminal, dentro da imagem docker docker exec -it nomeDoContainer bash

  • apt-get update && apt-get install -y software-properties-common curl lsb-release
  • add-apt-repository ppa:ondrej/php -y
  • apt-get update
  • apt-get install -y php8.2 php8.2-fpm php8.2-curl php8.2-gd php8.2-mbstring php8.2-mysql php8.2-opcache php8.2-xml php8.2-xmlrpc php8.2-common php8.2-imagick php8.2-pgsql php8.2-xdebug
  • service php8.2-fpm start
  • a2enconf php8.2-fpm
  • service apache2 restart

Caso queira salvar a imagem com as configurações:

  • docker commit custom-php-image

testar com phpInfo (rodar isso no terminal>: echo "" > /var/www/html/info.php

testar no prompt: php -r "if (function_exists('pg_connect')) { echo 'PostgreSQL driver is enabled.'; } else { echo 'PostgreSQL driver is not enabled.'; }"

precisa estar como postgreSQL driver is enabled
Ainda dentro do Container:

  • a2enmod php8.2
  • service apache2 restart

Caso ele dê esse erro: ERROR: Module php8.2 does not exist!

  • apt-get update
  • apt-get install -y php8.2 libapache2-mod-php8.2
  • a2enmod php8.2
  • service apache2 restart

O arquivo phpInfo.php precisa estar dessa forma: echo "" > /var/www/html/info.php

Após esse momento ele precisa aparecer os dados do server.

Esse repositorio github é importante:
https://gist.github.com/nd3w/b8a336ced3cce0efb999e50303e015e2
Caso saia do ar, está anexado no Drive.

@nd3w
Copy link
Author

nd3w commented Apr 23, 2025

Deu certo meu amigo. Montei um passo a passo para quem queira instalar em docker, vou deixar anexado aqui caso alguém precise no futuro Ok? Agradeço muito a sua contribuição em compartilhar o seu conhecimento.

Thank you for sharing.

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