This guide provides a complete Ansible playbook to install phpSysInfo from source with proper configuration for displaying system information via web interface.
Current phpSysInfo version: 3.4.1
Create a file named phpsysinfo.yml:
---
- name: Install and Configure phpSysInfo
hosts: phpsysinfo
become: true
vars:
phpsysinfo_version: "3.4.1"
phpsysinfo_port: 80
phpsysinfo_dir: "/var/www/phpsysinfo"
tasks:
- name: Install prerequisites (Debian/Ubuntu)
apt:
name:
- php
- php-xml
- php-mbstring
- php-json
- nginx
- git
- lm-sensors
- hddtemp
state: present
update_cache: true
when: ansible_os_family == "Debian"
- name: Install prerequisites (RHEL/CentOS)
yum:
name:
- php
- php-xml
- php-mbstring
- php-json
- nginx
- git
- lm_sensors
state: present
when: ansible_os_family == "RedHat"
- name: Create phpSysInfo directory
file:
path: "{{ phpsysinfo_dir }}"
state: directory
owner: www-data
group: www-data
mode: '0755'
- name: Download phpSysInfo
get_url:
url: "https://github.com/phpsysinfo/phpsysinfo/archive/refs/tags/{{ phpsysinfo_version }}.tar.gz"
dest: "/tmp/phpsysinfo.tar.gz"
mode: '0644'
- name: Extract phpSysInfo
unarchive:
src: /tmp/phpsysinfo.tar.gz
dest: /tmp
remote_src: true
creates: "/tmp/phpsysinfo-{{ phpsysinfo_version }}"
- name: Copy phpSysInfo files to web directory
copy:
src: "/tmp/phpsysinfo-{{ phpsysinfo_version }}/"
dest: "{{ phpsysinfo_dir }}/"
remote_src: true
owner: www-data
group: www-data
- name: Set proper permissions
file:
path: "{{ phpsysinfo_dir }}"
owner: www-data
group: www-data
mode: '0755'
recurse: true
- name: Create phpSysInfo configuration
copy:
dest: "{{ phpsysinfo_dir }}/config.php"
owner: www-data
group: www-data
mode: '0644'
content: |
<?php
// phpSysInfo Configuration
define('PSI_ROOT_FILESYSTEM', '');
define('PSI_LOG_FILE', '{{ phpsysinfo_dir }}/data/phpsysinfo.log');
define('PSI_LOAD_BAR', 'local');
// System settings
define('PSI_SYSTEM_LANG', 'en');
define('PSI_SYSTEM_THEME', 'Bootstrap');
define('PSI_SYSTEM_TEMPLATE', 'bootstrap');
// Display options
define('PSI_SHOW_PICKLIST_LANG', 'false');
define('PSI_SHOW_PICKLIST_THEME', 'false');
define('PSI_SHOW_PICKLIST_TEMPLATE', 'false');
// Hardware sensors
define('PSI_SENSOR_LIST', 'true');
define('PSI_HDD_TEMP', 'true');
define('PSI_UPS_INFO', 'false');
// Network
define('PSI_NETWORK_INTERFACE', 'auto');
define('PSI_NETWORK_ACTIVE_ONLY', 'true');
// Refresh interval (seconds)
define('PSI_REFRESH', '60');
- name: Create data directory
file:
path: "{{ phpsysinfo_dir }}/data"
state: directory
owner: www-data
group: www-data
mode: '0775'
- name: Configure Nginx for phpSysInfo
copy:
dest: /etc/nginx/sites-available/phpsysinfo
owner: root
group: root
mode: '0644'
content: |
server {
listen {{ phpsysinfo_port }};
server_name {{ ansible_fqdn | default(ansible_hostname) }};
root {{ phpsysinfo_dir }};
index index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
# Deny access to sensitive files
location ~ /(config\.php|phpsysinfo\.ini|\.git) {
deny all;
}
}
when: ansible_os_family == "Debian"
- name: Enable phpSysInfo site (Debian/Ubuntu)
file:
src: /etc/nginx/sites-available/phpsysinfo
dest: /etc/nginx/sites-enabled/phpsysinfo
state: link
when: ansible_os_family == "Debian"
- name: Restart Nginx
systemd:
name: nginx
enabled: true
state: restarted
- name: Configure firewall (UFW)
ufw:
rule: allow
port: "{{ phpsysinfo_port }}"
proto: tcp
comment: "phpSysInfo web interface"
when: ansible_os_family == "Debian"
failed_when: false
- name: Verify phpSysInfo installation
uri:
url: "http://localhost/"
method: GET
status_code: 200
register: health_check
retries: 3
delay: 3
until: health_check.status == 200
- name: Display phpSysInfo status
debug:
msg: |
phpSysInfo {{ phpsysinfo_version }} installed successfully!
Web Interface: http://{{ ansible_default_ipv4.address | default(ansible_host) }}/
Installation directory: {{ phpsysinfo_dir }}
Configuration file: {{ phpsysinfo_dir }}/config.php
---
phpsysinfo:
hosts:
phpsysinfo-server:
ansible_host: 192.168.1.128
ansible_user: ansible
ansible_become: true
# Test connectivity
ansible all -i inventory.yml -m ping
# Run the phpSysInfo playbook
ansible-playbook -i inventory.yml phpsysinfo.yml
# Test web interface
curl http://phpsysinfo-server/
# Access web UI
# http://phpsysinfo-server/
- name: Configure hardware sensors for phpSysInfo
hosts: phpsysinfo
become: true
tasks:
- name: Detect hardware sensors
command: sensors-detect --auto
register: sensors_detect
changed_when: false
failed_when: false
- name: Load sensor modules
modprobe:
name: "{{ item }}"
state: present
loop:
- coretemp
- k10temp
failed_when: false
- name: Enable lm-sensors service
systemd:
name: lm-sensors
enabled: true
state: started
failed_when: false
- name: Update phpSysInfo config for sensors
lineinfile:
path: "{{ phpsysinfo_dir }}/config.php"
regexp: "^define\\('PSI_SENSOR_LIST'"
line: "define('PSI_SENSOR_LIST', 'true');"
# Check Nginx logs
sudo tail -f /var/log/nginx/error.log
# Check PHP errors
sudo tail -f /var/log/php_errors.log
# Verify permissions
sudo ls -la /var/www/phpsysinfo/
# Check sensors
sensors
# Load required modules
sudo modprobe coretemp
# Check permissions
sudo chmod 644 /sys/class/hwmon/*/temp*_input
We develop tailored automation solutions for:
Let’s discuss your requirements: office@linux-server-admin.com | Contact