This content originally appeared on DEV Community and was authored by Athreya aka Maneshwar
Hi there! I’m Maneshwar. Right now, I’m building LiveAPI, a first-of-its-kind tool that helps you automatically index API endpoints across all your repositories. LiveAPI makes it easier to discover, understand, and interact with APIs in large infrastructures.
Manually installing PHP across servers? Nah.
Let’s make it boringly repeatable with Ansible.
This playbook snippet handles PHP 7.3 installation along with all the commonly used extensions.
No more apt install
gymnastics on every new box.
Prerequisites
- Ubuntu server (18.04 or later works well)
- Ansible installed on your control machine
- SSH access to target machine(s)
What This Playbook Does
- Adds the trusted Ondřej Surý PPA for PHP.
- Installs
php7.3
. - Installs all commonly needed PHP 7.3 extensions.
- Verifies the installation with
php -v
.
The Playbook
---
- name: Install PHP 7.3 and Extensions
hosts: all
become: true
tasks:
- name: Add PHP PPA repository
apt_repository:
repo: "ppa:ondrej/php"
state: present
update_cache: yes
- name: Install PHP 7.3
apt:
name: php7.3
state: present
update_cache: yes
- name: Verify PHP installation
command: php -v
register: php_version
changed_when: false
- name: Display PHP version
debug:
msg: "{{ php_version.stdout }}"
- name: Install PHP 7.3 extensions and dependencies
apt:
name:
- php7.3-bcmath
- php7.3-bz2
- php7.3-curl
- php7.3-gd
- php7.3-gmp
- php7.3-imap
- php7.3-intl
- php7.3-json
- php7.3-ldap
- php7.3-mbstring
- php7.3-mysql
- php7.3-opcache
- php7.3-readline
- php7.3-soap
- php7.3-sqlite3
- php7.3-tidy
- php7.3-xml
- php7.3-xmlrpc
- php7.3-xsl
- php7.3-zip
- php7.3-cli
- php7.3-common
state: present
update_cache: yes
Running the Playbook
ansible-playbook -i hosts.ini php73.yml
Make sure your inventory (hosts.ini
) is properly set up and includes the correct ansible_user
and SSH access.
Output You Should See
You’ll get output like:
TASK [Verify PHP installation]
ok: [myserver]
TASK [Display PHP version]
ok: [myserver] => {
"msg": "PHP 7.3.33-9+ubuntu18.04.1+deb.sury.org+1 (cli) ..."
}
Bonus: Reuse via Roles
Want to reuse this across projects? Move it into a role (e.g., roles/php73/
) and include it like this:
roles:
- php73
Note
PHP 7.3 is EOL. Only use this if:
- You’re dealing with legacy apps.
- You’re explicitly required to stay on this version.
Otherwise, consider installing a more recent version like PHP 8.1 or 8.2.
That’s It
You now have a fully automated PHP 7.3 setup using Ansible. This keeps your infrastructure consistent, easy to update, and less prone to manual errors.
Let the YAML do the talking.
LiveAPI helps you get all your backend APIs documented in a few minutes.
With LiveAPI, you can generate interactive API docs that allow users to search and execute endpoints directly from the browser.
If you’re tired of updating Swagger manually or syncing Postman collections, give it a shot.
This content originally appeared on DEV Community and was authored by Athreya aka Maneshwar