Champ = CH(romebook) A(pache) M(ySQL) P(hp)
Lamp is pretty popular and a well know term in the Web Developers world, Wamp also exists, and I have used Xampp with pleasure for many years.
But this blog posting is about the real champion: It's about Champ !!!
Ch = Chromebook
a = Apache
m = MySQL
p = PHP
Turn your Chromebook into a low cost Apache/PHP/MySQL development machine, run Apache/PHP/MySQL offline, develop LAMP websites offline.
Ch = Chromebook
a = Apache
m = MySQL
p = PHP
Turn your Chromebook into a low cost Apache/PHP/MySQL development machine, run Apache/PHP/MySQL offline, develop LAMP websites offline.
It started because I wanted to test my own PHP apps with the new PHP 7.0 version that was in in that time in beta stage. I was wondering if I could use my Chromebook for this. YES, that was possible !
( ok ok, the term Champ is technically wrong, I have used Debian in a chroot environment that is setup by Crouton, so it is still Lamp, but the term Champ is just to good not to use it )
Developer mode
First the Chromebook must be put into developer mode, this can be different for the brand Chromebook you have, for me below actions did work.
- Press <esc> + <reload> + <power> at the same time
- Press <ctrl> + d
https://www.chromium.org/chromium-os/poking-around-your-chrome-os-device#TOC-Putting-your-Chrome-OS-Device-into-Developer-Mode
Install Debian through Crouton
Download Crouton at https://goo.gl/fd3zc and then activate it with below actions.
- <ctrl> + <alt> + t
- shell
- sudo sh ~/Downloads/crouton -r jessie -t cli-extra
Please read more about Crouton at below site, it's a great tool !
https://github.com/dnschneid/crouton/blob/master/README.md
Going into Debian on your Chromebook
After installation you can enter Debian on your Chromebook with below actions
- <ctrl> + <alt> + t
- shell
- sudo enter-chroot
Get the source archives
I did use below ones, but for sure those version numbers will soon be old ...
- httpd-2.4.16.tar.gz
- mysql-5.6.26.tar.gz
- php-7.0.0RC3.tar.gz
- phpMyAdmin-4.4.14-all-languages.zip
Setup an build environment
To compile the sources, we need compilers, build tools & libraries. Below packages will give this.
- sudo apt-get install gcc g++ make cmake bison zip libaio-dev libapr1-dev libaprutil1-dev libpcre3-dev libxml2-dev libncurses5-dev libmcrypt-dev tidy libtidy-dev
Compile, install & start Apache
First step, the A from Champ, the Apache webserver
http://localhost
PHP is next.
http://localhost/phpinfo.php
- cd ~
- tar zxvf Downloads/httpd-2.4.16.tar.gz
- cd httpd-2.4.16
- ./configure --with-mpm=prefork
- make
- sudo make instal
- sudo /usr/local/apache2/bin/apachectl start
http://localhost
Compile, install, configure & start PHP
PHP is next.
- cd ~
- tar zxvf Downloads/php-7.0.0RC3.tar.gz
- cd php-7.0.0RC3
- ./configure --with-apxs2=/usr/local/apache2/bin/apxs --enable-mbstring --with-mysqli --with-mcrypt --with-tidy
- make
- sudo make install
- sudo pico /usr/local/apache2/conf/httpd.conf
DirectoryIndex index.htmlAnd change it into
DirectoryIndex index.php index.htmlAnd add below lines just after the loading of the PHP 7 module.
<FilesMatch "\.php">Restart apache with below command
SetHandler application/x-httpd-php
</FilesMatch>
- sudo /usr/local/apache2/bin/apachectl restart
- sudo pico /usr/local/apache2/htdocs/phpinfo.php
<?phpAnd got to below url in Chrome
phpinfo();
?>
http://localhost/phpinfo.php
Compile, setup and start MySQL
This one will take some time
- cd ~
- tar zxvf ~/Downloads/mysql-5.6.26.tar.gz
- cd mysql-5.6.26
- cmake .
- make
- make install
- cd /usr/local/mysql
- sudo chown -R champ:champ .
- ./scripts/mysql_install_db --user=champ
- chown -R root .
This step did also generate the file /champ/my.cnf file, lets edit it a bit, execute below command
- sudo pico /usr/local/mysql/my.cnf
and add below 2 lines under [mysqld]
The second line defines the runtime user the MySQL deamon runs under.
bind-address=127.0.0.1The first line makes sure that only your local Chromebook can access MySQL.
user=champ
The second line defines the runtime user the MySQL deamon runs under.
Starting MySQL
- cd /usr/local/mysql
- sudo ./bin/mysqld_safe &
- cd /usr/local/mysql
- sudo ./bin/mysql_secure_installation
Setup the real website.
Lets make our website, as a start, a single PHP page with "Hello world"
Ok ok, a real linux champ will develop websites in a vt100 terminal with emacs, but wannabies like me will use Chrome OS apps like Caret, or a web edit like Codiac, that's why we put our website in ~/Downloads, so that Chrome OS apps like Caret can see it.
pico ~/Downloads/champ/htdocs/index.php
Put below content in the file.
Ok ok, a real linux champ will develop websites in a vt100 terminal with emacs, but wannabies like me will use Chrome OS apps like Caret, or a web edit like Codiac, that's why we put our website in ~/Downloads, so that Chrome OS apps like Caret can see it.
- chmod 755 ~/Downloads
- mkdir ~/Downloads/champ
- mkdir ~/Downloads/champ/htdocs
pico ~/Downloads/champ/htdocs/index.php
Put below content in the file.
<?php
echo "Hello world";
?>
More Apache configuration
Some more Apache configuration is needed to let Apache use above website and some other little tweeks
- sudo pico /usr/local/apache2/conf/httpd.conf
Listen 127.0.0.1:80Then add below new lines at the end of the httpd.conf file.
User champ
Group champ
ServerName localhost:80
DocumentRoot "/home/champ/Downloads/champ/htdocs"
<Directory /home/champ/Downloads/champ>Restart apache to activate this new configuration
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
- sudo /usr/local/apache2/bin/apachectl restart
phpMyAdmin
Install
- cd ~/Downloads/champ/htdocs
- unzip ~/Downloads/phpMyAdmin-4.4.14-all-languages.zip
- mv phpMyAdmin-4.4.14-all-languages phpMyAdmin
- cd ~/Downloads/champ/htdocs/phpMyAdmin/sql
- /usr/local/mysql/bin/mysql --user=root --password=????? < create_tables.sql
- cd ~/Downloads/champ/htdocs/phpMyAdmin
- mv config.sample.inc.php config.inc.php
- pico config.inc.php
Change below line to something, every value seems to work.
http://localhost/phpMyAdmin
To make standard Linux start scripts, execute below commands.
$cfg['blowfish_secret'] = 'your_biggest_secret';Go to it
http://localhost/phpMyAdmin
Starting and stopping MySQL & Apache/PHP
To make standard Linux start scripts, execute below commands.
- sudo cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
- sudo cp /usr/local/apache2/bin/apachectl /etc/init.d/apache
- sudo service mysql start
- sudo service mysql stop
- sudo service apache start
- sudo service apache stop
- sudo service mysql start
- sudo service apache start
Starting in the background & closing the chrosh tab afterwards
If you do the development with Chrome Apps and/or browser based, then there is no need to keep a crosh chrome tab open all the time.
Add the service start commands to /etc/rc.local as described in the previous paragraph. And then you execute below sequence of statements and afterwards close the crosh tab. The -b option submits the chroot to ghe background and the sleep make sure it never ends.
- <cntrl> <alt> t
- shell
- sudo enter-chroot -b sleep infinity
Automatic starting MySQL & Apache/PHP
For me the previous paragraph is good enough, I don't need Champ every time I use my Chromebook.
However, it is possible to start Champ automatically after you login in your Chromebook. Add below file as champ.conf to /etc/init , note that this is in the ChromeOS file sytem, not the chrooted linux file system.
start on start-user-session
stop on stopping ui or starting halt or starting reboot
script
sudo enter-chroot sleep infinity
end script
!!! HA !!! You could not do this !!! Even the user root is not alowed to make changes to the root filesystem on ChromeOS. I suggest you leave it this way, I'm sure you like it that your Chromebook is a very secure system in the bad bad internet world.
Ok ok, of course you are not going to listen to the my good advice as given in the previous line, on below page you can find a script that will make the root file system on your Chromebook writable.
Poking around your Chrome OS Device
Please see also below page, that page covers in dept making the ChromeOS root file system writable and starting the Chroot environment automatically.
Please see also below page, that page covers in dept making the ChromeOS root file system writable and starting the Chroot environment automatically.
Autostart crouton chroot at ChromeOS startup
If you are going to use above page to autostart your Chroot, then below settings must be done in ~/Downloads/crouton.init to match the setup as given in this blog posting.
If you are going to use above page to autostart your Chroot, then below settings must be done in ~/Downloads/crouton.init to match the setup as given in this blog posting.
CHROOT=jessie
START_DE=enter-chroot
CHROOT_APP=sleep infinity
XMETHOD=default
Geen opmerkingen:
Een reactie posten