Setting Up Orange Pi PC Plus


Create Bootable Micro SD

On a windows computer download Win32 Disk Imager and SD Card Formatter. First format the card with the quick format option, then use the imager to install a Debian image from here.

Install Image

Turn off the Orange Pi and then insert the Micro SD Card. Boot it up and it should boot to that card. Try username as root and password 1234. Once loaded, type

sudo nand-sata-install

to install the image to the EMMC. It may take some time to transfer it to the Pi's internal storage.

Setup Wifi

Create a backup of the interface file.

sudo cp /etc/network/interface /etc/network/backup_interface

Then open that file.

sudo vim /etc/network/interface

In the file, copy and paste the following code.

auto lo
iface lo inet loopback

# Wired adapter #1
auth eth0
allow-hotplug eth0
iface eth0 inet dhcp

# Wireless adapter #1
allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface homewifi inet dhcp

Then we need to create the wpa_supplicant file.

sudo vim /etc/wpa_supplicant/wpa_supplicant.conf

Copy and paste the following code.

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdv
update_config=1

network={
ssid="wifi_name"
scan_ssid=1
mode=0
proto=WPA2
auth_alg=OPEN
pairwise=CCMP
group=CCMP
key_mgmt=WPA-PSK
psk="wifi_password"
id_str="homewifi"
priority=1
}

Fill in ssid and psk with your own credentials. Save the file. Now lets enable wlan0.

sudo ifup wlan0

Restart the Pi.

sudo reboot

Toggle on off wifi.

ifconfig
sudo ifconfig wlan0 down
sudo ifconfig wlan0 up

Install Git

sudo apt-get install git-core

Get SSH-Key

ssh-keygen -t rsa -b 4096 -C "email@gmail.com"

Install MySQL and NodeJS

Debian Stretch

sudo apt-get install mysql-server default-libmysqlclient-dev nodejs

Ubuntu Xenial

sudo apt-get install mysql-server libmysqlclient-dev nodejs

Updating Xenial Packages

For some reason I had trouble updating my package because the lock file was being strange, so I had to remove it and then do an apt-get update.

sudo rm /var/lib/apt/lists/lock
sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock

I also did an install of Xenial Server and since it gave me a static ip automatically, the IPv-6 was causing my packages not to update so I did the following.

To check if IPv6 is enabled or disabled.

cat /proc/sys/net/ipv6/conf/all/disable_ipv6

0 means it’s enabled and 1 is disabled.

To disable IPv6.

su -
nano /etc/sysctl.conf

Add these lines to sysctl.conf file.

#disable ipv6
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1

Save sysctl.conf file with new config, then reboot your system.

reboot

Check your system again.

cat /proc/sys/net/ipv6/conf/all/disable_ipv6

Now you should see “1″, which means IPv6 has been disabled on your system.

Install RVM

Here's a list of RVM options.

gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
curl -sSL https://get.rvm.io | bash -s stable --ruby
echo 'gem: --no-document' >> ~/.gemrc
rvm install 2.5.0

Follow the steps. You may need to install it with different flags if it's not able to compile it the first time.

Add the following line below to your .bashrc file.

source ~/.rvm/scripts/rvm

Install Rails/Bundler

First install bundler.

gem install bundler

Then install the gems you need in your project.

bundle install

For me, my MySQL socket was located in a different directory. So I had to change my projects path to look for the socket.

# config/database.yml
socket: /run/mysqld/mysqld.sock

For Rails 5.2, I also had to get rid of bootsnap because it can't compile right on Orange Pi's at the moment.

# config/boot.rb
#require 'bootsnap/setup' # Speed up boot time by caching expensive operations.

If you have trouble connecting with the MySQL root user, you may have to reset the password to be blank ("") or give it a password. Here is a work around to skip the grant tables if this is an issue to be able to reset MySQL's root pasword.

sudo /etc/init.d/mysql stop
sudo mysqld_safe --skip-grant-tables &

mysql -u root

# in mysql>
use mysql;
update user set authentication_string=PASSWORD("") where User='root';
update user set plugin="mysql_native_password" where User='root';

flush privileges;
quit;

sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql start
mysql -u root

With version mysql 5.7+ the column password is replaced by authentication_string from the mysql.user table.

I also did not have any error log files or a run directory, so I had to create those for some reason.

sudo mkdir -p /var/run/mysqld
sudo chown mysql:mysql /var/run/mysqld

sudo mkdir /var/log/mysql
sudo touch /var/log/mysql/error.log

Use the command below to find where your sockets are located.

sudo find / -type s

Now start the Rails Server and cross your fingers that everything is fine!

rails s -b 0.0.0.0 -p 3000

If you get this error:

error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'

This error occurs due to multiple installations of mysql. Run the command:

ps -A|grep mysql
#Kill the process by using:

sudo pkill mysql
#and then run command:

ps -A|grep mysqld
#Also Kill this process by running:

sudo pkill mysqld
#Now you are fully set just run the following commands:

service mysql restart
mysql -u root -p

Install Docker

To install Docker, run the following command. Your kernel version must be above 3.10 for Docker to run and compile properly.

sudo apt-get install docker.io

After installing this I got an ip_tables cannot be found in the modules file. After some research, I was able to fix it with just restarting the Pi.

Nginx and Passenger

Let's install Nginx through RVM. I had trouble doing it through installing everything through apt-get, so this was an alright workaround. Passenger install guide here. Run the following steps in order to install Passenger with Nginx module. You'll see the third command is to see if it installed correctly. I installed Nginx to /etc/ instead of /opt/.

gem install passenger --no-rdoc --no-ri
rvmsudo passenger-install-nginx-module
rvmsudo passenger-config validate-install
rvmsudo passenger-memory-stats

Starting and Stopping Nginx. Due to that we installed Nginx through RVM, we can't use the normal:

sudo service nginx restart

We have to kill the pid directly. Luckily the pid is saved by Nginx already and we can call it, and then restart it.

sudo kill $(cat /opt/nginx/logs/nginx.pid)
sudo /etc/nginx/sbin/nginx

Nginx configuration

sudo vim /etc/nginx/conf/nginx.conf

Then paste the configuration lines you need. For me, just a simple http app here.

#/etc/nginx/conf/nginx.conf

include my_app.conf;

In that same directory, create a virtual host called my_app.conf.

# /etc/nginx/conf/my_app.conf

server {
    listen       3000;
    server_name  localhost;
    passenger_enabled on;
    root /home/user/app/public;
}

Let's add some gzip configuration to compress the pages when they are sent to load them faster.

# /etc/nginx/conf/nginx.conf

gzip on;
gzip_disable "msie6";
gzip_proxied any;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

Deploying the app guide here

  • Picture from AliExpress Orange Pi Product Page