LAMP Stack on an ARM ChromeBook

UPDATE: Please click here for a new, and better, approach to LAMP on your ARM (or really, any) ChromeBook

tl;dr: Skip to the step by step setup instructions.

This article explains how to get a fully functional LAMP stack running on a Samsung ARM-based ChromeBook.  I’m indebted to many, many sources for pieces of what you’ll find below – please see the “References” section below for a complete list of sources used in this post.

Please note that this article is not for those who wish to boot (or dual-boot) a complete linux distribution on their ARM ChromeBook.  For that, see this post about ChrUbuntu.  There’s also this post about using an ARM ChromeBook as a development platform for Go, for those interested in that.

Background

One of my key projects at present is the Annotum project, a scholarly authoring and publishing platform built on WordPress.  Most of my work is done on a PC. I use git to access the Annotum source code repository on GitHub, a local editor to edit php, css, js, and other files (I use notepad++),  ‘office’ applications such as Excel and Word for documentation, and an image editor for logos and the like (I use Photoshop Elements on my PC).

For WordPress and Annotum development on my PC, I use a handy WAMP stack called Server2Go to run local instances of Apache, MySQL, and php; there’s even a packaged version of Annotum called Annotum2Go that I use for testing and local demos.

So, when I got my new ChromeBook a few weeks ago, I was interested to see how capable this small, light, and very inexpensive machine would be for my daily work.  I loved the simplicity of both the hardware and software – it has great battery life, the performance is fast enough not to be noticeable, and the size and weight remind me of a Macbook Air (at around a quarter of the price). The ChromeBook is truly a joy to use in day-to-day web browsing, email, and other lightweight tasks.  But what about as a software development workstation?

ChromeOS allows me to do much of my work out of the box: I can use Google Docs (or Office Web Apps) instead of Word and Excel, and Pixlr Editor for image editing.  With developer mode enabled, I can even open a shell and edit local files using vim (albeit a very limited, minimal version included with ChromeOS).

I looked around for some browser/Chrome Apps that would edit text, but eventually settled on using VIM. VIM has a steep learning curve, but it is ubiquitous on linux systems and worth learning.  However, as I got into the VIM tutorial, I realized that many of the nicer features of VIM (such as visual mode) are not included in the version compiled with ChromeOS.

On other linux distributions, I’d normally use a  package management system such as apt-get, yum, or emerge, to get a more complete version of VIM installed, but ChromeOS does not include any such tool.  I realized that if I could get a package mangement tool up and running, I could probably get not only VIM and git, but also Apache, MySQL, and PHP as well.  So I set out to make this happen.

After a relatively short period of googling, I hit upon this gist, which is really the key to this whole approach.  Rather than re-partitioning the drive and installing an entire OS including the boot/kernel portion, this approach let me keep all the cool ChromeOS stuff, while still accessing my ‘real’ development toolkit at the same time. I can’t thank chrisavl enough for this!

Project Objectives

  • Retain access to ChromeOS features – run the Chrome browser and all other built in tools and features of ChromeOS
  • Run a complete linux distribution, in particular one with a package management system
  • Add development tools such as the full version of VIM, git, etc. Check out, edit, test, and commit code changes both locally and back to GitHub.
  • Install and run a complete apache/mysql/php/smtp stack locally
  • Install and run a local copy of WordPress

Step-by-step setup instructions

1. Set your ChromeBook to developer mode

  • Hold down [esc] and [refresh] and tap the power button. This will bring up the scary ‘recovery’ screen.
  • Press [ctrl+d] to go into developer mode (there’s no prompt – you have to know to do it). Note that all local settings and data will be wiped.
  • After the machine reboots into developer mode, you’ll be at the scary ‘not verified’ startup screen.  Wait 30 seconds for it to boot, or press [ctrl+d] to start immediately.

2. Set up a local arch linux environment

  • Download http://archlinuxarm.org/os/ArchLinuxARM-imx6-latest.tar.gz
  • Press [ctrl+alt+t] to open the crosh shell, then type the following commands:
shell
cd /usr/local
sudo mkdir arch
sudo chown chronos.chronos arch
cd arch
sudo tar xzvf /home/user/*/Downloads/ArchLinuxARM-imx6-latest.tar.gz .
  • Create a script containing the following commands (you can use vi which is already installed).
vi ~/go_to_arch.sh

Put the following commands into your script:

#!/bin/bash
# go_to_arch.sh - switch from ChromeOS to Arch Linux
if uname -a | grep -q SAMSUNG ; then
 echo "Changing Root to Arch Linux"
 sudo cp /etc/resolv.conf /usr/local/arch/etc/resolv.conf
 sudo mount -o bind /dev /usr/local/arch/dev
 sudo mount -t devpts -o rw,nosuid,noexec,relatime,mode=620,gid=5 none /usr/local/arch/dev/pts
# link to the chronos home so it's accessible from arch linux
# (including the Downloads folder)
 sudo mount -o bind /home/chronos/user /usr/local/arch/root

 sudo mount -t proc proc /usr/local/arch/proc
 sudo mount -t sysfs sys /usr/local/arch/sys
 sudo chroot /usr/local/arch /bin/bash
 sudo umount /usr/local/arch/dev/pts
 sudo umount /usr/local/arch/dev
 sudo umount /usr/local/arch/proc
 sudo umount /usr/local/arch/sys
 sudo umount /usr/local/arch/root
else
 # don't change to arch linux if it's already running!
 echo "You're already running `uname -a`"
 exit 0
fi
  • Now you can enter arch linux from the ChromeOS terminal shell by typing
. ~/go_to_arch.sh
  • After you run the script, you’ll be running arch linux, and most importantly you’ll have access to the pacman package installer.
  • To exit arch linux, simply type
exit

to get back to the regular ChromeOS shell.

Note: if you want the home directory to be executable (for example, if you will be compiling programs or writing scripts and storing them there), you will want to add a line like the following to your .bashrc file:

sudo mount -i -o remount,exec /home/chronos/user/

See this gist for a more complete .bashrc example that I use.

3. Install the LAMP stack

Install Apache

Before installing any of the LAMP programs, update the package manager:

pacman -Syu

IMPORTANT: If you get errors running pacman, try enabling a different mirror.

Once the update is complete, we can install Apache:

pacman -S apache

Open up the apache configuration file:

nano /etc/httpd/conf/httpd.conf

Comment out the unique_id_module (you can use ctrl+w to find it quickly in nano):

#LoadModule unique_id_module modules/mod_unique_id.so

Restart Apache:

 /etc/rc.d/httpd restart

Using Chrome (in another tab than the one running the shell), navigate to http://localhost – which should display an (empty) auto-index directory. Add a sample index page:

nano /srv/http/index.html

Include this text (or whatever you’d like):

<html><head><title>Welcome</title></head>
<body><h2>Hello World!</h2>
Welcome to Arch on ChromeBook!
</body></html>

Navigate to http://localhost/index.html to see the new page.

Install MySQL

pacman -S mysql

Start it up

 rc.d start mysqld

Run the MySQL set up script:

 mysql_secure_installation

Press [enter] when asked for the root password (which isn’t set yet), and enter a new root password if desired. After that it’s easiest just to say Yes to all the options. At the end, MySQL will reload and implement the new changes.

Install PHP

pacman -S php php-apache

Add php to the apache configuration file:

nano /etc/httpd/conf/httpd.conf

Paste in this text block within the config.

# Use for PHP 5.x:
LoadModule php5_module modules/libphp5.so
AddHandler php5-script php
Include conf/extra/php5_module.conf

Check the PHP setup with a phpinfo page. Create a new blank file:

 nano /srv/http/info.php

The file should contain:

<?php phpinfo(); ?>

Save and Exit, then restart apache so that all of the changes take effect:

/etc/rc.d/httpd restart

And finally navigate to http://localhost/info.php to see the result.

IMPORTANT: if you will be installing WordPress (see below), you need to install and enable php-gd:

pacman -S php-gd

Update php.ini to enable gd:

nano /etc/php/php.ini

Uncomment the following line:

extension=gd.so

4. Install phpmyadmin and sSMTP

IMPORTANT: this is all wide open and may be insecure.  This configuration is only appropriate for a local dev system that is appropriately firewalled. Use at your own risk, YMMV, etc.

Install phpmyadmin

Install the phpmyadmin and php-mcrypt packages:

pacman -S phpmyadmin php-mcrypt

Configuration Copy the example configuration file to your httpd configuration directory.

cp /etc/webapps/phpmyadmin/apache.example.conf /etc/httpd/conf/extra/httpd-phpmyadmin.conf

Add the following lines to /etc/httpd/conf/httpd.conf:

# phpMyAdmin configuration
Include conf/extra/httpd-phpmyadmin.conf

Adjust access rights. To allow access from any host, edit /etc/webapps/phpmyadmin/.htaccess and change

deny from all

into

allow from all

Note security caveat from above!

Enable mysqli and mcrypt (if you want phpMyAdmin internal authentication) modules:

nano /etc/php/php.ini

Uncomment the following lines:

extension=mysqli.so
extension=mcrypt.so

Install sSMTP

sSMTP is a simple mail transfer agent or MTA – it will send, but not receive mail.  I install it so that my WordPress installation can send mail (Annotum relies on email notifications for some workflow features).

These steps will enable sending mail via a Gmail account using sSMTP

pacman -S ssmtp

 

nano /etc/ssmtp/ssmtp.conf

Comment out everything, and add the following lines (thanks, Tombuntu!):

root=mygmailusername@gmail.com
mailhub=smtp.gmail.com:587
AuthUser=mygmailusername@gmail.com
AuthPass=mypassword
UseSTARTTLS=YES

Test sSMTP by sending a test message:

ssmtp recipient_email@example.com

To: recipient_email@example.com

From: myemailaddress@gmail.com
Subject: test email

hello world!

Note the blank line after the Subject, and finish with a [ctrl+d] to send. Check to see that you received the email.  Note that the from address in the received email can be modified via the instructions found on this page (search for “Change the ‘From’ text”).  Note that there are various other configuration options on that page, but I didn’t find any of them (apart from editing the ssmtp.conf file) to be necessary to get up and running on my ChromeBook.

5. Install and run WordPress

Create a database by navigating to http://localhost/phpmyadmin and logging in with ‘root’ and the password you created for the root user above.  Click on ‘users’, ‘add a user’, name it, click the button to generate a password, and finally check the box to  create a new database with the same name and grant all privileges. Copy the generated password for later use.

Once the db is created, get the latest WordPress:

cd ~
wget http://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz
mv wordpress /srv/http

Navigate to http://localhost/wordpress and follow the prompts, first to create a configuration file, then entering the database information. Use the database and user names you created in phpmyadmin, and ‘localhost’ for the server. Finally, paste in the generated password.

Follow the rest of the WordPress installation, and soon you should be able to log into your new WordPress site on ChromeOS!

If you set up sSMTP correctly, you should also get an email at the address you gave for the admin user.

Note: if you cannot select different image sizes when attaching media to posts (e.g. you only see an option for “Full Size” and no “thumbnail” or “medium”) make sure you have installed and enabled php-gd as described above.

6. (optional) Install other tools using pacman

I use VIM and Git, so I install them with

pacman -S git vim

7. Finishing up

For my implementation, I like to manually start and stop apache and mysql, so I wrote this easy pair of scripts to do that:

#startem.sh - starts Apache and MySQL
rc.d start mysqld
/etc/rc.d/httpd restart

 

#stopem.sh - stops Apache and MySQL
rc.d stop mysqld
/etc/rc.d/httpd stop

References

Many, many thanks to the creators and maintainers of the following resources, without which this page would not exist.

Questions, comments? Please contact me @gcto, comment here, or use the contact form above.

Happy LAMPing!

50 thoughts on “LAMP Stack on an ARM ChromeBook

  1. Thank you so much for this great article! This is what convinced me to go ahead and give Chromebook a try.

    I’m having several issues, though, that no one else seems to be having. I’ll just start with the first one, as the other issues may stem from it.

    When I run go-to-arch.sh, I see bash: sudo: command not found. Then I’m dropped into root@localhost. It appears that the line that is causing the “bash: sudo: command not found” is the chroot line. I typed each line into the command prompt manually, and each line worked until that line, which gave me the same result as running the script.

    I’m literate in unix/linux, but by no means an expert. I hope this question is not out of place.

    Again, thank you so much for this article!

  2. The gist by chrisavl and your own instructions both say to use the ARM imx6-latest. Upon checking out the archlinuxarm.org site they have a different download listed specifically for Chromebooks (ArchLinuxARM-chromebook-latest.img.gz) under the heading of ARMv7 where I’m making the assumption that the earlier imx6 means ARMv6. a) Would using this work? b) Would using this work exactly the same as using the other version? b) If it would work, is there any reason to pick one or the other?

    1. a) Give it a try and see!

      b) I have no idea if it would be the same. Usually later versions work fine, but not always.

      b) (c?) If it would work, I’d use the one that’s chromebook-specific and/or newer.

      It’d be great if you’d give this a try and reply back here.

      1. 1) Forgive my delay, I thought I’d automatically get an email when my comment was replied to so I only just checked this now. Did I just miss a checkbox?

        2) So the Chromebook-specific image is a .img.gz to be written to an SD card or USB3 drive whereas your image is a .tar.gz. I’m inexperienced enough to know neither if one can nor how to go from one to the other. Some quick Googling and trying commands didn’t work, so I’ll have to look into it more later.

      2. Upon simply doing uname -m, evidently imx6 does not mean ARMv6 and it actually is ARMv7. My mistake.

  3. I’ve been trying this, but I can’t seem to get further as step 2.
    I’m running chrome on the Acer C7.

    When I made the go to script, it gives me the message that I’m already running linux. It does execute some of it’s functions but it does not enable me to run pacman and I’m still in the normal shell environment.

    Any idea what I’m missing? the files are all in place in /usr/local/arch/

    1. I found out after reading a bit more carefully, the script is based on the samsung machines, see the str SAMSUNG, change it to something which matches the chromebook, I used 847

  4. I’ve completed the steps up to the point of being able to run the script and enter the Arch Linux chroot environment. I am able to run pacman and other command line utilities, however name resolution is not working. I.e. “ping yahoo.com” results in unknown host yahoo.com. As a result, pacman and other utilities are pretty much useless because they can’t connect to the mirrors to obtain updates and new packages.

  5. Carl,
    Do you know what happens Arch if you move to a different channel (dev/beta) or restore the chromebook with usb?

    Thanks!

  6. Is their a way to install a gui in this thing? I’m relativley new to linux, and liked the idea of having linux in a chrome tab. But when I try to use Allegro, a game library, it does not compile. I think it need the x window system or something.

    1. Definitely have a look at crouton which will get you set up with Unity or another graphical environment. It uses Ubuntu and not Arch Linux, but it is another (and simpler?) way to use chroot to install a linux distribution on a Chromebook.

      1. Thank you so much! I had Chrubuntu running on an sd card but the fact that I can easily switch between crouton and chrome os and not have to reboot made crouton better.

  7. Hi Thank you so much for these instructions works great. One question maybe you can help. I have everything running but in Apache I want “/root/Downloads/ApacheWWW” to be my DocumentRoot but I keep getting the Permission Denied error in localhost. I have tried chmod for the directories but still no go, is there anyway to do this? Basically I want to have a visual file system for the HTML files.

    Thanks Again for the great work.

    1. Ok figured it out, I had to chmod /root to prevent the apache error “Access Denied” when accessing /root/Downloads/ApacheWWW as my Document root, also added “Allow access all” to the conf. Now I can just drag files from GDrive or Flash drive to my ApacheWWW folder and they will execute on the server.

      Thanks again.

  8. Once you have LAMP running, how do you develop? It seems all the IDE’s in the Chrome Store are just links to online stuff. Is there an easy way to type code and save into the appropriate httpd directory without having to be a command line guru?

    1. Personally, I use vim and command-line git for all of my PHP/CSS/JS development, and http://pixlr.com/editor/ for editing images. I’m no guru, but I find that vim, grep, git, and the like are relatively easy to learn and use — help is usually a quick google away.

  9. Dear sir, thanx for that page, as a total noob, i managed to get to the step 2, i’m blocked at : vi ~/go_to_arch.sh

    when i do that i have a column of ~ coming and i can’t figure out how to start typing the script in here.

    Does any of you linux masters have any tips to COPY/PASTE that script into it, or how can i start typing in it , it looks like the main cursor is locked and produces a slight “tilt” sound whenever i try to type something.

    1. vi can be a little tricky to use at first. The main things you need to know are:

      • Type esc, then :q to quit (notice the colon “:”)
      • Type :w to write changes (save)
      • To enter new text, press i to enter ‘insert’ mode.
      • In the bash shell on ChromeOS, in vi, in insert mode, you can press CTRL+SHIFT+V to paste text you copied from the browser.

      You can also just type the commands in go_to_arch.sh manually, get into arch linux, then use pacman to install a simpler editor such as nano that can be a bit easier to use.

      For more on vi/vim, see: http://vim.wikia.com/wiki/Vim_Tips_Wiki

      See:

    1. @Mike – I’m working through a modification of your revised script to get past the “can’t restart crosh” problem once I run Arch and then exit all the way out of all shells and close the terminal tab. Can you shed a little more light on how you are tracking mount/umount and the locks in your script?

      Thanks!

      1. Carl,

        Have you been able to come up with a solution for the issue where you cannot open another crosh tab without rebooting? I tried adapting the linked gist, but it didn’t seem to help me.

          1. Carl,

            I found that the issue had to do with the mounting options for devpts. I changed the line to match the original mounting options, and I am able to open simultaneous crosh/chrooted terminals with no problems.

            sudo mount -t devpts -o rw,nosuid,noexec,relatime,mode=620,gid=5 none /usr/local/arch/dev/pts

            1. Fantastic – works great!! I’ve updated the appropriate line in the original example code.

              Thank you so much for following up and posting back.

  10. Hello again,

    I’m finding a PATH issue that I thought you might have an idea about. For example, the vim text editor is already installed under the ChromeOS “shell”. It’s a minimal version, so I used pacman to install vim (7.3.754) myself. I then noticed that setting $HOME/.vimrc has no effect. I also notice that typing vi instead of vim will still invoke the ChromeOS version. How can I clear things up here? Is it possible to remove the ChromeOS PATH from the archlinux PATH? Is that the right thing to do? Help me sever the chains!

  11. Wow, this is exactly what I was looking for, no need to mess around with partitioning or alsa! When I exit Arch and then try to open a new terminal however, I get the message “Opening crosh process failed. The command crosh completed with exit code 1. Please close this window at your leisure.” It seems like this is an issue of not mounting the ChromeOS filesystem on the exit of this script, but I’m only moderately knowledgable in this area of Linux. What can be done so that a new terminal window can be opened after closing the Arch one?

  12. Thanks again. Now I’m wondering why you don’t call go_to_arch.sh in there too. Do you not always want to run under archlinux?

    Btw. sqlite was needed by mercurial, but I get a 404. Also, after installing clang, running it gives an error as libLLVM-3.2.so can’t be found. It seems like the latter is known anyway; http://archlinuxarm.org/forum/viewtopic.php?t=4832&p=26544.

    One other question: I should mount my SD card as I will certainly run out of space in a few months. (Can’t believe I just upgraded the 40 GB of my broken ASUS 1000 netbook for 16 GB.) Which filesystem systemwould you recommend? Root already seems to be using ext3, but I believe ext4 is supported; also by Google themselves.

    1. Now I’m wondering why you don’t call go_to_arch.sh in there too. Do you not always want to run under archlinux?

      It’s a good question! I actually have the script aliased as go so it’s quick to get into Arch; I suppose one reason is that since I’m still tweaking my settings, it’s nice to be able to exit out to the ChromeOS shell and then go back into Arch.

      As to your SD card question – that’s a bit beyond me. I would choose whatever will work with any other system(s) to which you may need to transfer your SD card.

      Personally, I’m not storing much of anything locally on the ChromeBook – I put most code and work in progress either on Google Drive or on GitHub. I’m also looking at using the FUSE over Amazon to mount some AWS S3 space as local storage.

  13. Thanks. I’ve also had no problem with those messages and am totally chuffed with all this. I can do a lot of C++ and Haskell coding with this. GCC 4.7.2 (the latest release) thanks to pacman. Nice.

    One thing you might help me with: the original chronos home looked a bit messy, so I make a new directory (work) there and thought I’d do everything in there. When I run archlinux I tried
    cd $HOME/work/cpp
    and then compiled hello world using GCC.
    g++ hello.cpp
    This results in the expected a.out, but if I try to execute it, I am am told:
    Permission denied.
    If I don’t do that cd, and just compile hello.cpp in the / directory, the result is executable. Perhaps my new “home from home” should be within /home? I could just
    mkdir myname
    and cd there after I run your script.

    1. My experience is as follows: Within $HOME, I have a directory called local-dev.

      If I cd ~/local-dev and run g++ hello.cpp I also get a.out – which runs fine.

      One piece that may be missing for you is the .bashrc that I run, which you can find in this gist. Note that on line 12 of the .bashrc file, I [re]mount the home directory with

      sudo mount -i -o remount,exec /home/chronos/user/

      . That lets me execute scripts and programs within $HOME, regardless of whether I’m using arch linux or ChromeOS “linux”.

      As an aside, the gist also contains some prompt fun for use with git and a few aliases that I use.

  14. This is very interesting as I’m leaning towards a chromebook for personal LAMP stack development. I’m interested to know how it’s going. Is the 2GB of ram enough to run everything you need for extended amounts of time? How about storage issues? Do you use an external hardrive or usb flash drive? Basically I’m looking for a followup “so I’ve been doing LAMP staack dev on my chromebook and this is how it’s going” Pros and cons kind of thing.

    thanks!

    1. Hi Greg,

      I won’t pretend that I’m doing hard core development by any means, but for my needs – editing php/js/CSS, phpmyadmin, and running and testing WordPress, this setup works really well. Performance is excellent; it feels comparable to a fairly new Thinkpad running win7 and the server2go wamp stack. Git, vim, and other tools are snappy as well. I’d be curious to hear how the ChromeBookArmLAMP performs with larger databases or load, but for me it has been great.

      One real advantage of not dual-booting with another distro is the savings on disk space. I have a good 8gb free even with all the tools and LAMP installed.

      Thanks for the comment,
      -Carl

  15. Amazing. Thankyou. It all works very nicely. I have one question. When running pacman I often get a few warnings such as:

    warning: could not get filesystem information for /mnt/stateful_partition: No such file or directory
    warning: could not get filesystem information for /usr/share/oem: No such file or directory

    Do you have any idea about them?

Leave a Reply to Shaun Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.