In the current Internet era, web applications are ubiquitous. As one of the languages, PHP language is widely popular among developers. In development, many students use headless environment tools such as virtual machines or Docker prepared for Linux or Mac system users, but most of the time, they are too cumbersome and cumbersome. So in this article I will introduce a simpler method to build a PHP environment using Android Shell.
First of all, we need to prepare some necessary software and environment:
- An Android phone or Android emulator
- Install the Termux Terminal Emulator application
- PHP installation package of Termux Extra application package
After installing the Termux Terminal Emulator application, you need to download the "Termux Extra application package" in the Termux application.
Enter the following command in Termux:
pkg install php
The Termux package manager will automatically install the PHP and PHP-FPM services. Once installed, you can run PHP and set it to start with the system.
Next, we need to edit the configuration file of PHP-FPM so that when we access PHP files, Nginx can correctly send requests and communicate with the PHP-FPM process.
In Termux, enter the PHP directory:
cd /data/data/com.termux/files/usr/etc/php-fpm.d
Open the www.conf file with a text editor:
nano www.conf
Set user and group to the UID of the current Termux user:
user = ${UID} group = ${GID}
Find the listen variable, set it to UNIX Socket mode, and set it to /data/data/com.termux/files/usr/var/run/php-fpm.sock:
#(打开的时候前面的 ; 号必须删掉) listen = /data/data/com.termux/files/usr/var/run/php-fpm.sock listen.owner = ${UID} listen.group = ${GID} listen.mode = 0660
Save the file and close the Nano editor: Ctrl X, Y, Enter
Next, we need to configure the Nginx server to communicate with the above PHP-FPM process. You can download and install Nginx from the official website, or you can download and install it from the Termux package manager:
pkg install nginx
After installation, run the following command in Termux to start the Nginx server:
nginx
At this point, Nginx will start and listen for requests on port 8080.
You can test whether Nginx starts successfully. Open your browser and visit http://localhost:8080. Nginx will return the default Welcome To Nginx text.
Now, we will create a simple PHP web page to test whether our CMS is installed successfully. Open your text editor and create the following index.php file:
<?php echo "Hello, PHP on Android!" ?>
Save the above file to /data/data/com.termux/files/home/my-www (please create this first in Termux Table of contents).
Next, we need to create Nginx’s virtual host configuration file to direct the Nginx server to find our web page and pass it to the PHP-FPM process. Enter the following command in the Termux command prompt:
nano /data/data/com.termux/files/usr/etc/nginx/conf.d/default.conf
Add the following content to the file, configuring the root directory to the directory created in the previous step: /data/data/com.termux/files/home/ my-www/
server { listen 8080; root /data/data/com.termux/files/home/my-www; index index.php; server_name localhost; location / { try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$ { try_files $uri =404; fastcgi_pass unix:/data/data/com.termux/files/usr/var/run/php-fpm.sock; fastcgi_index index.php; include fastcgi.conf; } }
Exit the Nano editor (Ctrl X, Y, Enter), and then restart Nginx through the following command:
nginx -s reload
At this time, enter http:// in the browser localhost:8080/index.php You can see the output: Hello, PHP on Android!
Here, we have used a simple method to upload the configuration and established a lightweight PHP environment that can be convenient for desktop or mobile web development. If you need to deploy PHP in a production environment, there are additional security and scaling considerations.
Quote:
1.https://www.linuxidc.com/Linux/2019-09/160469.htm
2.https ://www.guru99.com/php-installation-and-configuration-in-android-termux.html
The above is the detailed content of How to build php in Android shell. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Atom editor mac version download
The most popular open source editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Notepad++7.3.1
Easy-to-use and free code editor

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
