Install LAMP, FTP and PhpMyAdmin on your Onion Omega



  • DISCLAIMER:
    I'm not responsible if You brick Your Onion following this tutorial. I'm Linux newbie so follow this tutorial on Your own reponsibillity 🙂

    I tested it on 0.0.4 (b220) firmware.

    Hi,
    in this tutorial I'll show you how to install LAMP, FTP and PhpMyAdmin on your Onion Omega. In this tutorial I'll use nano for editing text (yes I'm newbie who deosen't use vi:) and you can install it with:

    opkg update
    opkg install nano
    

    Make Your Onion to boot from USB storage

    Apache as other packages requires a lot of space so first thing You will have to do is to extend your storage. I did this by following this tutorial. To do that you will have to format your USB storage into ext4 filesystem. You can do this by following commands:

    opkg update
    opkg install e2fsprogs
    mkfs.ext4 /dev/<your partition>
    

    (your partition is the same You got from fdisk command in the tutorial above)

    Install SFTP
    To install sftp use opkg install openssh-sftp-server command.

    Install Apache server

    opkg update
    opkg install apache
    

    Then edit httpd.conf:

    nano /etc/apache/httpd.conf
    

    Find Listen part in the file and change it into:

    Listen <ip You use to connect to Your console>:<port number other than 80>
    

    Also find ServerName and change it into:

    ServerName <name for Your server>:<same port as in Listen>
    

    Then you should find:

    LogLevel debug
    

    and change it into

    LogLevel error
    

    To start Apache server You hould execute:

    apachectl start
    

    Address of Your Apache server is : <Onion Console IP adress>:<Your chosen port>

    Install PHP
    Since I had some problems with PhpMyAdmin I installed all this packages for php (all of them are not required but those were that I installed)

    opkg install php5 php5-cgi php5-fastcgi php5-mod-json php5-mod-session php5-mod-zip libsqlite3 zoneinfo-core php5-mod-pdo php5-mod-pdo-sqlite php5-mod-ctype php5-mod-mbstring php5-mod-gd sqlite3-cli php5-mod-sqlite3 php5-mod-curl curl php5-mod-xml php5-mod-simplexml php5-mod-hash php5-mod-dom php5-mod-iconv
    

    Type:

    ln -s /usr/bin/php-cgi /usr/share/cgi-bin/
    

    and then add folowing lines into httpd.conf:

    <Directory "/usr/share/cgi-bin">
        AllowOverride None
        Options FollowSymLinks
        Order allow,deny
        Allow from all
    </Directory>
    
    <Directory "/usr/bin">
        AllowOverride None
        Options none
        Order allow,deny
        Allow from all
    </Directory>
    

    Find ScriptAlias /cgi-bin/ "/usr/share/cgi-bin" and affter that line add ScriptAlias /php/ "/usr/bin" so you should have:

    ScriptAlias /cgi-bin/ "/usr/share/cgi-bin"
    ScriptAlias /php/ "/usr/bin"
    

    Find <IfModule mime_module> section and add AddType application/x-httpd-php .php and Action application/x-httpd-php "/php/php-cgi"' into that section (before </IfModule>)so you should have:

    AddType application/x-httpd-php .php
    Action application/x-httpd-php "/php/php-cgi"
    </IfModule> 
    

    To change Directory Index, change DirectoryIndex index.html to DirectoryIndex index.php index.html.

    Open php.ini:

    nano /etc/php.ini
    

    And uncomment (remove ; ) on lines:

    extension  = gd.so
    extension = mbstring.so
    extension = pdo-mysql.so
    extension = pdo_sqlite.so
    extension = socket.so
    

    Also do not specify doc_root so change doc_root into doc_root =

    After that restart apache server: apachectl restart

    Install mysql

    opkg install mysql-server
    

    Create two folders:

    mkdir /mnt/data/mysql
    mkdir /mnt/data/tmp
    

    Use command:

    mysql_install_db --force
    

    Ok, nex step is to create root user (when I installed mysql, table with users was empty, if that's also Your case use this steps). Execute:

    /usr/bin/mysqld --skip-grant-tables --skip-networking &
    mysql -u root
    use mysql;
    FLUSH PRIVILEGES;
    INSERT into user (Host, User,Password) values ('localhost','root',' ');
    UPDATE user SET Password=PASSWORD('password you want') WHERE User='root';
    
    update user set Select_priv='Y',Insert_priv='Y',Update_priv='Y',Delete_priv='Y',Create_priv='Y',Drop_priv='Y',Reload_priv='Y',Shutdown_priv='Y',Process_priv='Y',File_priv='Y',Grant_priv='Y',References_priv='Y',Index_priv='Y',Alter_priv='Y',Show_db_priv='Y',Super_priv='Y',Create_tmp_table_priv='Y',Lock_tables_priv='Y',Execute_priv='Y',Repl_slave_priv='Y',Repl_client_priv='Y',Create_view_priv='Y',Show_view_priv='Y',Create_routine_priv='Y',Alter_routine_priv='Y',Create_user_priv='Y' where user='root';
    
    FLUSH PRIVILEGES;
    

    To start mysql server you should type:

    /etc/init.d/mysqld start
    

    Install PhpMyAdmin
    To install PhpMyAdmin you should download it from link and extract it to /usr/share/htdocs (Apache server root) and rename root folder of PhpMyAdmin (PhpMyAdmin-4..-allLanguages) to phpmyadmin.
    You should copy the content of config.sample.inc.php to config.inc.php and edit it:

    cp usr/share/htdocs/phpmyadmin/config.sample.inc.php usr/share/htdocs/phpmyadmin/config.inc.php
    nano usr/share/htdocs/phpmyadmin/config.inc.php
    

    Change Authentication type and Servers parameters into:

    $cfg['Servers'][$i]['auth_type'] = 'cookie';
    
    $cfg['Servers'][$i]['host'] = '127.0.0.1';
    $cfg['Servers'][$i]['connect_type'] = 'tcp';
    $cfg['Servers'][$i]['compress'] = false;
    $cfg['Servers'][$i]['extension'] = 'mysql';
    $cfg['Servers'][$i]['AllowNoPassword'] = true;
    

    After that open /usr/share/htdocs/phpmyadmin/libraries/common.inc.php with nano (or whatever You use) and comment following part:

     #if (PMA_MYSQL_INT_VERSION < $cfg['MysqlMinVersion']['internal'] {
        #    PMA_fatalError(
        #        __('You should upgrade to %s %s or later.'),
        #        array('MySQL', $cfg['MysqlMinVersion']['human'])
        #    );
        #}
    

    And that's it:)
    You can access PhpMyAdmin on <Onion Console IP adress>:<Your chosen port>/phpmyadmin

    UPDATE (ty to @Chris-MacKay)
    If you get some permission errors change ScriptAlias /php/ "/usr/bin" to ScriptAlias /php/ "/usr/bin/" in httpd.conf .




  • This post is deleted!


  • @Josip-Mlakar Mind if I post this on our Wiki? 😄



  • @Boken-Lin of course I don't 🙂



  • @Josip-Mlakar Such a nice tutorial. I will modify it a bit to use the pivot-overlay method instead of pivot-root.



  • @Josip-Mlakar Fantastic 🙂
    I have been wanting to be able to use my 32GByte USB drive for some time in order to get more space.
    While I don't need LAMP etc. there were some packages that I wanted that I couldn't install for lack of space.

    However, following the instructions you referenced from https://samhobbs.co.uk/2013/11/more-space-for-packages-with-extroot-on-your-openwrt-router I now have my Omega running entirely from USB without any problems.

    Consequently, I am now able to install jamvm (which I need for a compact Java VM on the Omega) though I did need to use the --force-depends option on opkg because of kernel/repo version mismatches - though it is in fact not causing any problems.

    @Boken-Lin While I don't understand your reference to pivot-overlay vs pivot-root, if it makes an important difference, I will await your updates and re-do the loading on to USB



  • @Kit-Bishop Here's how you setup rootfs with the pivot-overlay method. https://wiki.onion.io/Tutorials/Using-USB-Storage-as-Rootfs. I'm still working on the pivot-root method.



  • @Boken-Lin Thanks - looking at the instructions for pivot-overlay it looks like it would be preferable to pivot-root in that it only puts the /overlay directory on to the USB rather than the whole system.

    While the pivot-root method as referenced by @Josip-Mlakar in https://samhobbs.co.uk/2013/11/more-space-for-packages-with-extroot-on-your-openwrt-router appears to work well, i think I will change to the overlay-root method.

    Will let you know if I hit any problems. And again thanks for the info 🙂



  • @Boken-Lin I have tried following the instructions you give at https://wiki.onion.io/Tutorials/Using-USB-Storage-as-Rootfs for pivot-overlay method.
    I am having a problem.
    When I try the command in Step 3 :

    • mount /dev/sda1 /mnt ; tar -C /overlay -cvf - . | tar -C /mnt -xf - ; umount /mnt

    I get the messages

    • tar: empty archive
      tar: short read

    I think this may be related to the fact that Step 2 said:

    • mount /dev/sda1 /mnt/sda1

    I think there is some issue as to where /dev/sda1 is mounted.
    I am confused - can you clarify please. Thanks.



  • This post is deleted!


  • @Kit-Bishop That's quite strange. Can you try running the commands separately to see if it helps?

    mount /dev/sda1 /mnt
    

    then

    tar -C /overlay -cvf - . | tar -C /mnt -xf -
    

    Finally,

    umount /mnt
    


  • @Boken-Lin I'm having one of those days when nothing seems to go right! 😞
    I have managed to move on a bit. Not sure why, but when I tried the

    mount /dev/sda1 /mnt ; tar -C /overlay -cvf - . | tar -C /mnt -xf - ; umount /mnt
    

    via PuTTY I continued to get the same error. However using MobaXTerm it worked.
    Now, my /mnt/sda1 directory has a copy of my /overlay directory.

    So I proceeded with the subsequent steps:

    block detect > /etc/config/fstab
    

    Edited /etc/config/fstab to set enabled to '1'

    reboot
    

    But nothing seems to have changed on my Omega.
    Sorry to swamp you with lots of information, but after the reboot, I have:

    Output from df -h

    root@Omega-0A97:/# df -h
    Filesystem                Size      Used Available Use% Mounted on
    rootfs                    8.4M    376.0K      8.1M   4% /
    /dev/root                 6.5M      6.5M         0 100% /rom
    tmpfs                    29.9M    456.0K     29.4M   1% /tmp
    /dev/mtdblock3            8.4M    376.0K      8.1M   4% /overlay
    overlayfs:/overlay        8.4M    376.0K      8.1M   4% /
    tmpfs                   512.0K         0    512.0K   0% /dev
    /dev/sda1                29.2G     44.0M     27.7G   0% /mnt/sda1
    root@Omega-0A97:/#
    

    Output from mount

    root@Omega-0A97:/# mount
    rootfs on / type rootfs (rw)
    /dev/root on /rom type squashfs (ro,relatime)
    proc on /proc type proc (rw,nosuid,nodev,noexec,noatime)
    sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,noatime)
    tmpfs on /tmp type tmpfs (rw,nosuid,nodev,noatime)
    /dev/mtdblock3 on /overlay type jffs2 (rw,noatime)
    overlayfs:/overlay on / type overlay (rw,noatime,lowerdir=/,upperdir=/overlay/upper,workdir=/overlay/work)
    tmpfs on /dev type tmpfs (rw,nosuid,relatime,size=512k,mode=755)
    devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,mode=600)
    /dev/sda1 on /mnt/sda1 type ext4 (rw,relatime,data=ordered)
    debugfs on /sys/kernel/debug type debugfs (rw,noatime)
    root@Omega-0A97:/#
    

    Contents of /etc/config/fstab

    root@Omega-0A97:/# cat /etc/config/fstab
    config 'global'
            option  anon_swap       '0'
            option  anon_mount      '0'
            option  auto_swap       '1'
            option  auto_mount      '1'
            option  delay_root      '5'
            option  check_fs        '0'
    
    config 'mount'
            option  target  '/mnt/sda1'
            option  uuid    'cad99fb9-c045-467a-b629-3acd4c170ae3'
            option  enabled '1'
    
    root@Omega-0A97:/#
    

    It looks like my USB is not getting mounted on /overlay.

    Do you see anything wrong? Is there some step I have missed? Is there any other info I can supply that might help?



  • @Josip-Mlakar Wiki article is online: https://wiki.onion.io/Tutorials/How-To-Install-LAMP-Stack-on-the-Omega 🙂 I will put up a separate article for PHPMyAdmin.



  • @Kit-Bishop I think you should change:

    config 'mount'
            option  target  '/mnt/sda1'
            option  uuid    'cad99fb9-c045-467a-b629-3acd4c170ae3'
            option  enabled '1'
    

    from /etc/config/fstab to:

    config 'mount'
            option  target  '/overlay'
            option  uuid    'cad99fb9-c045-467a-b629-3acd4c170ae3'
            option  enabled '1'
    


  • @Boken-Lin cool 😄



  • @Boken-Lin Thanks - had just figured out that something like that was needed - having a slow brain day today 🙂
    That works!
    Perhaps this should be made clearer on the bit on editing /etc/config/fstab in the WiKi page at https://wiki.onion.io/Tutorials/Using-USB-Storage-as-Rootfs



  • @Kit-Bishop Done!



  • @Boken-Lin Cool 🙂 That was quick. Thanks for your help



  • @Boken-Lin ,

    While adapting @Josip-Mlakar 's guide to the Wiki, this step was missed.

    Seems simple enough of a step, but it is assumed the drive is formatted as ext4 in further steps.

    Thanks for both of yours' work!

    @Josip-Mlakar said:

    To do that you will have to format your USB storage into ext4 filesystem. You can do this by following commands:

    opkg update
    opkg install e2fsprogs
    mkfs.ext4 /dev/<your partition>



  • @Chris-MacKay I think I mentioned that somewhere in the prerequisite section.



5 out of 59

Looks like your connection to Community was lost, please wait while we try to reconnect.