Rasppi-web-mysql
From openmichigan
Revision as of 08:26, 13 August 2013
To install Apache and MySQL, connect to the Raspberry Pi (RPi) either via SSH or as a "console" and issue the following commands:
sudo apt-get install apache2 sudo apt-get install mysql-server #### use same "xxxxxxxx" password sudo /etc/init.d/mysql restart sudo apt-get install php5 php5-mysql
If you do not want your web content and your database content to reside on the SDCard (remember, there is only 4GB of space!), you can use an external USB device if it is USB 2.0 compatible.
If you need a NTFS formatted external drive (which was required when sharing data with a desiginated application), resist the temptation to place the MySQL databases on the NTFS drive because of an endless number of "permissions" issues. Figuring out the magic incantation required to allow MySQL to write to an NTFS formatted drive was ... frustrating, given that DB changes appeared to work until the RPi was re-booted and no changes appeared. The changes were in the runtime "cache" but were never committed to the NTFS disk due to "permissions" issues.
After wrestling this issue for some days, I surrendered and pursued another solution. Given that the MySQL content did not/should not be easily made available on the USB external drive, I decided to partion the USB external drive into 2 logical partitions. It is important that the first partition be the NTFS partition to allow this drive to be usable when used on a Windows system. The second partition would be an EXT3 or EXT4 partition. All non-MySQL content would reside on the NTFS partition, which allows this partition to be used on non-RPi machines to create, copy, edit content (like web pages). All the MySQL content would be placed on the EXT3/EXT4 partition by the RPi, which resolves all the permissions problems.
Since my primary workstation is a Macintosh, I looked for a freeware program that could partition both NTFS and EXTn. I ended up using http://www.easeus.com/partition-manager/, which is a Windows application. I ran this app using my Virtual Box "Windows XP" instance. Given I had no clue to what extent MySQL might be used on the RPi, I partitioned the 128GB USB storage stick into two partitions: ~ 100 GB NTFS, ~28 GB EXT3.
Changes were also required to the /etc/fstab on the RPi to accommodate and mount both of these partitions:
proc /proc proc defaults 0 0 /dev/mmcblk0p1 /boot vfat defaults 0 2 /dev/mmcblk0p2 / ext4 defaults,noatime 0 1 /dev/sda5 /media/ntfs ntfs-3g auto,users,permissions 0 0 /dev/sda6 /media/usb0 ext4 defaults,noatime 0 0 # # a swapfile is not a swap partition, so no using swapon|off from here on, use dphys-swapfile swap[on|off] for that'''
Of course, /var/lib/mysql needs to be moved to /media/usb0 and the "DataDir" parameter in the "my.cnf" file needs to use /media/usb0.
sudo /etc/init.d/mysql stop sudo cp -R -p /var/lib/mysql /media/usb0 sudo vi /etc/mysql/my.cnf #### change "datadir = /var/lib/mysql" to "datadir = /media/usb0/mysql" sudo rm -rf /var/lib/mysql sudo /etc/init.d/mysql start
Now make changes related to the Apache Web Server:
sudo /etc/init.d/apache2 stop sudo cp -R -p /var/www /media/usb0 sudo rm -rf /var/www sudo ln -s /media/usb0/www /var/www sudo /etc/init.d/apache2 start
All the web content and database content will now be on the USB drive. Of course, if you power up the RPi without the USB drive, the web server and the MySQL server will not be available due to the content files missing.