Linux PHP Guide - ryzendew/Linux-Tips-and-Tricks GitHub Wiki
Linux PHP Guide
Complete beginner-friendly guide to PHP on Linux, covering Arch Linux, CachyOS, and other distributions including installation, configuration, and web development.
Table of Contents
PHP Installation
Install PHP
Arch/CachyOS:
# Install PHP
sudo pacman -S php php-apache
# Or with FPM
sudo pacman -S php php-fpm
# Install extensions
sudo pacman -S php-gd php-mysql php-sqlite
Debian/Ubuntu:
sudo apt install php php-fpm php-mysql
Fedora:
sudo dnf install php php-fpm php-mysqlnd
Verify Installation
Check PHP:
# Check version
php --version
# Check modules
php -m
PHP Configuration
PHP.ini
Edit config:
# Edit PHP config
sudo vim /etc/php/php.ini
# Common settings
upload_max_filesize = 20M
post_max_size = 20M
memory_limit = 128M
Test PHP
Test PHP:
# Command line
php -r "echo 'Hello, World!';"
# Or create test file
echo "<?php phpinfo(); ?>" | php
PHP with Apache
Configure Apache
Enable PHP:
# Edit Apache config
sudo vim /etc/httpd/conf/httpd.conf
Add:
LoadModule php_module modules/libphp.so
AddHandler php-script .php
Restart Apache:
sudo systemctl restart httpd
PHP with Nginx
Configure PHP-FPM
Nginx with PHP-FPM:
# Edit Nginx config
sudo vim /etc/nginx/nginx.conf
Add:
location ~ \.php$ {
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
Troubleshooting
PHP Not Working
Check configuration:
# Check PHP
php -v
# Check Apache/Nginx config
sudo apachectl configtest
sudo nginx -t
Summary
This guide covered PHP installation, configuration, and web server integration for Arch Linux, CachyOS, and other distributions.
Next Steps
- Web Servers - Web server setup
- Apache Guide - Apache setup
- Nginx Guide - Nginx setup
- PHP: https://www.php.net/
This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.