Setting up a LAMP environment on the Asus EEE
If you fancy using the Asus EEE as a development environment for you web projects then you are in luck. The little machine will quite happily run the entire LAMP stack. LAMP stands for Linux, Apache, PHP and MySQL, which are the operating system, web server, programming language and database components respectively. Being a developer isn't the only reason you might want to install this technology, it also lets you experiment with some interesting software, which I will be exploring in later blog posts.
In addition to the normal LAMP stack, I'll show you how to install two other components that might be useful, the web database front end PHPMyAdmin and the source code control system Subversion, which will allow you to connect to a remote Subversion server, which makes a good backup should anything happen to your EEE. If you haven't got access to a remote Subversion server to back up your source code then have a look here! There is a excellent free online book to help you get started in Subversion (a.k.a. SVN) at: http://svnbook.red-bean.com/.
The LAMP stack is not included in the standard repositories, so you will have to add some more (as we did in an earlier post). Follow the instructions at http://wiki.eeeuser.com/addingxandrosrepos paying particular attention to the section on 'Pinning'. After doing an apt-get update you will be ready to install the software. We can do all of this at once:
apt-get install subversion libapache2-mod-php5 php5-mysql mysql-server \
([EDIT] Note the "\" backslash means continue the command - see comments below. You could run this all on one line - then you would miss out the backslash)
Thanks to the built in dependency system, this will give you everything you need. However, we need to make a couple of manual adjustments to make this work properly. Notice we are installing PHP5 and not PHP4, this is because most of the open source community is upgrading to take advantage of the powerful new features of PHP5 have a look at GoPHP5.org for more information.
So on to our tweaking, the first task is to set a password for the root account on MySQL which is by default blank, so not very secure. You can do this by going to http://localhost/phpmyadmin then selecting 'Privileges'. On the list you will see two entries for root, go ahead and edit their properties to set a password, just don't forget what you set it to! When you were in PHPMyAdmin you might have noticed that the graphics were not working. You may also have noticed that when Apache started up it complained it could not 'could not reliably determine server's fully qualified domain name'. Both of these issues can be fixed by editing the file (as root) /etc/apache2/apache2.conf and adding these two lines to the end:
Now we just need to set up the directory that contains the web files to be accessible by the normal user and to be adaptable to the different web applications you might like to install. A commonly used Apache module is mod_rewrite, this allows applications to change URLS to be more human friendly. To enable it use the command:
sudo a2enmod rewrite
A quick change is needed now to /etc/apache2/sites-available/default and that is to change the line that says AllowOverrides None to AllowOverrides all. This enables applications like Drupal to protect thier system files. The final step to configure the Apache part is to change the web files directory so the normal user can write to it, then you will be able to edit files normally with your favourite text editor. Do this with the command:
sudo chown user /var/www
Restart Apache to get it to pick up the changes:
sudo /etc/init.d/apache2 restart
When you start your computer, Apache and MySQL won't start automatically. This is probably unnecessary and could use up battery life. You can start it with:
sudo /etc/init.d/apache2 start
sudo /etc/init.d/mysql start
Can you guess how would stop it?!
You can always get round having to start each daemon (service) seperately by using a little script, I have this saved to the "bin" directory in my home and it is named "lamp":
# Script to start/stop lamp service
case $1 in
[ -f /var/run/apache2.pid ] || /etc/init.d/apache2 start
[ -f /var/run/mysqld/mysqld.pid ] || /etc/init.d/mysql start
[ -f /var/run/apache2.pid ] && /etc/init.d/apache2 stop
[ -f /var/run/mysqld/mysqld.pid ] && /etc/init.d/mysql stop
Change the script to be executable with:
chmod u+x ~/bin/lamp
Now when you want to start the LAMP stack, just type:
sudo ~/bin/lamp start
sudo ~/bin/lamp stop
Now you are all set up to try out some PHP and MySQL development!