DEV Community


Posted on

Hosting a website locally.

Till this day I was using PHP servr (PHP -S) on Android (termux) to host a website locally. Now I want to use a database too. So I'm planning to host the website with Apache2. I've downloaded Apache2, PHP and MariaDB on Android with termux. Now I dont know how to integrate them. I hope someone understand me. Thanks in advance.

Top comments (1)

victorrims68524 profile image
Rimsha Victor Gill

Install Apache2, PHP, and MariaDB using the package manager in Termux:

Copy code
pkg install apache2 php mariadb
Configure Apache2 by editing the file /data/data/com.termux/files/usr/etc/apache2/httpd.conf:

Uncomment the line LoadModule php7_module modules/
Configure PHP by editing the file /data/data/com.termux/files/usr/etc/php.ini:

Set short_open_tag to On
Set display_errors to Off (recommended for production)
Start the MariaDB server:

Copy code
Create a new MySQL database and user:

Access the MariaDB shell:
Copy code
mysql -u root
Inside the MariaDB shell, run the following commands:
Copy code
CREATE DATABASE your_database_name;
CREATE USER 'your_username'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON your_database_name.* TO 'your_username'@'localhost';
Replace your_database_name, your_username, and your_password with your preferred values.

Place your website files in the web server root directory:
By default, the directory is located at /data/data/com.termux/files/usr/share/apache2/default-site/htdocs/.

Start the Apache2 server:

Copy code
apachectl start
Your website should now be accessible at localhost or on your Android device.

Following these steps will allow you to integrate Apache2, PHP, and MariaDB on Android with Termux, enabling you to develop and host your website locally with database support.