Running Apache, PHP, MySQL / MariaDB Web Server on Android Using Termux
Tools & Materials
- Latest Termux Application
- Chrome or Firefox browser
- Nano Text Editor etc.
Apache and PHP configuration
- First download the Termux application on the Playstore when you just open the application and run this command to update to the latest package.
apt update && apt upgrade
- Next we will install the necessary packages
apt install apache2 php php-apache mariadb nano -y
Apache2 and PHP configuration
- When finished we will now configure Apache, type the following command then press enter
nano $PREFIX/etc/apache2/httpd.conf
- If the nano line number does not appear, please repeat it again with CTRL + x to exit nano and type it like this Then Enter now nano the line number appears
nano -\$lcw $PREFIX/etc/apache2/httpd.conf
- Please, friends, look for Listen text, to change the port to search for text with nano friends, press CTRL + W then Enter when you find it, please change the port you want (if not changed it's also okay, this is only optional), this Text Listen to be precise on line 52
Listen 8080
- Now look for the text ServerName then add the text below (the number 8080 equates to the Listen port above)
ServerName 127.0.0.1:8080
- Then look for the text LoadModule mpm_prefork then remove the # sign beside it
- Then add a comment to LoadModule mpm_worker_module libexec / apache2 / mod_mpm_worker.so so the module is changed like this
LoadModule mpm_prefork_module libexec/apache2/mod_mpm_prefork.so
# LoadModule mpm_worker_module libexec/apache2/mod_mpm_worker.so
- Now look for the text <IfModule unixd_module> then add this text above it
LoadModule php_module libexec/apache2/libphp.so
Addhandler php-script .php
- Now add this text at the very bottom
Include etc/apache2/extra/php_module.conf
Now we set up the DocumentRoot, this DocumentRoot will be the folder that will store the php scripts to run. look for the DocumentRoot text (CTRL + W enter the DocumentRoot text) then enter (line 246)
- You can change the folder to another place, for example in the internal memory or just leave it like that, the shortcomings in the internal memory of the cellphone are that the files / folders will not support permissions / chmod because it is not an ext partition. I just leave it like that
- When everything is finished, please save the configuration by pressing CTRL + O then Enter and CTRL + x
- Don't forget to create an empty file like this
touch $PREFIX/etc/apache2/extra/php_module.conf
- Please test whether the configuration is correct, just type this command
httpd -t
- when the Syntax OK appears, it means there is no error or success in the script
- first turn on the apache server by typing the command
sv reload httpd
sv up httpd
- To confirm whether the Apache server is running, we try to open the browser then enter the address http: // localhost: 8080 (the number 8080 is the port that you set in the Apache2 configuration above the Listen section) when it says "it works!" congratulations apache2 server is running well
- Next we will test with the php syntax to make sure Apache correctly loads the php module that we added above.
- Enter the folder where the root apache2 document is located in / usr / share / apache2 / default-site / htdocs / how to do it with the following cd command
cd $PREFIX/share/apache2/default-site/htdocs/
we can see there is one index.html file, it contains the text Its works which we saw earlier in the browser. please delete the file because it is no longer needed.
- now we make the index.php file still in the htdocs folder with nano
nano index.php
- then fill in the php script below
<?php
phpinfo();
- when finished, please save (CTRL + X) then press Y
- Now open the browser again and enter the url http: // localshost: 8080 / index.php
- If the image appears as below, it means that Apache has successfully loaded the PHP module, then we will configure Mysql / Mariadb
- please type the command below to first turn on the mysql server
sv up mysqld
- then we will configure the mysql password
mysql -u $(whoami)
- Next, type the line below the line by line then enter
use mysql; set password for 'root'@'localhost' = password('MASUKKAN_PASSWORD'); flush privileges; quit;in the INPUT_PASSWORD text, please set the password for later to access the mysql database
- now we test whether we can enter mysql by doing the command below
mysql -u root -p
- then enter the mysql password that we set above (the password is not visible) so if you have just press enter. if the display looks like this it means you can access the mysql server. now my friend can create databases, tables etc.
Okay, that's all the post this time, hopefully it's useful, look forward to the next post ... thanks ...
