Skip to content

Linux PHP Guide

Mattscreative edited this page Dec 5, 2025 · 2 revisions

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

  1. PHP Installation
  2. PHP Configuration
  3. PHP with Apache
  4. PHP with Nginx
  5. Troubleshooting

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


This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.

Clone this wiki locally