Bullseye Pi OS with Apache, Php and MariaDb
AJA • March 10, 2022
raspberryInstalling Apache, Php and MariaDb on Bullseye Pi OS
Apache
sudo apt install apache2
Change apache /var/www/html owner, group and permissions.
sudo chown -R www-data:www-data /var/www/
sudo chmod -R 775 /var/www/html/
Add current user in www-data group
sudo usermod -a -G www-data pi
Check apache installation with http://localhost/ or http://127.0.0.1/.
Apache verify.
sudo apache2ctl configtest
sudo apache2ctl -S
PHP
sudo apt install php php-mbstring
Check PHP installation
sudo -u www-data touch /var/www/html/index.php
echo "<?php phpinfo ();?>" > /var/www/html/index.php
Mariadb
sudo apt install mariadb-server php-mysql
Configure mysql
sudo mysql --user=root
First delete the default mysql root user and create a new mysql root user, because the default one can only be used with Linux root account, and so not available for the webserver and php scripts.
DROP USER 'root'@'localhost';
CREATE USER 'root'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;
Check mysql installation
sudo mysql -uroot -ppassword
Phpmyadmin
sudo apt install phpmyadmin
During the installation process, select these options:
- Select Apache2 (press space and enter)
- Configure the database for PHPMyAdmin with db-common: No
Check Phpmyadmin with http://localhost/phpmyadmin/.
UFWW
Ufw is a uncomplicated firewall
Warning you need to allow OpenSSH before enabling Ufw.
Allow http and https with 'WWW Full'.
sudo apt-get install ufw
sudo ufw status
sudo ufw allow OpenSSH
sudo ufw allow 'WWW Full'
sudo ufw enable
sudo ufw status
Allow only ssh and https.
sudo ufw delete allow 'WWW Full'
sudo ufw allow 'WWW Secure'
sudo ufw status
Check apache configuration
sudo apache2ctl configtest
sudo apache2ctl -S
sudo apache2ctl restart
Cerbot
Certbot is a free, open source software tool for automatically using Let’s Encrypt certificates on manually-administrated websites to enable HTTPS.
sudo apt install snap
sudo snap install core
sudo snap install certbot --classic
sudo ln -s /snap/bin/certbot /usr/bin/certbot
sudo certbot certonly --apache
sudo a2enmod ssl
sudo systemctl restart apache2
sudo apache2ctl -M
sudo nano /etc/apache2/sites-available/default-ssl.conf
sudo systemctl restart apache2
cd /etc/apache2/sites-enabled/
sudo ln -s ../sites-available/default-ssl.conf
sudo apache2ctl configtest
sudo apache2ctl restart
sudo certbot renew --dry-run
npm rebuild directpry in sties-available