Webserver-tut

 

Host your own website on the raspberry pi? Yes you can!

You will install the following programs:

  • nginx
  • MySQL
  • PHP5-fpm
  • phpMyAdmin
  • ImagIck
  • vsftpd
apt-get update
[enter]
apt-get upgrade
[enter]

Now you are up to date ūüôā

 

Install the mysql server:

sudo apt-get install mysql-server
[ENTER]

You will get a screen for entering the mysql password, enter a long and secure password!

 

sudo apt-get install nginx
[ENTER]
sudo service nginx start
[ENTER]
sudo apt-get install php5-fpm
[ENTER]
sudo apt-get install php5-imagick
[ENTER]
sudo nano /etc/php5/fpm/php.ini

Change the rule “upload_max_filesize = 2M” to

"upload_max_filesize = 10M"

Add this rule at the  Dynamic Extensions section:

extension=imagick.so

Webserver-tut2

Control + X to close/save the file.

sudo apt-get install phpmyadmin
[ENTER]

At the webserver selection screen press “TAB” on your KEYBOARD
[ENTER] Don’t¬†select¬†apache or¬†lighttpd!

If you get the screen if you want db-config, ¬†choose “Yes”.

Webserver-tut3

The following step is entering your MySQL password, and set a password for phpMyAdmin.

Webserver-tut4

 

Done?

sudo service php5-fpm restart
[ENTER]
sudo mkdir /srv/www
[ENTER]
sudo chown -R YOURUSERNAME:www-data /srv/www
[ENTER]
sudo chmod -R 755 /srv/www
[ENTER]
mkdir /srv/www/example.com
[ENTER]
cd /srv/www/example.com
[ENTER]
mkdir logs
[ENTER]
nano logs/access.log (Just make the file, and close it)
[ENTER]
nano logs/error.log (Just make the file, and close it)
[ENTER]
mkdir public

(Change example.com with your own site-name)

sudo nano /etc/nginx/sites-available/example.com
[ENTER]

Add the following info in the file:

 

server {
    server_name example.com 192.168.1.116;
    access_log /srv/www/example.com/logs/access.log;
    error_log /srv/www/example.com/logs/error.log;
    root /srv/www/example.com/public/;
    location / {
        index index.php index.html index.htm;
        try_files $uri $uri/ /index.php?$args;
    }
    location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /srv/www/example.com/public$fastcgi_script_name;
    }
    location /phpmyadmin {
        root /usr/share/;
        index index.php index.html index.htm;
        location ~ ^/phpmyadmin/(.+\.php)$ {
            try_files $uri =404;
            root /usr/share/;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include /etc/nginx/fastcgi_params;
        }
        location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
            root /usr/share/;
        }
    }
    location /phpMyAdmin {
        rewrite ^/* /phpmyadmin last;
    }
}

 

sudo ln -s /etc/nginx/sites-available/yoursitename /etc/nginx/sites-enabled/yoursitename
[ENTER]
sudo service nginx restart
[ENTER]
nano /srv/www/example.com/public/index.php

Add the following:

<?php phpinfo(); ?>

Control + x to close/save the file.

http://YOURRASPBERRYPIIPADRES

Have fun!