Uusi asennus ohje OpenWRT LAMP serverille.
Tietokanta ohjelma Mariadb alkoi toimimaan kun lisäsin 1Gt Swap osion muistikortille.
Eli muistikortille tai USB muistille 3 osiota ext4 formaattiin. Swapin ja Extroot osioden koko on maku kysymys, mutta muisti on halpaa joten ei kannata pihistellä.
OpenWRT LAMP Server install
I use WinSCP FTP software to edit files, it is most easier way to handle. You can download it here:
https://winscp.net/
After you have installed WinSCP make new connect, Protocol: SCP, Server: 192.168.1.1, Port 22, User: root, Password: xxxxxxxx, and login.
All command lines root@OpenWrt:~# use SSH (Putty), Download here:
Download PuTTY - a free SSH and telnet client for Windows
After installed Putty make new connect and login.
----------------------------------------------------------------------------------------
First thing to do is partitionig and format (ext4) of USB-stick or SD-card for 3 partitions Extroot, External storage space and Swap.
To do this is simpliest with Linux PC and GParted or you can do it with your router after you have installed fdisk.
root@OpenWrt:~#
opkg update && opkg install fdisk
I use 32Gb SD-Card, 4Gb for Extroot (overlay), 27Gb for Ext. Data storage (mmcblk0p2) and 1Gb for Swap (swap).
root@OpenWrt:~#
block info
/dev/mtdblock5: UUID="68f3c87e-739f36fc-d477c2c5-b8b26e3f" VERSION="4.0" MOUNT="/rom" TYPE="squashfs"
/dev/mtdblock6: TYPE="jffs2"
/dev/mmcblk0p1: UUID="e55d9a28-31c5-4c23-8fe9-ce35f5f6c8f3" VERSION="1.0" MOUNT="/overlay" TYPE="ext4"
/dev/mmcblk0p2: UUID="559d8e50-6f22-4577-b9db-0251f48306b2" VERSION="1.0" MOUNT="/mnt/mmcblk0p2" TYPE="ext4"
/dev/mmcblk0p3: VERSION="1" TYPE="swap"
If you have more than one ext. memory in the router you can suggest running "block info" before.
After inserting the SD-card or USB-stick make note of the changing my "mmcblk0p1" device name match your system.
I use 32Gb sd card with 3 partitions 4Gb "mmcblk0p1" for extroot and 27Gb "mmcblk0p2" data storage as mysql, website and others.
-----------------------------------------------------------------------------------------
Just copy paste one command line at a time text after root@OpenWrt:~#
1. root@OpenWrt:~#
opkg update && opkg install block-mount kmod-fs-ext4 kmod-usb-storage e2fsprogs kmod-usb-ohci kmod-usb-uhci fdisk
2. root@OpenWrt:~#
block info
3. root@OpenWrt:~#
mount /dev/mmcblk0p1 /mnt ; tar -C /overlay -cvf - . | tar -C /mnt -xf - ; umount /mnt
4. root@OpenWrt:~#
block detect > /etc/config/fstab; \
Just copy paste one command line at a time text after >
5. >
sed -i s/option$'\t'enabled$'\t'\'0\'/option$'\t'enabled$'\t'\'1\'/ /etc/config/fstab; \
6. >
sed -i s#/mnt/mmcblk0p1#/overlay# /etc/config/fstab; \
7. >
cat /etc/config/fstab;
8. root@OpenWrt:~#
reboot
After reboot check if you got more space on your router
9. root@OpenWrt:~#
df -h
For me it show following lines:
root@OpenWrt:~# df -h
Filesystem Size Used Available Use% Mounted on
/dev/root 2.5M 2.5M 0 100% /rom
tmpfs 61.0M 372.0K 60.7M 1% /tmp
/dev/mmcblk0p1 3.8G 92.8M 3.5G 3% /overlay
overlayfs:/overlay 3.8G 92.8M 3.5G 3% /
tmpfs 512.0K 0 512.0K 0% /dev
/dev/mmcblk0p2 24.2G 223.4M 22.7G 1% /mnt/mmcblk0p2
/dev/mmcblk0p1 3.8G 92.8M 3.5G 3% /mnt/mmcblk0p1
-----------------------------------------------------------------------------
First edit with your new installed WinSCP: /etc/config/uhttpd
Change port 80 to 85 with this you can login also to LUCI GUI with browser 192.168.1.1:85
list listen_http 0.0.0.0:85
list listen_http [::]:85
-----------------------------------------------------------------------------
Install PHP
root@OpenWrt:~#
opkg update && opkg install php7 php7-cgi php7-cli php7-mod-gd php7-mod-hash php7-mod-json php7-mod-mbstring php7-mod-mysqli php7-mod-opcache php7-mod-pdo php7-mod-pdo-mysql php7-mod-session
Install Lighttpd webserver
root@OpenWrt:~#
opkg install lighttpd lighttpd-mod-cgi
Note! of the changing "mmcblk0p1" or "sda1" device name match your system.
root@OpenWrt:~#
mkdir -p /mnt/mmcblk0p2/data/www
root@OpenWrt:~#
reboot
-----------------------------------------------------
Edit /etc/php.ini
Change doc_root to:
doc_root = "/mnt/mmcblk0p2/data/www"
Add this to end:
[Date]
date.timezone = Europe/Helsinki
------------------------------------------------------
Edit /etc/lighttpd/conf.d/30-cgi
Add line: ".php" => "/usr/bin/php-cgi",
cgi.assign = ( ".pl" => "/usr/bin/perl",
".cgi" => "/usr/bin/perl",
".rb" => "/usr/bin/ruby",
".erb" => "/usr/bin/eruby",
".php" => "/usr/bin/php-cgi",
".py" => "/usr/bin/python" )
------------------------------------------------------
Edit /etc/lighttpd/lighttpd.conf
Change server.document-root to:
server.document-root = "/mnt/mmcblk0p2/data/www"
Uncomment and change server.port to:
server.port = 80
------------------------------------------------------
Create test Webserver & PHP tests
root@OpenWrt:~#
echo "<html><body>Webserver - It's Working!</body></html>" > /mnt/mmcblk0p2/data/www/index.html
root@OpenWrt:~#
/etc/init.d/lighttpd stop
root@OpenWrt:~#
/etc/init.d/lighttpd enable
root@OpenWrt:~#
/etc/init.d/lighttpd start
Test Webserver with browser:
192.168.1.1
root@OpenWrt:~#
mkdir -p /mnt/mmcblk0p2/data/www/php
root@OpenWrt:~#
echo "<?php phpinfo(); ?>" > /mnt/mmcblk0p2/data/www/php/index.php
Test PHP with browser:
192.168.1.1/php
root@OpenWrt:~#
reboot
------------------------------------------------------
Install MariaDB/MySQL
root@OpenWrt:~#
opkg update && opkg install mariadb-server
Note! of the changing "mmcblk0p2" or "sda1" device name match your system.
root@OpenWrt:~#
mkdir -p /mnt/mmcblk0p2/data/mysql
root@OpenWrt:~#
mkdir -p /mnt/mmcblk0p2/data/tmp
root@OpenWrt:~#
chmod 777 /mnt/mmcblk0p2/data/tmp
root@OpenWrt:~#
/etc/init.d/mysqld enable
root@OpenWrt:~#
/etc/init.d/mysqld start
root@OpenWrt:~#
reboot
-------------------------------------------------------
Edit /etc/mysql/my.cnf
Add lines Note! of the changing "mmcblk0p2" or "sda1" device name match your system.
datadir =
/mnt/mmcblk0p2/data/mysql/
tmpdir =
/mnt/mmcblk0p2/data/tmp
Edit /etc/mysql/conf.d/50-server-cnf
Note! of the changing "mmcblk0p2" or "sda1" device name match your system.
datadir = /mnt/mmcblk0p2/data/mysql
# tmpdir should also not go on flash memory
tmpdir = /mnt/mmcblk0p2/data/tmp
------------------------------------------------------------------
root@OpenWrt:~#
mysql_install_db --force --basedir=/usr
Installing MariaDB/MySQL system tables in '/mnt/mmcblk0p2/data/mysql' ...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
To do so, start the server, then issue the following commands:
'/usr/bin/mysqladmin' -u root password 'new-password'
'/usr/bin/mysqladmin' -u root -h OpenWrt password 'new-password'
Alternatively you can run:
'/usr/bin/mysql_secure_installation'
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the MariaDB Knowledgebase at
http://mariadb.com/kb or the
MySQL manual for more instructions.
You can start the MariaDB daemon with:
cd '/usr' ; /usr/bin/mysqld_safe --datadir='/mnt/mmcblk0p2/data/mysql'
You can test the MariaDB daemon with mysql-test-run.pl
cd '/usr/mysql-test' ; perl mysql-test-run.pl
Please report any problems at
http://mariadb.org/jira
The latest information about MariaDB is available at
http://mariadb.org/.
You can find additional information about the MySQL part at:
http://dev.mysql.com
Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/
--------------------------------------------------------------------
root@OpenWrt:~#
opkg update && opkg install mariadb-client mariadb-client-extra
root@OpenWrt:~#
mysqladmin -u root password admin123
root@OpenWrt:~#
mysql -uroot -padmin123
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.2.26-MariaDB Source distribution
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
select version();
+-----------------+
| version() |
+-----------------+
| 10.2.26-MariaDB |
+-----------------+
1 row in set (0.01 sec)
MariaDB [(none)]>
create database testdata;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]>
create user 'testuser'@'localhost' IDENTIFIED BY 'userpass';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]>
GRANT ALL PRIVILEGES ON * . * TO 'testuser'@'localhost';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]>
FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]>>
exit
Bye
------------------------------------------------------------------------
Install phpMyAdmin
root@OpenWrt:~#
opkg install php7-mod-iconv php7-mod-json php7-mod-session php7-mod-zip php7-mod-mbstring zoneinfo-europe
root@OpenWrt:~#
opkg install wget
root@OpenWrt:~#
cd /mnt/mmcblk0p2/data/www
root@OpenWrt:~#
wget https://files.phpmyadmin.net/phpMyAdmin/4.9.2/phpMyAdmin-4.9.2-all-languages.tar.gz
root@OpenWrt:~#
tar zxvf phpMyAdmin-4.9.2-all-languages.tar.gz
root@OpenWrt:~#
rm phpMyAdmin-4.9.2-all-languages.tar.gz
root@OpenWrt:~#
mv phpMyAdmin-4.9.2-all-languages phpmyadmin
--------------------------------------------------------------------
Rename
/mnt/mmcblk0p2/data/www/phpmyadmin/config.inc.php to config.inc_org.php
Make new file
/mnt/mmcblk0p2/data/www/phpmyadmin/config.inc.php
Copy following lines to it and save
<?php
$i = 0;
$i++;
$cfg['Servers'][$i]['verbose'] = 'localhost';
$cfg['Servers'][$i]['host'] = '127.0.0.1';
$cfg['Servers'][$i]['port'] = '3306';
$cfg['Servers'][$i]['socket'] = '';
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'testuser';
$cfg['Servers'][$i]['password'] = 'userpass';
$cfg['DefaultLang'] = 'fi';
$cfg['ServerDefault'] = 1;
$cfg['UploadDir'] = '';
$cfg['SaveDir'] = '';
?>
------------------------------------------------------------------------
Edit /etc/php.ini file, set memory_limit to 24M
memory_limit = 24M
-------------------------------------------------------------------------
Login to phpMyAdmin with browser at
192.168.1.1/phpmyadmin/
-------------------------------------------------------------------------