Using Apache+PHP on ARM Linux

Publisher:技术掌门Latest update time:2016-06-20 Source: eefocusKeywords:ARM  Linux  Apache+PHP Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
I believe this article is also a HOWTO that is hard to find in China (until I wrote it). My original purpose was to use PHP on ARM. I tried Busybox's httpd and boa, but they couldn't easily interface with PHP. So I made up my mind and compiled Apache. The advantage of using PHP on ARM is that the script is easier to write than cgi, but the price is that the speed is as slow as a snail. Don't expect many people to visit at the same time.
Another thing, there are many articles on the blog, and I often find that someone reprints them, but some people don't cite the source... Do you want me to write my name and email address in every part of the article? Maybe Chinese people lack a certain spirit. In the blogs that reprint my articles, they are basically a collection of various ARM Linux articles on the Internet. It is undeniable that they have collected them very well, but after reading so many articles, I don't even have a little experience. Is it so difficult to write something original? Anyway, I still stick to the style of EE Station-originality. Let's get to the point. This article is divided into three parts: apache, php and configuration.

Compile apache
Download apache 1.3.39 (1.3.41 has some bugs and cannot be cross-compiled)
Download address http://apache.mirror.phpchina.com/httpd/apache_1.3.39.tar.bz2


Cross-compiling apache generally requires two steps:
1. Compile native code
2. Use native code for cross-compilation

This is because when compiling apache, you need to use the compiled tools to make header files for subsequent compilation. Of course, the cross-compiled tools cannot be run on a PC, so you need to use the tools compiled by the native code. Assume that the Apache code compiled for the native machine has been unzipped to /home/lxz/apache-1.3.39-i586, the Apache code compiled for ARM has been unzipped to /home/lxz/apache-1.3.39, and the cross-compiler arm-linux-gcc has set the default path. The specific steps are still explained with commands:

# cd /home/lxz/apache-1.3.39-i586
# ./configure

Because you are only borrowing the native code, you don't need to set the configuration parameters, and then compile

# make

After the compilation is completed, you can configure the cross-compiled Apache. The installation location of apache is /usr/local/apache

# cd /home/lxz/apache-1.3.39
# CC=arm-linux-gcc ./configure --prefix=/usr/local/apache

There will be a prompt like this, because the testfunc tool generated by cross compilation cannot be executed on the PC, but you can ignore it./helpers/TestCompile
: line 294: /home/lxz/apache-1.3.39/src/helpers/testfunc: cannot execute binary file
Open the file /home/lxz/apache-1.3.39/src/main/Makefile and find these two codes
uri_delims.h: gen_uri_delims
./gen_uri_delims >uri_delims.h
test_char.h: gen_test_char
./gen_test_char >test_char.hChange
to
uri_delims.h: gen_uri_delims
/home/lxz/apache-1.3.39-i586/src/main/gen_uri_delims >uri_delims.h
test_char.h: gen_test_char
/home/lxz/apache-1.3.39-i586/src/main/gen_test_char >test_char.hHere
we borrow the tools from the native code generated by the compilation just now, and then

# make

the compilation is done, and the following is the installation. Because the installation location specified by the "prefix" parameter when configuring apache is /usr/local/apache, on the PC, accessing /usr/local requires root privileges, and you need to switch to the root user to install. It is not recommended to install apache to a random directory and then copy it, because this will cause errors in the script call location in apache. Of course, if you want to install apache to a fixed location that can be accessed by both PC and ARM Linux, such as /home/lxz/apache, it is also possible.
If you don't understand what the above paragraph is saying, then follow the steps below. Please make sure that the directory /usr/local/apache on your PC Linux does not exist in the apache used on the PC, otherwise the following steps will make the apache on your PC Linux unusable.

# su root

enter password

# cd /home/lxz/apache-1.3.39/
# make install
# exit

Don't forget to exit the root user mode with exit, so that the apache files are installed in /usr/local/apache on the PC. The next thing to do is to copy apache to the ARM Linux root file system. Assume that the location of the ARM Linux root file system on the PC is /home/lxz/root, which already has the directory /usr/local

# cp -r /usr/local/apache /home/lxz/root/usr/local

If you have built the root file system by following my blog, you must also create the nobody user and the nogroup group, because apache refuses to run as the root user. Specifically, create the /etc/passwd and /etc/group files on the ARM Linux root file system. You can google how to write these two files. Their contents can be as follows:

/etc/passwd
root::0:0:root:/:/bin/ash
nobody::65534:65533:nobody:/:/bin/ash
/etc/group
nobody::65533:
nogroup::65534:nobody
root::0:
users::100:
Of course, if there are these two files in your ARM Linux root file system, then you need to check whether there is a nobody user and a nogroup group. Next, you can create a file system image and test whether Apache can work properly. Let me use commands to illustrate.

# mkfs.cramfs /home/lxz/root /home/lxz/root.img

I have always used cramfs, and SUSE 10.2 comes with the mkfs.cramfs tool. I will not go into the steps of burning or loading file system images. It should be noted that if you use a non-writable file system, such as cramfs, you need to mount the Apache log path as a temporary file directory. The following commands are executed on ARM Linux.

# mount -t tmpfs tmpfs /usr/local/apache/log

Then you can start apache

# cd /usr/local/apache/bin
# ./apachectl start

Assuming the IP address of the ARM board is 192.168.5.118, enter http://192.168.5.118:8080 in the browser to access the ARM board (do not modify the default configuration, the service port is 8080). I will talk about the configuration of apache after compiling php.

To compile PHP
, first download PHP-4.4.8. Download address: http://cn2.php.net/get/php-4.4.8.tar.bz2/from/this/mirror.

Cross-compiling PHP also requires two steps:
1. Compile native code
2. Use native code for cross-compilation

I will not repeat the reasons. Assume that the PHP code compiled for the native machine has been unzipped to /home/lxz/php-4.4.8-i586, and the PHP code compiled for ARM has been unzipped to /home/lxz/php-4.4.8. The cross compiler arm-linux-gcc has set the default path. The specific steps are still explained with commands:

# cd /home/lxz/php-4.4.8-i586
# ./configure
# make

While compiling, you can open the file /home/lxz/php-4.4.8/configure and search for "can not run test program while cross compiling". You will find many results like this:
{ echo "configure: error: can not run test program while cross compiling compiling" 1>&2; exit 1; }
Change them all to
{ echo "configure: error: can not run test program while cross compiling" 1>&2; }
The purpose of this is to directly ignore the cross-compilation test program errors. In addition, I am using arm-linux-gcc version 3.4.1, which is not very compatible with the code. Find line 238 of /home/lxz/php-4.4.8/Zend/zend_strtod.c
#if defined(IEEE_LITTLE_ENDIAN) + defined(IEEE_BIG_ENDIAN) + defined(VAX) + \
    defined(IBM) != 1
Exactly one of IEEE_LITTLE_ENDIAN IEEE_BIG_ENDIAN, VAX, or
IBM should be defined.
#endif
Change this paragraph to
#if defined(IEEE_LITTLE_ENDIAN) + defined(IEEE_BIG_ENDIAN) + defined(VAX) + \
    defined(IBM) != 1
//Exactly one of IEEE_LITTLE_ENDIAN IEEE_BIG_ENDIAN, VAX, or
//IBM should be defined.
#endif
After compiling PHP on this machine, enter the following command

# cd /home/lxz/php-4.4.8
# CC=arm-linux-gcc ./configure --prefix=/usr/local/php --host=i586-suse-linux --target=arm-linux

Don't think you can compile it now, there are still some things to modify. It's really scary... Open /home/lxz/php-4.4.8/Makefile and find this
install-pear-packages: $(top_builddir)/sapi/cli/php
@$(top_builddir)/sapi/cli/php $(PEAR_INSTALL_FLAGS) /home/lxz/php-4.4.8/pear/install-pear.php -d "$(peardir)" -b "$(bindir)" /home/lxz/php-4.4.8/pear/packages/*.tar
Use the files in the local php we just compiled and change it to
install-pear-packages: /home/lxz/php-4.4.8-i586/sapi/cli/php
@/home/lxz/php-4.4.8-i586/sapi/cli/php $(PEAR_INSTALL_FLAGS) /home/lxz/php-4.4.8/pear/install-pear.php -d "$(peardir)" -b "$(bindir)" /home/lxz/php-4.4.8/pear/packages/*.tar
can finally be compiled

# make

Then, like apache, you need to switch users and install the php files to /usr/local/php

# su

Enter password

# cd /home/lxz/php-4.4.8
# make install
# exit

In this way, PHP is compiled.

Configure Apache and PHP
Next, you need to modify the configuration file so that Apache and PHP can work together. This configuration process is similar to the process of using apache+php under Windows, because I did not compile apache and php together, but just let apache recognize the ".php" extension and then call php. For convenience, the apache configuration file is directly given. The location of the configuration file is /usr/local/apache/conf/httpd.conf in the ARM Linux file system. The red words are modified or added based on the default configuration file.
ServerType standalone
ServerRoot "/usr/local/apache"
PidFile /usr/local/apache/logs/httpd.pid
ScoreBoardFile /usr/local/apache/logs/httpd.scoreboard
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 15
MinSpareServers 5
MaxSpareServers 10
StartServers 5
MaxClients 150
MaxRequests PerChild 0
Port 80
User nobody
Group
ServerAdmin cosine@126.com
DocumentRoot "/home/webroot"

    Options FollowSymLinks
    AllowOverride None


    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all


    UserDir public_html


    DirectoryIndex index.html
    DirectoryIndex index.php
    DirectoryIndex index.php3
    DirectoryIndex index.phtml

AccessFileName .htaccess

    Order allow,deny
    Deny from all
    Satisfy All

UseCanonicalName On

    TypesConfig /usr/local/apache/conf/mime.types

DefaultType text/ plain

    MIMEMagicFile /usr/local/apache/conf/magic

HostnameLookups Off
ErrorLog /usr/local/apache/logs/error_log
LogLevel warn
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
Log Format "%h %l %u %t \"%r\" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
CustomLog /usr/local/apache/logs/access_log common
ServerSignature On

    Alias ​​/icons/ "/usr/local/apache/icons/"
    
        Options Indexes MultiViews
        AllowOverride None
        Order allow,deny
        Allow from all
    

    Alias /manual/ "/usr/local/apache/htdocs/manual/"
    
        Options Indexes FollowSymlinks MultiViews
        AllowOverride None
        Order allow,deny
        Allow from all
    

    ScriptAlias /cgi-bin/ "/usr/local/apache/cgi-bin/"
    ScriptAlias /php4/ "/usr/local/php/bin/"
    # 注意 "/usr/local/php/bin/" 中最后一个"/"不可少
    
        AllowOverride None
        Options None
        Order allow,deny
        Allow from all
    



    IndexOptions FancyIndexing
    AddIconByEncoding (CMP,/icons/compressed.gif) x-compress x-gzip
    AddIconByType (TXT,/icons/text.gif) text/*
    AddIconByType (IMG,/icons/image2.gif) image/*
    AddIconByType (SND,/icons/sound2.gif) audio/*
    AddIconByType (VID,/icons/movie.gif) video/*
    AddIcon /icons/binary.gif .bin .exe
    AddIcon /icons/binhex.gif .hqx
    AddIcon /icons/tar.gif .tar
    AddIcon /icons/world2.gif .wrl .wrl.gz .vrml .vrm .iv
    AddIcon /icons/compressed.gif .Z .z .tgz .gz .zip
    AddIcon /icons/a.gif .ps .ai .eps
    AddIcon /icons/layout.gif .html .shtml .htm .pdf
    AddIcon /icons/text.gif .txt
    AddIcon /icons/c.gif .c
    AddIcon /icons/p.gif .pl .py
    AddIcon /icons/f.gif .for
    AddIcon /icons/dvi.gif .dvi
    AddIcon /icons/uuencoded.gif .uu
    AddIcon /icons/script.gif .conf .sh .shar .csh .ksh .tcl
    AddIcon /icons/tex.gif .tex
    AddIcon /icons/bomb.gif core
    AddIcon /icons/back.gif ..
    AddIcon /icons/hand.right.gif README
    AddIcon /icons/folder.gif ^^DIRECTORY^^
    AddIcon /icons/blank.gif ^^BLANKICON^^
    DefaultIcon /icons/unknown.gif
    ReadmeName README.html
    HeaderName HEADER.html
    IndexIgnore .??* *~ *# HEADER* README* RCS CVS *,v *,t


    AddLanguage da .dk
    AddLanguage nl .nl
    AddLanguage en .en
    AddLanguage et .ee
    AddLanguage fr .fr
    AddLanguage de .de
    AddLanguage el .el
    AddLanguage he .he
    AddCharset ISO-8859-8 .iso8859-8
    AddLanguage it .it
    AddLanguage ja .ja
    AddCharset ISO-2022-JP .jis
    AddLanguage kr .kr
    AddCharset ISO-2022-KR .iso-kr
    AddLanguage nn .nn
    AddLanguage no .no
    AddLanguage pl .po
    AddCharset ISO-8859-2 .iso-pl
    AddLanguage pt .pt
    AddLanguage pt-br .pt-br
    AddLanguage ltz .lu
    AddLanguage ca .ca
    AddLanguage es .es
    AddLanguage sv .sv
    AddLanguage cs .cz .cs
    AddLanguage ru .ru
    AddLanguage zh-TW .zh-tw
    AddCharset Big5         .Big5    .big5
    AddCharset WINDOWS-1251 .cp-1251
    AddCharset CP866        .cp866
    AddCharset ISO-8859-5   .iso-ru
    AddCharset KOI8-R       .koi8-r
    AddCharset UCS-2        .ucs2
    AddCharset UCS-4        .ucs4
    AddCharset UTF-8        .utf8
    
        LanguagePriority en da nl et fr de el it ja kr no pl pt pt-br ru ltz ca es sv tw
    

    AddType application/x-tar .tgz
    AddType application/x-httpd-php .php3
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php .phtml
    AddEncoding x-compress .Z
    AddEncoding x-gzip .gz .tgz

Action application/x-httpd-php "/php4/php"

    BrowserMatch "Mozilla/2" nokeepalive
    BrowserMatch "MSIE 4\.0b2;" nokeepalive downgrade-1.0 force-response-1.0
    BrowserMatch "RealPlayer 4\.0" force-response-1.0
    BrowserMatch "Java/1\.0" force-response-1.0
    BrowserMatch "JDK/1\.0" force-response-1.0

php也有配置文件,但是修改起来比较简单,只需要把/home/lxz/php-4.4.8/php.ini-dist到ARM Linux文件系统的/usr/local/php/lib,并改名为php.ini,找到
register_globals = Off
修改为
register_globals = On
保存就可以了。
如果你觉得上面的一切都很麻烦,可以在EE小站的SkyDrive下载我制作好的压缩包,地址http://cid-4201fdc93932ddaf.skydrive.live.com/self.aspx/EE小站琐碎文件/armv4-apache-php.tar.bz2,解压缩到ARM Linux根文件系统的/。这个压缩包包含apache 1.3.39和php 4.4.8,默认的网页服务器根目录为/home/webroot,默认监听端口为80。
Keywords:ARM  Linux  Apache+PHP Reference address:Using Apache+PHP on ARM Linux

Previous article:Using OpenGL on ARM Linux
Next article:Transplantation of Boa server on ARM+Linux

Recommended ReadingLatest update time:2024-11-16 19:28

Design of indoor temperature control system based on ARM
Aiming at the characteristics and shortcomings of winter heating system in northern my country, an indoor intelligent temperature control system based on embedded system ARM-Linux platform and fuzzy control technology is designed. Multi-point temperature acquisition is completed by using DS18B20 and ZigBee wireless
[Microcontroller]
Design of indoor temperature control system based on ARM
Tiny4412 learning (IV) transplanting linux-device tree (2) device tree LED lighting
Hardware platform: tiny4412 System: linux-4.4 File system: busybox-1.25 Compiler: arm-none-linux-gnueabi-gcc (gcc version 4.8.3 20140320) Uboot: Friendly built-in uboot This section modifies the device tree file to support LED lighting. 1. Device tree file     led_pin {     compatible         = "tiny4412,led_demo";  
[Microcontroller]
Tiny4412 learning (IV) transplanting linux-device tree (2) device tree LED lighting
ARM Cortex-M core interrupt/exception system, interrupt priority/nesting details
question When I was using the STM32F3 chip recently, I encountered such a problem: if the frequency of external interrupts is fast enough, and the previous interrupt has not been processed, how to handle the new interrupt? During debugging, I found that there are interrupts with suspended, activated, disabled and othe
[Microcontroller]
ARM Cortex-M core interrupt/exception system, interrupt priority/nesting details
ARM7 Thumb series embedded processors
    The arm7 Thumb series processors are a series of high-performance, low-power 32-bit RISC processors that combine the Thumb 16-bit reduced instruction set. The excellent code efficiency achieved by Thumb means a reduction in the demand for memory capacity, making it possible to achieve high performance that can onl
[Microcontroller]
ARM11 learning based on S3C6410 (XI) DDR initialization
     Previously, programs were run in the internal stepping stone. But the size of the stepping stone is very small. The size of ARM11 is only 8K. It is definitely not possible to run large programs in such a small space. So external memory is needed. The external memory of ARM11 uses DDR. So the DDR must be initializ
[Microcontroller]
ARM11 learning based on S3C6410 (XI) DDR initialization
Hardware Design of Frequency Hopping Radio Central Control Unit and Frequency Hopping Unit
1 Preface Frequency hopping communication is a branch of spread spectrum communication. Its working principle is that the carrier frequency of the transmission signal of the sender and receiver changes discretely according to a predetermined rule. In other words, the carrier frequency used in communication jump
[Microcontroller]
arm9(s3c2440)jlink烧写uboot
The author's development environment: operating system win7, development board GT2440, the computer has no serial port, and the u-to-serial port is used (this article briefly excerpts and organizes related resources) 1. Connect PC, JLink and development board 2. Install the jlink driver and configure jlink 3. The deve
[Microcontroller]
arm9(s3c2440)jlink烧写uboot
9.ARM addressing mode
1. Immediate addressing Immediate addressing is a special addressing mode. The operand itself is given in the instruction. The operand is obtained only when the instruction is fetched. This operand is called an immediate number, and the corresponding addressing mode is the immediate addressing mode. For example
[Microcontroller]
9.ARM addressing mode
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号