So why Nginx and MariaDB ?

Nginx will replace our Apache server. But why ? Short answer is performance. Bit longer answer is that Nginx is Asynchronous server which means it can perform several actions at the same time, without waiting previous to end. Nginx responds faster and consumes less RAM then Apache and this is my main reason for switching to Nginx. There are of course differences. Nginx doesn’t support .htaccess files and sometimes the are differences how Nginx handles PHP.
And MariaDB is drop in replacement to MySQL. MySQL was brought by oracle some time ago and since then the MySQL has problems with including community in development process and distrust from community for having competing products, open source MySQL and proprietary OracleDB. So the original developer of MySQL created a new projects MariaDB and it is fully open source, has strong community and is being actively developed.



Installing Nginx to Raspberry Pi

  1. Run
    sudo aptitude install nginx php5-fpm

    This installs the nginx and faster version of PHP called php-fpm
    https://php-fpm.org/

     

  2. Now lets check the installation
    go to your Raspberry-s IP port 80. You should see following welcome message:
    [S 004]
  3. Next we going to configure the Nginx and php. Lets edit the default file:
    sudo nano /etc/nginx/sites-available/default
  4. Replace Line:
    index index.html index.htm index.nginx-debian.html;

    with

    index index.html index.htm index.php;

    This will add an automatic redirection to the “index.php” files for the site folders, Apache’s default behavior.

  5. Lets activate php-fpm for Nginx. Find following lines in the same file:
    #location ~ \.php$ { 
    # include snippets/fastcgi-php.conf; 
    #
    # # With php5-cgi alone: 
    # fastcgi_pass 127.0.0.1:9000; 
    # # With php5-fpm: 
    # fastcgi_pass unix:/var/run/php5-fpm.sock; 
    #}

    And replace with:

    location ~ \.php$ { 
    include snippets/fastcgi-php.conf;
     fastcgi_pass unix:/var/run/php5-fpm.sock;
    }

    Save and exit file.

  6. Now we going to change the permissions of the necessary folders by running following two commands:
    sudo chown -R www-data:pi /var/www/html/ 
    sudo chmod -R 770 /var/www/html/
  7. Lets create php info file:
    echo "<?php phpinfo(); ?>" > /var/www/html/index.php

     

  8.  For changes to take effect we have to restart the server:
    sudo /etc/init.d/nginx restart
  9. Now check the installation by going to the Raspberry-s IP and you should see php info page:
    [Sel 005]
  10. Done with “THESE 10 SIMPLE STEPS” but Wait there’s MORE:

Installing MariaDB to Raspberry Pi

  1. Run:
    sudo apt-get install mariadb-server
  2. Create root user password when prompted.
  3. DONE.

Installing PhpMyAdmin with Nginx on Raspberry Pi

This is little trickier with nginx but no problem we got this.

  1. Lets install phpmyadmin:
    sudo apt-get install phpmyadmin
  2. During the installation, you will be prompted for some information. It will ask you which web server you would like the software to automatically configure. Since Nginx, the web server we are using, is not one of the available options, you can just hit TAB to bypass this prompt.
  3. The next prompt will ask if you would like dbconfig-common to configure a database for phpmyadmin to use. Select “Yes” to continue.
  4. You will need to enter the database administrative password that you configured during the MySQL installation to allow these changes. Afterward, you will be asked to select and confirm a password for a new database that will hold phpMyAdmin’s own data.
  5. For the Nginx web server to find and serve the phpMyAdmin files correctly, we just need to create a symbolic link from the installation files to our Nginx web root directory by running following command:
    sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin

     

  6. Now we will enable the mcrypt PHP module, which phpMyAdmin relies on. This was installed with phpMyAdmin so we just need to toggle it on and do a restart to PHP:
    sudo php5enmod mcrypt
    sudo service php5-fpm restart

     

  7. DONE. Test your phpmyadmin by logging in  YOUR-RP-IP/phpmyadmin