Skip to content

Commit

Permalink
tutorials - complete LAMP guides for alpine 3.14 and 3.20 with OSPOS
Browse files Browse the repository at this point in the history
  • Loading branch information
mckaygerhard committed Oct 10, 2024
1 parent 2df7c4a commit c1b981a
Show file tree
Hide file tree
Showing 3 changed files with 567 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tutorials/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ alpine-install-from-usb-to-disk-pc-single-boot-nointernet.md
* Virtualization
* Qemu simple emulation with KVM [alpine-howto-qemu-on-pc.md](alpine-howto-qemu-on-pc.md)
* Libvirt with qemu and KVM with hugepages [alpine-howto-libvirt-qemu-kvm-service.md](alpine-howto-libvirt-qemu-kvm-service.md)
* Complete guides
* Alpine 3.14 + Apache2 + PHP 7 + MySQL + OSPOS4 [server-alpine-LAMP-ospos-314.md](server-alpine-LAMP-ospos-314.md)
* Alpine 3.20 + Apache2 + PHP 8.3 + MySQL + OSPOS3 [server-alpine-LAMP-ospos-320.md](server-alpine-LAMP-ospos-320.md)


## Convention for naming the files:
Expand Down
280 changes: 280 additions & 0 deletions tutorials/server-alpine-LAMP-ospos-314.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,280 @@
# Alpine3.14 + Apache2 + Mysql + Php7 + Ospos3

**Warning** those are for **php 7 (php7) due composer dependencies on alpine 3.14**
if you runs newers use [server-alpine-LAMP-ospos-320.md](server-alpine-LAMP-ospos-320.md)

* [install alpine linux](#install-alpine-linux)
* [0 - Environment](#0---setup-environment)
* [1 - Apache2](#1---apache2)
* [2 - Php](#2---php)
* [3 - DBMS Mysql](#3---databases-mysql)
* [4 - ospos](#4---ospos)
* [How to use this guide](#how-to-use-this-guide)
* [LICENSE](#LICENSE)

This document will not explain anything you must to obey, as must be cos just works and works very well, please if you dont know check [How to use this guide](#how-to-use-this-guide) section before starts:

## Install alpine linux

```
mkdir -p /home/general/VM/alpine314 && cd /home/general/VM/alpine314
qemu-img create -f raw computerint1alpine-vitualdisk1-file.raw 6G
wget -c -t8 --no-check-certificate http://dl-cdn.alpinelinux.org/alpine/v3.14/releases/x86_64/alpine-extended-3.14.0-x86_64.iso
qemu-system-x86_64 -m 2048 -name "computerint1alpine314" \
-cpu host -machine q35 \
-device rtl8139,netdev=nd1 -netdev user,id=nd1,restrict=off,hostfwd=tcp::3222-:22,hostfwd=tcp::9080-:80,hostfwd=tcp::9443-:443 \
-device virtio-keyboard -device virtio-mouse -device virtio-tablet -device virtio-vga,max_outputs=1 \
-drive file=computerint1alpine-vitualdisk1-file.raw,format=raw \
-cdrom alpine-extended-3.14.0-x86_64.iso -boot d
```
* When start it, will ask for root just write "root" and enter to start the command `setup-alpine`

#### the setup-alpine command procedure

* keyboard and variant, example for Latin is es and after then es-winkeys
* hostname: just hit enter, it's the name of the computer, must be only strings.
* Network: select the eth0 one that is the network cable and answer dhcp.
* Network (again): only happends if you have wifi or second card.. must ignore it
* DNS Options: It is recommended to use 8.8.8.8 and none for the domain
* Root: password for the administrative account, take care and dont forgive it
* Timezone: use UTC only for one OS, otherwise America/Panama or something similar
* Proxy Options: Use none if you are connecting directly to the Internet.
* NTP Options: Use chrony the packet already in the medium (extended).
* APK mirror: if you are over slow or no interent, type Skip or none
* User: modern alpine releases allows user creation, skip by typing no
* SSH Options: Use openssh the package that already comes in the medium (extended).
* Root allow: here you must type yes because we do not setup user yet!
* SSH key: just type here none
* Disk Options: Use sda as the entire hard drive present will be used.
* Mode: Select sys to install the system on disk.

Then reboot and if you are using a virtual machine change the line `-boot d` to ` -boot c`

## 0 - Setup environment

```
cat > /etc/apk/repositories << EOF
http://dl-4.alpinelinux.org/alpine/v$(cat /etc/alpine-release | cut -d'.' -f1,2)/main
http://dl-4.alpinelinux.org/alpine/v$(cat /etc/alpine-release | cut -d'.' -f1,2)/community
EOF
apk update
apk add man-pages nano binutils coreutils readline \
sed attr dialog lsof less groff wget curl terminus-font \
file lz4 gawk tree pciutils usbutils lshw tzdata \
zip p7zip xz tar cabextract cpio binutils lha acpi musl-locales musl-locales-lang \
e2fsprogs btrfs-progs exfat-utils f2fs-tools dosfstools xfsprogs jfsutils \
arch-install-scripts util-linux docs
rc-update add consolefont boot
```

## 1 - apache2

```
apk add apache2 apache2-utils apache2-error apache2-proxy-html apache2-proxy
mkdir -p /etc/skel/Devel
mkdir -p /var/www/localhost/cgi-bin /var/www/localhost/htdocs /var/log/apache2
sed -i -r 's#^Listen.*#Listen 80#g' /etc/apache2/httpd.conf
sed -i -r 's#^ServerTokens.*#ServerTokens Minimal#g' /etc/apache2/httpd.conf
chown -R apache:www-data /var/www/localhost/
chown -R apache:wheel /var/log/apache2
sed -i -r 's#.*LoadModule.*modules/mod_cgid.so.*#LoadModule cgid_module modules/mod_cgid.so#g' /etc/apache2/httpd.conf
sed -i -r 's#.*LoadModule.*modules/mod_cgi.so.*#LoadModule cgi_module modules/mod_cgi.so#g' /etc/apache2/httpd.conf
sed -i -r 's#.*LoadModule.*modules/mod_alias.so.*#LoadModule alias_module modules/mod_alias.so#g' /etc/apache2/httpd.conf
sed -i -r 's#.*ScriptAlias /cgi-bin/.*# ScriptAlias /cgi-bin/ "/var/www/localhost/cgi-bin"#g' /etc/apache2/httpd.conf
sed -i -r 's#.*LoadModule.*modules/mod_usertrack.so.*#LoadModule usertrack_module modules/mod_usertrack.so#g' /etc/apache2/httpd.conf
sed -i -r 's#.*LoadModule.*modules/mod_userdir.so.*#LoadModule userdir_module modules/mod_userdir.so#g' /etc/apache2/httpd.conf
sed -i -r 's#public_html#Devel#g' /etc/apache2/conf.d/userdir.conf
sed -i -r 's#AllowOverride.*#AllowOverride All#g' /etc/apache2/conf.d/userdir.conf
sed -i -r 's#/usr/lib/libxml2.so.*#/usr/lib/libxml2.so.2#g' /etc/apache2/conf.d/proxy-html.conf
rc-update add apache2 default
rc-service apache2 restart
echo "it works" > /var/www/localhost/htdocs/index.html
for i in /home/*; do mkdir $i/Devel ; done
```

For testing open a browser and go to `http://<webserveripaddres>` but for secure way or SSL support:
https://venenux.github.io/alpine-wiki/#/tutorials/server-alpine-LAMP-professional-fast-forward

## 2 - PHP

```
apk add php7-opcache php7-openssl php7-json php7-bcmath php7-mbstring php7-bz2 \
php7-ctype php7-dev php7-dom php7-enchant php7-fileinfo php7-shmop php7-simplexml php7-tidy \
php7-tokenizer php7-sysvmsg php7-sysvsem php7-sysvshm php7-xml php7-xmlreader \
php7-xmlwriter php7-xsl php7-zip php7-intl php7-gettext php7-pspell php7-calendar \
php7-exif php7-gd php7-pcntl php7-gmp php7-imap php7-session php7-curl php7-pear \
php7-phar php7-doc php7-embed php7-posix php7-fpm php7-cgi php7-dba php7-mysqli \
php7-mysqlnd php7-odbc php7-pgsql php7-sodium php7-sqlite3 php7-apache2 \
php7-pdo php7-pdo_dblib php7-pdo_mysql php7-pdo_odbc php7-pdo_pgsql php7-pdo_sqlite
sed -i -r 's|.*cgi.fix_pathinfo=.*|cgi.fix_pathinfo=1|g' /etc/php*/php.ini
sed -i -r 's#.*safe_mode =.*#safe_mode = Off#g' /etc/php*/php.ini
sed -i -r 's#.*expose_php =.*#expose_php = Off#g' /etc/php*/php.ini
sed -i -r 's#memory_limit =.*#memory_limit = 536M#g' /etc/php*/php.ini
sed -i -r 's#upload_max_filesize =.*#upload_max_filesize = 128M#g' /etc/php*/php.ini
sed -i -r 's#post_max_size =.*#post_max_size = 256M#g' /etc/php*/php.ini
sed -i -r 's#^file_uploads =.*#file_uploads = On#g' /etc/php*/php.ini
sed -i -r 's#^max_file_uploads =.*#max_file_uploads = 12#g' /etc/php*/php.ini
sed -i -r 's#^allow_url_fopen = .*#allow_url_fopen = On#g' /etc/php*/php.ini
sed -i -r 's#^.default_charset =.*#default_charset = "UTF-8"#g' /etc/php*/php.ini
sed -i -r 's#^.max_execution_time =.*#max_execution_time = 150#g' /etc/php*/php.ini
sed -i -r 's#^max_input_time =.*#max_input_time = 90#g' /etc/php*/php.ini
mkdir -p /var/run/php-fpm7/
sed -i -r 's|^.*listen.owner = .*|listen.owner = apache|g' /etc/php*/php-fpm.d/www.conf
sed -i -r 's|^.*listen.group = .*|listen.group = www-data|g' /etc/php*/php-fpm.d/www.conf
sed -i -r 's|^.*listen.mode = .*|listen.mode = 0660|g' /etc/php*/php-fpm.d/www.conf
chown apache:www-data /var/run/php-fpm7
sed -i -r 's|^.*listen =.*|listen = /run/php-fpm7/php-fpm.sock|g' /etc/php7/php-fpm.d/www.conf
sed -i -r 's|^pid =.*|pid = /run/php-php7/php-fpm.pid|g' /etc/php7/php-fpm.conf
rc-update add php-fpm7
rc-service php-fpm7 restart
sed -i -r 's|.*LoadModule.*modules/mod_mpm_event.so.*|LoadModule mpm_event_module modules/mod_mpm_event.so|g' /etc/apache2/httpd.conf
sed -i -r 's|.*LoadModule.*modules/mod_mpm_prefork.so.*|#LoadModule mpm_prefork_module modules/mod_mpm_prefork.so|g' /etc/apache2/httpd.conf
rm /etc/apache2/conf.d/php*.conf
cat >> /etc/apache2/conf.d/php7-fpm.conf << EOF
<FilesMatch \\.php\$>
<If "-f %{REQUEST_FILENAME}">
SetHandler "proxy:unix:/run/php-fpm7/php-fpm.sock|fcgi://localhost"
</If>
</FilesMatch>
EOF
rc-update add apache2
rc-service apache2 restart
echo -e "<?php\nphpinfo( );\n?>" > /var/www/localhost/htdocs/index.php
```

## 3 - Databases mysql

```
apk add mysql mysql-client mariadb-doc mariadb-server-utils mariadb-mytop
mysql_install_db --user=mysql --datadir=/var/lib/mysql
sed -i "s|.*max_allowed_packet\s*=.*|max_allowed_packet = 100M|g" /etc/mysql/my.cnf
sed -i "s|.*max_allowed_packet\s*=.*|max_allowed_packet = 100M|g" /etc/my.cnf.d/mariadb-server.cnf
sed -i "s|.*bind-address\s*=.*|bind-address=0.0.0.0|g" /etc/mysql/my.cnf
sed -i "s|.*bind-address\s*=.*|bind-address=0.0.0.0|g" /etc/my.cnf.d/mariadb-server.cnf
sed -i "s|.*skip-networking.*|#skip-networking|g" /etc/mysql/my.cnf
sed -i "s|.*skip-networking.*|#skip-networking|g" /etc/my.cnf.d/mariadb-server.cnf
rc-update add mariadb
rc-service mariadb restart
mysqladmin -u root password root
mkdir -p /usr/share/webapps/adminer && wget https://github.com/vrana/adminer/releases/download/v4.8.1/adminer-4.8.1.php -O /usr/share/webapps/adminer/adminer-4.8.1.php
ln -s adminer-4.8.1.php /usr/share/webapps/adminer/index.php
cat >> /etc/apache2/conf.d/adminer.conf << EOF
Alias /adminer /usr/share/webapps/adminer/
<Directory /usr/share/webapps/adminer/>
Require all granted
DirectoryIndex index.php
</Directory>
EOF
rc-service apache2 restart
```

## 4 - ospos

```
apk add doas bash shadow shadow-uidmap doas musl-locales musl-locales-lang
cat > /etc/doas.conf << EOF
permit nopass general as root cmd apk
EOF
useradd -m -U -c "" -s /bin/bash -G wheel,input,disk,floppy,cdrom,dialout,audio,video,lp,netdev,games,users,ping,wheel general
for u in $(ls /home); do for g in disk lp floppy audio cdrom dialout video lp netdev games users ping wheel; do addgroup $u $g; done;done
echo "general:general" | chpasswd
```

Now everithing will be using "general" user, so RUNS "su -l general" OR LOGIN WITH general USER!

```
doas apk add git git-doc nodejs nodejs-doc npm npm-doc
mkdir -p /home/general/Devel/opensourcepos && cd Devel/opensourcepos
wget https://github.com/opensourcepos/opensourcepos/releases/download/3.3.9/opensourcepos.3.3.9.c00ff2.zip
unzip opensourcepos.3.3.9.c00ff2.zip
mysql -u root -proot -e "CREATE SCHEMA ospos;"
mysql -u root -proot -e "CREATE USER 'admin'@'%' IDENTIFIED BY 'pointofsale';GRANT ALL PRIVILEGES ON ospos . * TO 'admin'@'%' IDENTIFIED BY 'pointofsale' WITH GRANT OPTION;FLUSH PRIVILEGES;"
mysql -u root -proot -e "CREATE USER 'admin'@'localhost' IDENTIFIED BY 'pointofsale';GRANT ALL PRIVILEGES ON ospos . * TO 'admin'@'localhost' IDENTIFIED BY 'pointofsale' WITH GRANT OPTION;FLUSH PRIVILEGES;"
mysql -u admin -ppointofsale -D ospos < database/database.sql
chown -R general:www-data /home/general/Devel/opensourcepos
rm -f /home/general/Devel/opensourcepos/.htaccess
rm -f /home/general/Devel/opensourcepos/public/.htaccess
cat > /home/general/Devel/opensourcepos/index.php << EOF
<?php
header('Location: public/index.php', true, 301);
die();
?>
EOF
```

Edit `/home/general/Devel/opensourcepos/application/config/config.php` and set `$config['index_page'] = '';` to `$config['index_page'] = 'index.php';`

#### Results

* OSPOS: `http://<ip>/~general/opensourcepos/`
* MYSQL: `http://<ip>/adminer/`
* FILES: `/home/general/Devel/opensourcepos/`

## How to use this guide

This guide **structure all the commands in blocks, each block its separated by a line spaced**,
so you must **type each line as is.. and hit enter**, so you noted that then you
typed each separated clocks of commands, copy/type only blocks separated by an empty line,
all new(next) lines are made by just enter. the terminal will detect if must execute or not.

This guide is for install process, many parts will need you understand minimal
knowledge of linux.

This guide assumed you have a serial port allowed in the targeted computer, also
its important you shuold understand the way of the configuration in this guide.

> **Warning** Some Linux or/and Mac terminals have security cut/paste locks, so
if you paste, the first line will be preceded by garbage, check always the first char of your paste.

## see also

- 🗯 IRC
- 💬 `##alpine_telegram_english`
- 💬 `#alpine_linux_english`
- 📱 Telegram https://t.me/alpine_linux
- 🇬🇧 https://t.me/alpine_linux_english
- 🇷🇺 https://t.me/alpine_linux_pycckuu (dual english russian, low activity)
- 🇨🇴 https://t.me/alpine_linux_espanol
- 🇧🇬 https://t.me/alpine_linux_bulgarian (dual english bulgarian, low activity)
- 🇨🇳 https://t.me/alpine_linux_chinese (dual english chinese, low activity)
- 📡 https://t.me/opentechnologies (open languajes but english as main)
- Matrix
- 👥 https://matrix.to/#/#alpine-linux-english:matrix.org

# LICENSE

**CC BY-NC-SA**: the project allows reusers to distribute, remix, adapt, and build upon the material
in any medium or format for noncommercial purposes only, and only so long as attribution is given
to the creators involved. If you remix, adapt, or build upon the material, you must license the modified
material under identical terms, includes the following elements:

* **BY** – Credit must be given to the creator of each content respectivelly, starting at the first contributor.
* **NC** – Only noncommercial uses of the work are permitted, with exceptions if you fill an issue here!
* **SA** – Adaptations must be shared under the same terms, you must obey this terms and do not change it.

For more information check the [[alpine/copyright.md](../../alpine/copyright.md)](https://venenux.github.io/alpine-wiki/#/alpine/copyright)
Loading

0 comments on commit c1b981a

Please sign in to comment.