简体   繁体   中英

How to build a simple website into a embedded Linux using Apache and Yocto?

I like to build a demo of a website running on an eval board from ATMEL. For this eval board I am building an Linux by the use of Yocto. For handling the website the apache webserver should be used.

I got the apache2 recipe build and installed, as well as my simple website. But I failed to set up the apache configuration right.

My system has two ethernet ports eth0 and eth1. Eth0 is configured to the IP 1.2.3.4 and eth1 to dchp. The index.html should be accessed through eth0. Maybe it is possible to have an literal like "mywebsite" to access it. The website files are put in to the custom dir: /var/www/html/

Actual I am copying an virtual host config(myweb.conf) to /etc/apache2/sites-available/. It looks like:

# Ensure that Apache listens on port 80
Listen 80

<VirtualHost *:80>
        ServerName mywebsite
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/
        <Directory /var/www/html/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>
        ErrorLog /var/log/apache2/error.log
        LogLevel warn
        CustomLog /var/log/apache2/access.log combined
        ServerSignature On
</VirtualHost>

The yocto recipe unzips the index.html which is in myweb.zip and installs the virtual host config. The code looks like:

SUMMARY = "myweb"
SECTION = "test"
LICENSE = "CLOSED"

SRC_URI = "file://myweb.zip \
    file://myweb.conf \
    "

DEPENDS = "apache2"

S = "${WORKDIR}"

WWWdestPATH = "/var/www/html/"

do_install () {
    install -d ${D}${WWWdestPATH}
    cp -r ${S}/myweb/* ${D}${WWWdestPATH}

    install -d ${D}/etc/apache2/sites-available/
    cp ${S}/myweb.conf ${D}/etc/apache2/sites-available/myweb.conf
}

FILES_${PN} += "${WWWdestPATH}*"
FILES_${PN} += "/etc/apache2/sites-available/*"

Any ideas how to modify the files to get the website started?

Stefan,

If I understand you correctly you want to host web pages on the ATMEL board for clients connecting via eth0. I can't see anything obviously incorrect in your virtual host definition.

Adding mywebsite as ServerName tells Apache that that is the name for this specific virtual host - but clients still need to be able to resolve that name. Please note that if you only have a single site on the server the name doesn't matter in the Apache configuration - what matters is the DNS configuration. As long as the hostname resolves to the web server any request for any hostname would get the default site - unless there is a virtual site with a name that matches the requested host name.

What I would do is to start from the web server end and work your way out from there:

  1. If you have included telnet in your build you could for instance access the web page directly from the command line to make sure that it answers. Do this on the ATMEL board (eg via ssh or if you have a display+keyboard):

     telnet localhost 80 <ENTER> GET / HTTP/1.1 <ENTER> Host: mywebsite <ENTER><ENTER> 

    If that returns your web page then the web server is configured correctly.

  2. Make sure that you can reach the ATMEL board from your client. On the client:

     ping 1.2.3.4 

    If this doesn't work you need to put the client on the same network as the eth0 interface by setting it manually on the client or by adding a DHCP server on the ATMEL board, bound to eth0.

  3. Make sure that the client can resolve the mywebsite host name. On the client:

     ping mywebsite 

    If this doesn't work you need to add a DNS service (eg bind) to your image or, for a quick test, add the following line to the /etc/hosts file on your client (c:\\windows\\system32\\drivers\\etc\\hosts if you are running Windows):

     1.2.3.4 mywebsite 

Hope that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM