国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home Backend Development PHP Tutorial The Android Elephpant - Laravel on your Android Phone?

The Android Elephpant - Laravel on your Android Phone?

Feb 10, 2025 am 08:56 AM

Building a PHP development environment using Termux on Android devices: A mobile development guide

The Android Elephpant - Laravel on your Android Phone?

Core points

  • Use powerful terminal emulator and Linux package collection Termux to build a PHP development environment on Android devices.
  • Running Laravel on Android requires installing packages such as PHP, Git, and Composer, and verifying the PHP installation using a simple phpinfo() test.
  • Data persistence of Android devices can be achieved through SQLite, a lightweight serverless file-type database engine, which is ideal for storing small amounts of data.
  • While Android devices cannot run complex test suites or MySQL, this setup is useful for small development tasks or emergency fixes, allowing PHP development anytime, anywhere without having to carry a laptop.

Not long ago, Christopher Pitt wrote an excellent article on how to write and run PHP code on iPad. After reading it, I thought to myself, “It’s cool to do the same thing on Android”, for example, you can write and edit code anytime on the go without having to carry your laptop with you. So I decided to do some research and see what I could come up with.

The Android Elephpant - Laravel on your Android Phone?

This tutorial is suitable for any type of Android device. I did this on my phone, but an Android tablet with a Bluetooth keyboard might be the ideal setup.

There are some different shell applications on Android. This tutorial will use an application called Termux.

The Android Elephpant - Laravel on your Android Phone?

Termux combines powerful terminal emulation and an extensive collection of Linux packages. It is also completely free and easy to use.

After installing Termux from the Play Store, first run the apt update command. According to the documentation: "This command needs to be run immediately after installation and then run regularly to receive updates."

Now is the exciting part. The first two commands I want to discuss are the apt list and apt list --installed commands. The first command will list all packages available to Termux. We can see that it supports many different programming languages, text editors, and has some useful utility packages such as zip, tar, and so on. The second command will list all installed packages. We can see that Termux has pre-installed some packages such as apt and bash.

My goal when testing Termux was to see if I could assemble a suitable *PHP development environment, so I first installed a text editor. I prefer Vim, but there are some other options available, such as Emacs and Nano. Vim's learning curve is a bit steep, but once you get the basics of it, it becomes very comfortable. You can use the apt install vim command to get Vim.

If you want to learn more about vim, here is a very good article, or, after installation, type vimtutor to use the built-in tutorial.

If you test this on an Android phone, running vim will bring the first set of problems. How do I press the Escape key? Termux has a large list of shortcut keys that can be used to emulate unavailable buttons on Android keyboard:

命令
Volume Up E Escape鍵
Volume Up T Tab鍵
Volume Up 1 F1 (Volume Up 2 → F2,以此類推)
Volume Up 0 F10
Volume Up B Alt B (使用readline時向后一個單詞)
Volume Up F Alt F (使用readline時向前一個單詞)
Volume Up X Alt X
Volume Up W 上箭頭鍵
Volume Up A 左箭頭鍵
Volume Up S 下箭頭鍵
Volume Up D 右箭頭鍵
Volume Up L | (管道字符)
Volume Up U _ (下劃線)
Volume Up P Page Up
Volume Up N Page Down
Volume Up . Ctrl (SIGQUIT)
Volume Up V 顯示音量控制

Now that our editor is up and running, it's time to install the packages we need: PHP, Git, and Composer.

apt install php
apt install git

This will install the latest PHP and Git packages.

The Android Elephpant - Laravel on your Android Phone?

For Composer, we need to do some extra work. We need to go to the Composer download page and use the command line installation instructions:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '55d6ead61b29c7bdee5cccfb50076874187bd9f21f65d8991d46ec5cc90518f447387fb9f76ebae1fbbacf329e583e30') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

This will download the installer, verify it, run it and delete it. If all goes well, we should be able to run Composer from Termux.

The Android Elephpant - Laravel on your Android Phone?

Now that we have all the tools installed, we should test if our PHP installation is running correctly. To do this, let's do a simple phpinfo() test. Let's create a new folder and test our PHP installation.

mkdir test
cd test
echo "<?php phpinfo();" ?> > index.php
php -S localhost:8080

This will create a new folder, and then create a phpinfo() file containing the index.php command. I echo it directly into the file, but you can do it with Vim. Finally, we use a PHP server to provide it to our localhost. When accessing localhost:8080 in the browser, we should see something like this:

The Android Elephpant - Laravel on your Android Phone?

We now have Composer for dependency management and git for version control. But I know what you're thinking: "We just did a simple phpinfo test, what about the rest?"

Can we install Laravel on our Android device?

At this point, we have everything we need to install and run Laravel on our Android device. To create a new Laravel project, we need to run the following command:

php composer.phar create-project --prefer-dist laravel/laravel new_project

This will create a new Laravel project in the new_project folder. The --prefer-dist option is well documented here. It may take a while to install. Once done, we can use Laravel's own Artisan command line interface to run our newly created project. In the new_project folder, we can run the following command:

php artisan serve

Accessing localhost:8000 URL in your browser should now display Laravel's homepage.

The Android Elephpant - Laravel on your Android Phone?

Success! Our Laravel installation is complete. We have successfully installed the tools we need to write and execute code. However, no development environment is complete without a method to persist data.

For Android devices, memory and storage capacity are practical issues in most cases. Therefore, Termux only provides SQLite as a way to persist data. SQLite is a serverless file-type database engine. It's lightweight and is perfect for a small amount of data, as you've read here and in this article that goes beyond the basics. First, we need to install it.

apt install php
apt install git

Next, we need to configure our Laravel project to use SQLite. In the root directory of the project, we have a .env file. This is the environment configuration file, the first file we need to edit. Use the editor of your choice to edit the following lines:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '55d6ead61b29c7bdee5cccfb50076874187bd9f21f65d8991d46ec5cc90518f447387fb9f76ebae1fbbacf329e583e30') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

Then go to the config/database.php file and turn the following line from:

mkdir test
cd test
echo "<?php phpinfo();" ?> > index.php
php -S localhost:8080

Change to:

php composer.phar create-project --prefer-dist laravel/laravel new_project

This will make SQLite the default connection in the connections array. Make sure the database.sqlite file path is correctly pointing to your database file.

database.sqliteThe file does not exist yet, so we need to create it:

php artisan serve

This is all the configuration we need to tell Laravel to use SQLite - we can test it now. We will use Laravel's pre-built authentication system. To create a scaffold, we need to run the following command:

apt install sqlite
After that, we will run the migration to build our database schema. This will create the

and users tables. password_reset

<code>DB_CONNECTION=sqlite
DB_DATABASE=homestead  # 或者更改為你的數(shù)據(jù)庫名稱</code>
If we run

again, we will see that we have the option to register and log in now. Our authentication CRUD has been successfully created! php artisan serve

The Android Elephpant - Laravel on your Android Phone?

Conclusion

I did all this on my Android phone. This setup is great for small development tasks, as it has all the tools you need to start developing on smaller devices without having to carry your laptop with you.

While it is not the pinnacle of productivity, it comes in handy when it comes to an emergency repair or if you want to see how much PHP performance you can squeeze from your Android device.

Try it and tell us your thoughts, if you build something interesting with PHP on Android, please market to us your concept and we will write about it!


*"Appropriate" refers to the appropriateness for the context. Android phones don't run MySQL, and they can't run complex test suites, especially end-to-end tests, but some other things may run well enough to do some work.

(The FAQs part is omitted because it does not match the pseudo-original goal and is too long.)

The above is the detailed content of The Android Elephpant - Laravel on your Android Phone?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What are some best practices for versioning a PHP-based API? What are some best practices for versioning a PHP-based API? Jun 14, 2025 am 12:27 AM

ToversionaPHP-basedAPIeffectively,useURL-basedversioningforclarityandeaseofrouting,separateversionedcodetoavoidconflicts,deprecateoldversionswithclearcommunication,andconsidercustomheadersonlywhennecessary.StartbyplacingtheversionintheURL(e.g.,/api/v

How do I implement authentication and authorization in PHP? How do I implement authentication and authorization in PHP? Jun 20, 2025 am 01:03 AM

TosecurelyhandleauthenticationandauthorizationinPHP,followthesesteps:1.Alwayshashpasswordswithpassword_hash()andverifyusingpassword_verify(),usepreparedstatementstopreventSQLinjection,andstoreuserdatain$_SESSIONafterlogin.2.Implementrole-basedaccessc

What are the differences between procedural and object-oriented programming paradigms in PHP? What are the differences between procedural and object-oriented programming paradigms in PHP? Jun 14, 2025 am 12:25 AM

Proceduralandobject-orientedprogramming(OOP)inPHPdiffersignificantlyinstructure,reusability,anddatahandling.1.Proceduralprogrammingusesfunctionsorganizedsequentially,suitableforsmallscripts.2.OOPorganizescodeintoclassesandobjects,modelingreal-worlden

What are weak references (WeakMap) in PHP, and when might they be useful? What are weak references (WeakMap) in PHP, and when might they be useful? Jun 14, 2025 am 12:25 AM

PHPdoesnothaveabuilt-inWeakMapbutoffersWeakReferenceforsimilarfunctionality.1.WeakReferenceallowsholdingreferenceswithoutpreventinggarbagecollection.2.Itisusefulforcaching,eventlisteners,andmetadatawithoutaffectingobjectlifecycles.3.YoucansimulateaWe

How can you handle file uploads securely in PHP? How can you handle file uploads securely in PHP? Jun 19, 2025 am 01:05 AM

To safely handle file uploads in PHP, the core is to verify file types, rename files, and restrict permissions. 1. Use finfo_file() to check the real MIME type, and only specific types such as image/jpeg are allowed; 2. Use uniqid() to generate random file names and store them in non-Web root directory; 3. Limit file size through php.ini and HTML forms, and set directory permissions to 0755; 4. Use ClamAV to scan malware to enhance security. These steps effectively prevent security vulnerabilities and ensure that the file upload process is safe and reliable.

How can you interact with NoSQL databases (e.g., MongoDB, Redis) from PHP? How can you interact with NoSQL databases (e.g., MongoDB, Redis) from PHP? Jun 19, 2025 am 01:07 AM

Yes, PHP can interact with NoSQL databases like MongoDB and Redis through specific extensions or libraries. First, use the MongoDBPHP driver (installed through PECL or Composer) to create client instances and operate databases and collections, supporting insertion, query, aggregation and other operations; second, use the Predis library or phpredis extension to connect to Redis, perform key-value settings and acquisitions, and recommend phpredis for high-performance scenarios, while Predis is convenient for rapid deployment; both are suitable for production environments and are well-documented.

What are the differences between == (loose comparison) and === (strict comparison) in PHP? What are the differences between == (loose comparison) and === (strict comparison) in PHP? Jun 19, 2025 am 01:07 AM

In PHP, the main difference between == and == is the strictness of type checking. ==Type conversion will be performed before comparison, for example, 5=="5" returns true, and ===Request that the value and type are the same before true will be returned, for example, 5==="5" returns false. In usage scenarios, === is more secure and should be used first, and == is only used when type conversion is required.

How do I perform arithmetic operations in PHP ( , -, *, /, %)? How do I perform arithmetic operations in PHP ( , -, *, /, %)? Jun 19, 2025 pm 05:13 PM

The methods of using basic mathematical operations in PHP are as follows: 1. Addition signs support integers and floating-point numbers, and can also be used for variables. String numbers will be automatically converted but not recommended to dependencies; 2. Subtraction signs use - signs, variables are the same, and type conversion is also applicable; 3. Multiplication signs use * signs, which are suitable for numbers and similar strings; 4. Division uses / signs, which need to avoid dividing by zero, and note that the result may be floating-point numbers; 5. Taking the modulus signs can be used to judge odd and even numbers, and when processing negative numbers, the remainder signs are consistent with the dividend. The key to using these operators correctly is to ensure that the data types are clear and the boundary situation is handled well.

See all articles