!/data/data/com.termux/files/usr/bin/bash¶
set -e
echo "[*] 1/7 Updating packages..." pkg update -y && pkg upgrade -y
echo "[*] 2/7 Installing Apache, PHP, MariaDB, phpMyAdmin, wget, unzip..." pkg install -y apache2 php php-apache mariadb phpmyadmin wget unzip
echo "[*] 3/7 Linking web root to shared storage..." mkdir -p ~/storage/shared/htdocs rm -rf $PREFIX/share/apache2/default-site/htdocs ln -s ~/storage/shared/htdocs $PREFIX/share/apache2/default-site/htdocs
echo "[*] 4/7 Creating minimal Apache config if missing..." mkdir -p $PREFIX/etc/apache2 if [ ! -f $PREFIX/etc/apache2/httpd.conf ]; then cat > \(PREFIX/etc/apache2/httpd.conf <<'EOF' ServerRoot "\)PREFIX/etc/apache2" Listen 8080
LoadModule mpm_event_module $PREFIX/lib/apache2/modules/mod_mpm_event.so LoadModule dir_module $PREFIX/lib/apache2/modules/mod_dir.so LoadModule php_module $PREFIX/lib/php-apache/libphp.so
DocumentRoot "\(PREFIX/share/apache2/default-site/htdocs" <Directory "\)PREFIX/share/apache2/default-site/htdocs"> Options Indexes FollowSymLinks AllowOverride None Require all granted
DirectoryIndex index.php index.html EOF echo "[] Apache config created." else echo "[] Apache config exists, skipping." fi
echo "[*] 5/7 Writing php.ini to suppress deprecations and enable buffering..." mkdir -p $PREFIX/etc mkdir -p $PREFIX/var/log cat > $PREFIX/etc/php.ini <<'EOF' [PHP] ; ------------------------------------------------------------------- ; Error handling and logging error_reporting = E_ALL & ~E_DEPRECATED & ~E_NOTICE & ~E_WARNING display_errors = Off display_startup_errors = Off log_errors = On error_log = $PREFIX/var/log/php_errors.log
; ------------------------------------------------------------------- ; Output buffering (prevents headers already sent issues) output_buffering = On implicit_flush = Off
; ------------------------------------------------------------------- ; Sessions session.use_strict_mode = 1 session.cookie_httponly = 1 EOF
echo "[*] 6/7 Upgrading phpMyAdmin to latest version..."
remove old¶
rm -rf $PREFIX/share/apache2/default-site/htdocs/phpmyadmin
fetch latest¶
LATEST=\((wget -qO- https://www.phpmyadmin.net/home_page/version.json | \ grep -Po '(?<="version":")[^"]+') wget -q https://files.phpmyadmin.net/phpMyAdmin/\)/phpMyAdmin-\({LATEST}-all-languages.zip -O /tmp/pma.zip unzip -q /tmp/pma.zip -d /tmp mv /tmp/phpMyAdmin-\)-all-languages $PREFIX/share/apache2/default-site/htdocs/phpmyadmin rm -rf /tmp/pma.zip
echo "[*] 7/7 Initializing MariaDB and setting root password..." if [ ! -d "\(PREFIX/var/lib/mysql/mysql" ]; then mariadb-install-db --user=\)(whoami) --basedir=\(PREFIX --datadir=\)PREFIX/var/lib/mysql fi
start, configure, stop¶
mariadbd-safe --skip-networking & sleep 5 mysql -u root <<SQL ALTER USER 'root'@'localhost' IDENTIFIED BY 'root'; FLUSH PRIVILEGES; SQL pkill mariadbd-safe
echo echo "[✓] Setup complete!" echo " To start the services, run:" echo " apachectl start" echo " mariadbd-safe &" echo echo " Then open in your browser:" echo " http://localhost:8080/" echo " http://localhost:8080/phpmyadmin"
Close apachectl stop mysqld_safe &
Later again
apachectl start mysqld_safe &
apachectl restart mysqld_safe &
Then open in browser http://localhost:8080 http://localhost:8080/phpmyadmin
Sure! Here's a narrative explanation of what each line of that script does — as if you were reading a guided walkthrough to setting up a XAMPP-like server in Termux:
Narrative Breakdown of the Script
!/data/data/com.termux/files/usr/bin/bash¶
This is the shebang line, which tells Termux to use its internal Bash shell to run the script. It's like saying, “Hey Termux, execute everything below using Bash.”
echo "[*] Updating packages..."
This is just a message to the user — it's saying: “I’m updating your package list and upgrading anything that’s outdated.”
pkg update -y && pkg upgrade -y
This command does two things:
pkg update refreshes the list of available packages (like apt update)
pkg upgrade installs newer versions of already installed packages The -y flag means “say yes to all prompts,” so the process is automatic.
echo "[*] Installing Apache, PHP, MariaDB, phpMyAdmin..."
Again, it tells you what it's doing next: “Now I’m installing the full server stack.”
pkg install -y apache2 php php-apache mariadb phpmyadmin
This installs all the components of a LAMP server:
apache2 — the web server
php — the scripting language
php-apache — lets Apache run PHP files
mariadb — a lightweight MySQL-compatible database
phpmyadmin — a web interface for managing databases
echo "[*] Linking web root to shared storage..."
This step is important — it tells you: “I'm putting your website files in /sdcard/htdocs so you can easily manage them with your Android file manager.”
mkdir -p ~/storage/shared/htdocs rm -rf $PREFIX/share/apache2/default-site/htdocs ln -s ~/storage/shared/htdocs $PREFIX/share/apache2/default-site/htdocs
Here’s what happens:
Create a htdocs folder in shared internal storage
Remove the default htdocs folder used by Apache
Create a symbolic link (shortcut) from Apache’s web root to /sdcard/htdocs so you can edit web files from Android easily
echo "[*] Configuring php.ini..."
The script tells you it's now going to make PHP behave nicely: “I’m setting up PHP to show most errors — but not annoying deprecated or notice-level messages.”
mkdir -p $PREFIX/etc cat > $PREFIX/etc/php.ini <<EOF [PHP] error_reporting = E_ALL & ~E_DEPRECATED & ~E_NOTICE display_errors = On EOF
This creates a basic php.ini configuration file:
Errors will be shown
Deprecated/notice messages are hidden to avoid screen clutter
This is essential for debugging and for phpMyAdmin to run quietly
echo "[*] Setting MySQL root password to 'root'..."
This is now preparing your MySQL (MariaDB) server: “Let’s initialize the database system and secure access with a default password.”
mysql_install_db mysqld_safe --skip-networking & sleep 5 mysql -u root -e "ALTER USER 'root'@'localhost' IDENTIFIED BY 'root'; FLUSH PRIVILEGES;" pkill mysqld_safe
Here’s what happens step-by-step:
-
mysql_install_db sets up MariaDB for first use.
-
mysqld_safe --skip-networking & starts MariaDB without network access, for safe setup.
-
sleep 5 waits a few seconds for the server to initialize.
-
mysql -u root -e ... changes the root password to 'root'.
-
pkill mysqld_safe kills the temporary MariaDB instance.
echo "[*] Ready. To start the server:"
Finally, it tells you the manual steps to launch the server:
apachectl start # Start Apache mysqld_safe & # Start MariaDB
Once started, you can access your local server and phpMyAdmin at:
http://localhost:8080 http://localhost:8080/phpmyadmin
Summary:
This script automates the entire setup of a local web server environment in Termux — like XAMPP but tailored for Android. It prioritizes:
Easy access via shared storage
Lightweight, efficient PHP and database setup
Clean error handling
Let me know if you want this made into a GitHub repo, shell package, or to add Python/Node.js support too.