LAMP Stack on IMX-6 Sabrelite

Introduction :

LAMP STACK stands for- 

L- Linux 

A- Apache server 

M- Mysql Server and Client 

P- All the programming language that starts from p.(Php,pearl,python etc). 

Definition of LAMP stack-The reason they call it a stack is because each level derives off it's base layer. Our Operating system, Linux, is the base layer. Then Apache, web daemon sits on top of OS. Then Our database stores all the information served by our web daemon, and PHP (or any P* scripting language) is used to drive and display all the data, and allow for user interaction.

So through Lamp stack we can create a truly database-driven and dynamic Web site that is easy to update and provides rich functionality to support users. 

Features Of Lamp Stack

About Linux:

A freely distributed open source operating system that runs on a number of hardware platforms.

About Apache:

Only Web server to run on all the major platform (*NIX ,Windows,mac,freebsd and other we name it)

About Mysql:

Open Source database server that relies on SQL for processing the data in the database..

Work on more than 20 platform including Linux ,Windows ,OS/X ,HP-UX,AIX and some more

About Php:

Open source server side scripting language designed specifically for the web. 

Output not only html but can also output xml,images (JPG and PNG),PDF files,flash movies. 

Some thing what we love today on web are: 

  • Google , Orkut , Facebook ,YouTube ,Gmail etc. all these famous and our favorite web apps are running some how on Lamp stack.
  • Wikipedia uses PHP, MySQL, and Apache HTTPD to provide an online encyclopedia with thousands of entries in multiple languages. All of this is served by Linux servers running the WikiMedia application. 

How it is Working:

  • The Apache server running on Linux is an easy way of building a simple Web server, but the information provided by the Apache server will be "static" — that is, basic pages of information that the we must build and type ourself. 
  • Adding interactive or dynamic components requires the use of a programming language, like Perl or PHP. These languages will allow us to work with forms. For example, they let our users send us an e-mail or randomly select a page to visit.
  • For truly interactive and dynamic Web sites, however, what we need is a way of building pages composed of information in a database.

For this MySql server and MySql CLient needs to be installed in our system.With the help of Mysql Server we can dump our database in forms of tables and MySql Client will provide interface (like command promt ) to access those tables. 

For Example-If we want to create an online store . We could do it using static pages. But we could even use dynamic elements to let people add products to their basket and send their order to us.

Our Achievements:

  • Cross compiled all the dependent libraries of Lamp stack for arm platform (IMX-6 sabrelite).
  • Lamp stack is up within 12 sec (Including Boot time).It means all the server ,Web demon   (Apache configured with Php) and Mysql Server is running successfully.

Techincal detailes of Bringing up Lamp Stack on Imx:

1) Cross compiling LAMP stack through ltib:

1.1 Create ltib environment for your PC.Follow the document named Ltib Document.txt provided in same directory. Linux part will be done while creating environment for ltib for your PC. 

1.2    Steps to cross compile apache. 

1.2.1 Go to main ltib directory and use: 

1.2.2 $./ltib -m config 

1.2.3 Select Package list under package selection .Then select httpd (apache) web server.    Exit from there and save the configuration. 

1.2.4 Run ltib command. 

          $./ltib 

1.3. Steps to cross compile Php,perl,python. 

1.3.1 Copy php-5.3.27.tar.bz2 and php-no-iconv-searchmysq.patch to /opt/freescale/pkgs/. 

         Modify the php.spec file as per new version of php. php.spec is provided in main       directory, directly replace that file.

1.3.2 Run ltib command. 

         $./ltib 

1.3.3 Steps to cross compile mysql. 

1.3.4  Copy php-5.3.27.tar.bz2 to /opt/freescale/pkgs/. Modify the mysql.spec file as per new version of mysql. mysql.spec is provided in main       directory, directly replace that file.

1.3.5 Run ltib command. 

         $./ltib 

Note:Also cross compile dhcpcd to enable networking. 

If you reached here means you have cross compiled LAMP stack successfully.
 

2) Steps to run LAMP stack on Target board

To start apache server on Target. 

$./usr/bin/apachectl start

Copy your php program into /usr/htdocs folder. 

Example : Hellowolrd.php 

Check localhost for your target board.To make local host up. 

$ifconfig lo up 

$ifconfig 

Output: 

lo        Link encap:Local Loopback  

          inet addr:127.0.0.1  Mask:255.0.0.0 

          UP LOOPBACK RUNNING  MTU:16436  Metric:1 

          RX packets:0 errors:0 dropped:0 overruns:0 frame:0 

          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 

          collisions:0 txqueuelen:0 

          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B) 

$wget http://localhost/ 

Output: 

Connecting to localhost (127.0.0.1:80) 

index.html           100% |*******************************|  1456   0:00:00 ETA 

     or 

Open any browser and type localhost/ 

Output:It should show that apache is working. 

To compile php program.

$wget http://localhost/Helloworld.php 

Output: 

Connecting to localhost (127.0.0.1:80) 

my.php               100% |*******************************|    16   0:00:00 ETA 

To check the output of php program.

$cat Helloworld.php 

Output: 

 Hello, World! 

or 

Open any browser on board and type localhost/Helloworld.php 

Output: 

 Hello, World! 

Note:If you will get the above output for given Helloworld php program then php and apache is configured properly. 

To run mysql server follow the document named mysql_runtime_error.txt provided in same directory. 

Note:All the initial commands to make LAMP satck up on target board are added in initial script (/etc/rc.d/rcS) itself. Boot time is 13 seconds.
 

3) Copying Rootfs 

The file system format ext3 or ext4 is a good option for removable media due to the

built-in journaling. Run the following command to format the partition:

$ sudo mkfs.ext3 /dev/sdb1

Or

$ sudo mkfs.ext4 /dev/sdb1

→  Copy the target file system to the partition:

$ mkdir /home/user/mountpoint 

$ sudo mount /dev/sdb1 /home/user/mountpoint

→  Extract rootfs package to certain directory: extract rootfs.ext2.gz to /home/user/rootfs for example:

$ gunzip rootfs.ext2.gz

$ mount -o loop -t ext2 rootfs.ext2 /home/user/rootfs

→ Assume that the root file system files are located in /home/user/rootfs as in the previous step:

$ cd /home/user/rootfs

$ sudo cp -rpa [A-z]* /home/user/mountpoint

$ sudo umount /home/user/mountpoint
 

4) Fixing Errors

Apache compile time error:

1.Apache was itself not cross compiled properly.Encountered following errors: 

error("Sorry, no shared object support for Apache");

error("available under your platform. Make sure");

error("the Apache module mod_so is compiled into");

Fix:--- httpd-2.0.54.orig/support/apxs.in 

+++ httpd-2.0.54/support/apxs.in

-unless (grep /mod_so/, `. $envvars && $httpd -l`) {

my $httpd_l ="Compiled in modules: \n core.c \n mod_access.c \n mod_auth.c \n mod_include.c \n mod_log_config.c \n mod_env.c \n mod_setenvif.c \n prefork.c \n http_core.c \n mod_mime.c \n mod_status.c \n mod_autoindex.c \n mod_asis.c \n mod_cgi.c \n mod_negotiation.c \n mod_dir.c \n mod_imap.c \n mod_actions.c \n mod_userdir.c \n mod_alias.c \n mod_so.c";

unless (grep /mod_so/, "$httpd_l") {

#unless (grep /mod_so/, `. $envvars && $httpd -l`) {

2.Some errors related path of headers files.

Fix:Giving full path resolved this issue.

File name:Script in /usr/local/apache2/bin:apxs,/usr/local/apache2/build/instdso.sh

Exp:my $targetdir="/home/sateesh-(user name)/buildroot/buildroot-2013.08.1/output/target";

my $installbuilddir = "$targetdir/usr/local/apache2/build";(same for other problem)

Some others files also required full path:httpd.h,apr_strings.h etc

Mysql compile Time Error:

1./bin/rm: cannot remove `libtoolT': No such file or directory 

edit configure and change  $RM "$cfgfile" to  $RM -f "$cfgfile" to fix "cannot remove `libtoolT': No such file or directory'" error. 

2.lib/ld-linux.so.3: No such file or directory 

#sudo apt-get install libc6-armel-cross 

#sudo ln -sf /usr/arm-linux-gnueabi/lib/ld-linux.so.3 /lib/ld-linux.so.3 

3./lib/ld-uClibc.so.0: No such file or directory 

Locate ld-uClibc.so.0 

#sudo ln -sf <path>lib/ld-uClibc.so.0 /lib/ld-uClibc.so.0 

4.I get the following on SCO 5.0.4: 

sql_lex.cc: In function `void lex_init()': 

sql_lex.cc:93: `symbols' undeclared (first use this function) 

sql_lex.cc:93: (Each undeclared identifier is reported only once 

sql_lex.cc:93: for each function it appears in.) 

sql_lex.cc:95: `sql_functions' undeclared (first use this function) 

sql_lex.cc: In function `int find_keyword(LEX *, unsigned int, bool)': 

sql_lex.cc:180: implicit declaration of function `int get_hash_symbol(...)' 

sql_lex.cc:180: initialization to `SYMBOL *' from `int' lacks a cast 

I have compiled other version withour problems. 

copy gen_lex_hash from host-mys 

configure && make 

[this error occurs] 

$ cd sql 

$ ./gen_lex_hash > lex_hash.h 

$ cd .. 

$ make 

 Some more Errors and Fixes.
 

5. Could not run test programme

Fix:  /output/build/host_mysql_client-5.1.67/configure changed the condition for tests so it will not run test program or it ll go forward even if it couldnt run the test program.
 

6. I have located this particular my_config.h from different build root source and compiled.
 

7.error: /bin/bash: ./gen_lex_hash: cannot execute binary file.

Fix: this is because buildroot is trying to executable compiled for arm Platform.so we copied gen_lex_hash from /output/build/host_mysql_client-5.1.1.67/sql/gen_lex_hash to /output/build/mysql_client-5.1.1.67/sql/gen_lex_hash as this file is compiled for host which is X86
 

8.error: operator '<' has no left operand 

Fix: initialized macro STACKDIRECTION to -1 which means stack grows form High address to low address value.In file /output/build/mysql_client.5.1.1.67/include/my_config.h and sql_parse.cc .Add # Define STACK_DIRECTION -1 in both files my_config.h and sql_parse.cc .

This link has been very helpful to solve last two errors.

http://translate.google.co.in/translate?hl=en&sl=zh-CN&u=http://www.cnblogs.com/yoleung/articles/1454763.html&prev=/search%3Fq%3Dsql%2Bcannot%2Bexecute%2Bgen_lex_hash%2Bbinary%2Bfile%26biw%3D1301%26bih%3D678

Mysql Run Time Error:

 1.

700101 01:20:44  mysqld started 

700101  1:20:44 [ERROR] Can't start server : Bind on unix socket: Permission denied 

700101  1:20:44 [ERROR] Do you already have another mysqld server running on socket: /tmp/mysql.sock ? 

700101  1:20:44 [ERROR] Aborting 

Fix: $chown -R mysql:mysql /tmp/ 

Check /tmp/mysql.sock is created or not:Created then successfull 

2. Fatal error: Can't open privilege tables: Table 'mysql.host' doesn't exist 

Fix:Tables are not created we need to run the following script: 

$mysql_install_db

Error while running above command: 

While running mysql_install_db,it is running through memory issue:No space left on device.Unable to create tables or does not exist 

Issue:

$df -h 

Output: 

/tmp folder is allocated by 512K,So when running mysql_install_db will try to install created database table into /tmp folder ,it will run through memory issue because /tmp is already full. 

Fix: 

I have edited /etc/rc.d/rc.conf 

export TMPFS_SIZE="512" to export TMPFS_SIZE="12M" .Change it as per your need.

3. 

071202 14:52:11 mysqld started 

071202 14:52:11 InnoDB: Operating system error number 13 in a file operation. 

InnoDB: The error means mysqld does not have the access rights to 

InnoDB: the directory. 

InnoDB: File name ./ibdata1 

InnoDB: File operation call: ‘create’. 

InnoDB: Cannot continue operation. 

071202 14:52:11 mysqld ended 

Fix: 

First update your my.cnf file for innoDB support 

$cp /usr/local/share/mysql/my-small.cnf /etc/rc.d/init.d/my.cnf 

Then update your paths in my.cnf as following. 

$ vi /etc/my.cnf 

# Uncomment the following if you are NOT using BDB tables 

#skip-bdb 

# Uncomment the following if you are using InnoDB tables 

innodb_data_home_dir = /usr/var/ 

innodb_data_file_path = ibdata1:10M:autoextend 

innodb_log_group_home_dir = /usr/var/ 

innodb_log_arch_dir = /usr/var/ 

# You can set .._buffer_pool_size up to 50 - 80 % 

# of RAM but beware of setting memory usage too high 

innodb_buffer_pool_size = 16M 

innodb_additional_mem_pool_size = 2M 

Set .._log_file_size to 25 % of buffer pool size 

innodb_log_file_size = 5M 

innodb_log_buffer_size = 8M 

innodb_flush_log_at_trx_commit = 1 

innodb_lock_wait_timeout = 50 

And now fix your permissions on the DATA directory. 

$chown -R mysql:mysql /usr/var 

To start mysql server: 

$mysqld_safe & 

$cp /usr/share/mysql/mysql.server /etc/rc.d/init.d/mysql 

$/etc/rc.d/init.d/mysql start 

To stop mysql server: 

$/etc/rc.d/init.d/mysql stop 

Note:mysql.server is just a wrapper that invokes mysqld_safe, which in turn invokes mysqld.  The advantage of involving mysqld_safe in  this process (as opposed to starting the server directly) is that  if the server crashes, mysqld_safe restarts it. 

To check mqsql is running or not : 

mysqladmin -u root -p ping 

Enter password: (enter) 

output:mysqld is alive 

5) Some basic tips to create data base and test any application.

6) To assign a new ip  to imx board.

    $ ifconfig eth0 <ip address>

Use:We can use any browser to test the application. Open any browser and type:

<ip address>/<projet name>

To run mysql server without any password:

$sudo mysqld_safe --skip-grant-tables &

OR

To change the password of mysql. Follow the below link.

http://www.rackspace.com/knowledge_center/article/mysql-resetting-a-lost-mysql-root-password

To check and create data base.

Login to mysql as root user

$mysql -u root -p

password <enter for nothing or you password>

To show the existing data bases.

mysql>show databases;

To ceate any data base.

mysql>create databases <database name>;

To use any data base.

mysql>use database;

To show the table in selected data base.

mysql>show tables;

To check the content of any tables.

mysql>select * from <table name>;

To dump any data base.

First Login to mysql,create database and the log out.

$mysql -u root -p -h localhost <database name > < /usr/htdocs/<database name>.sql

We use cookies to provide the best possible browsing experience to you. By continuing to use our website, you agree to our Cookie Policy