Search code examples
magentoraspberry-piphp-7lighttpd

raspberry pi with lighttpd, php7 and magento webshop


I setup my raspberry pi with lighttpd, php7 and magento. Unfortunately after unpack magento to /var/www/html I get an internal server error when open the webinterface setup.

This are the steps I did so far:

  1. put Raspbian Jessie Lite on my Rasberry Pi 3
  2. install lighttpd

    apt install lighttpd -y
    
  3. because PHP 7 is not available in jessie repo I get it from the new stretch repo:

    echo "deb http://httpredir.debian.org/debian stretch main contrib non-free" | tee /etc/apt/sources.list.d/debian-stretch.list
    apt install php7.0 php7.0-fpm -t stretch
    rm /etc/apt/sources.list.d/debian-stretch.list
    apt-get update -y
    
  4. Next we need to enable fastcgi and tell Lighttpd where to find PHP.

    tee /etc/lighttpd/conf-enabled/php.conf > /dev/null <<EOF
    fastcgi.server += (".php" => ((
                     "socket" => "/var/run/php/php7.0-fpm.sock"
    )))
    EOF
    
    lighttpd-enable-mod fastcgi
    lighttpd-enable-mod fastcgi-php
    /etc/init.d/lighttpd force-reload
    
  5. install MySQL and create magento db with one user

    apt-get install mysql-server
    apt-get install mysql-client
    
    mysql -u root -p
    CREATE DATABASE magento;
    CREATE USER magento_user@localhost IDENTIFIED BY 'password';
    GRANT ALL PRIVILEGES ON magento.* TO magento_user@localhost IDENTIFIED BY 'password';
    FLUSH PRIVILEGES;
    exit
    
  6. unpack magento. In winscp I copied the tar.gz file manually into /home/magento

    mkdir /home/magento
    tar xzvf /home/magento/Magento-CE-2.1.6-2017-03-29-01-08-05.tar.gz -C /home/magento
    apt-get install rsync
    sudo rsync -avP /home/magento/. /var/www/html/
    
  7. opening website http://192.168.2.103 raises 500 internal server error.

  8. see error log. I dont even know if these are the right errors...

    cat /var/log/lighttpd/error.log
    
    2017-04-14 12:58:45: (mod_fastcgi.c.2702) FastCGI-stderr: PHP message: PHP Fatal error:  Uncaught Magento\Framework\Exception\FileSystemException: The file "/var/www/html/var/.regenerate" cannot be deleted Warning!unlink(/var/www/html/var/.regenerate): Permission denied in /var/www/html/vendor/magento/framework/Filesystem/Driver/File.php:382
    2017-04-14 12:58:45: (mod_fastcgi.c.2702) FastCGI-stderr: Stack trace:
    2017-04-14 12:58:45: (mod_fastcgi.c.2702) FastCGI-stderr: #0 /var/www/html/vendor/magento/framework/Filesystem/Directory/Write.php(172): Magento\Framework\Filesystem\Driver\File->deleteFile('/var/www/html/v...')
    2017-04-14 12:58:45: (mod_fastcgi.c.2702) FastCGI-stderr: #1 /var/www/html/vendor/magento/framework/Code/GeneratedFiles.php(98): Magento\Framework\Filesystem\Directory\Write->delete('/var/.regenerat...')
    2017-04-14 12:58:45: (mod_fastcgi.c.2702) FastCGI-stderr: #2 /var/www/html/vendor/magento/framework/App/ObjectManagerFactory.php(114): Magento\Framework\Code\GeneratedFiles->cleanGeneratedFiles()
    2017-04-14 12:58:45: (mod_fastcgi.c.2702) FastCGI-stderr: #3 /var/www/html/vendor/magento/framework/App/Bootstrap.php(385): Magento\Framework\App\ObjectManagerFactory->create(Array)
    2017-04-14 12:58:45: (mod_fastcgi.c.2702) FastCGI-stderr: #4 /var/www/html/vendor/magento/framework/App/Bootstrap.php(362): Magento\Framework\App\Bootstrap->initObjectManager()
    2017-04-14 12:58:45: (mod_fastcgi.c.2702) FastCGI-stderr: #5 /var/www/html/vendor/magento/framewor...
    

I followed following tutorials to get so far:

https://blog.dantup.com/2016/03/installing-lighttpd-php7-and-letsencrypt-on-raspberry-pi-raspbian-jessie-lite/

https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-magento-on-ubuntu-14-04


Solution

  • After sitting here for whole day I found a way to get it working.

    I achieved to install following on my raspberry pi 3:

    • lighttpd (version 1.4.35)
    • php7.0 (7.0.16-3)
    • MySQL (Ver 14.14 Distrib 5.7.17, for Linux (armv7l))
    • Magento 2 Webshop (Magento-CE-2.1.5-2017-02-20-05-04-55.zip)

    This are the actions to do:

    1. put Raspbian Jessie Lite on my Rasberry Pi 3
    2. install lighttpd

      apt install lighttpd -y
      
    3. because PHP 7 is not available in jessie repo I get it from the new stretch repo:

      echo "deb http://httpredir.debian.org/debian stretch main contrib non-free" | tee /etc/apt/sources.list.d/debian-stretch.list
      apt install php7.0 php7.0-fpm apt php7.0-xml php7.0-curl php7.0-mcrypt php7.0-intl php7.0-mbstring php7.0-zip php7.0-gd php7.0-mysql -t stretch
      rm /etc/apt/sources.list.d/debian-stretch.list
      apt-get update -y
      
    4. Next we need to enable fastcgi and tell Lighttpd where to find PHP.

      tee /etc/lighttpd/conf-enabled/php.conf > /dev/null <<EOF
      fastcgi.server += (".php" => ((
                       "socket" => "/var/run/php/php7.0-fpm.sock"
      )))
      EOF
      
      lighttpd-enable-mod fastcgi
      lighttpd-enable-mod fastcgi-php
      /etc/init.d/lighttpd force-reload
      
    5. magento needs mysql-5.6 or higher but currently it's not in the raspbian repo. With following code we will install version 5.7:

      wget http://ftp.debian.org/debian/pool/main/m/mysql-5.7/libmysqlclient-dev_5.7.17-1_armhf.deb
      wget http://ftp.debian.org/debian/pool/main/m/mysql-5.7/libmysqlclient20_5.7.17-1_armhf.deb
      wget http://ftp.debian.org/debian/pool/main/m/mysql-5.7/libmysqld-dev_5.7.17-1_armhf.deb
      wget http://ftp.debian.org/debian/pool/main/m/mysql-5.7/mysql-client-5.7_5.7.17-1_armhf.deb
      wget http://ftp.debian.org/debian/pool/main/m/mysql-5.7/mysql-client-core-5.7_5.7.17-1_armhf.deb
      wget http://ftp.debian.org/debian/pool/main/m/mysql-5.7/mysql-server-5.7_5.7.17-1_armhf.deb
      wget http://ftp.debian.org/debian/pool/main/m/mysql-5.7/mysql-server-core-5.7_5.7.17-1_armhf.deb
      wget http://ftp.debian.org/debian/pool/main/m/mecab/libmecab2_0.996-3_armhf.deb
      wget http://ftp.debian.org/debian/pool/main/m/mysql-defaults/mysql-common_5.8+1.0.2_all.deb
      wget http://ftp.debian.org/debian/pool/main/l/lz4/liblz4-1_0.0~r131-2+b1_armhf.deb
      
      sudo apt install libaio1 libaio-dev libhtml-template-perl libevent-core-2.0-5
      
      sudo dpkg -i libmecab2_0.996-3_armhf.deb
      sudo dpkg -i liblz4-1_0.0~r131-2+b1_armhf.deb
      sudo dpkg -i mysql-common_5.8+1.0.2_all.deb
      sudo dpkg -i mysql-client-core-5.7_5.7.17-1_armhf.deb
      sudo dpkg -i mysql-client-5.7_5.7.17-1_armhf.deb
      sudo dpkg -i mysql-server-core-5.7_5.7.17-1_armhf.deb
      sudo dpkg -i mysql-server-5.7_5.7.17-1_armhf.deb
      
      apt-get update -y/
      
    6. create magento db with one user (needed for later magento web installer)

      mysql -u root -p
      CREATE DATABASE magento;
      CREATE USER magento_user@localhost IDENTIFIED BY 'password123';
      GRANT ALL PRIVILEGES ON magento.* TO magento_user@localhost IDENTIFIED BY 'password';
      FLUSH PRIVILEGES;
      exit
      
    7. unpack magento. In winscp I copied the tar.gz file manually into /home/magento

      mkdir /home/magento
      tar xzvf /home/magento/Magento-CE-2.1.6-2017-03-29-01-08-05.tar.gz -C /home/magento
      apt-get install rsync
      sudo rsync -avP /home/magento/. /var/www/html/
      
    8. set permissions (ATTENTION! Do not do this for productiv use! See official site for setting permissions right:)

    http://devdocs.magento.com/guides/v2.0/install-gde/prereq/file-system-perms.html

        chmod -R 777 /var/www/html
    
    1. opening webshop url (enter ip of raspberry pi in webbrowser) and finish the magento web installer.

    For me it was very helpful to open a second putty session and observing the lighttpd error.log to detect errors with following command:

        tail -f /var/log/lighttpd/error.log
    

    Please feel free to give advices to do better or faster.
    Maybe someone can tell me how to fix my mistake with the permissions and set the right ones ;)

    sources:

    https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=162960,

    https://magento.com/tech-resources/download