LAMP Server: Como Instalar Apache + MySQL + PHP (Raspberry PI)

Pre requesitos

Instalar Sistema Operativo

[email protected]:~ $ sudo apt update && sudo apt upgrade -y
image 2
LAMP Server: Como Instalar Apache + MySQL + PHP (Raspberry PI) 5

Instalar Apache2 no Raspberry Pi

[email protected]:~ $ sudo apt install apache2 -y
[email protected]:~ $ cd /var/www/html
[email protected]:/var/www/html $ ls -al
index.html
image 3
LAMP Server: Como Instalar Apache + MySQL + PHP (Raspberry PI) 6

Instalar PHP no Raspberry Pi

[email protected]:/var/www/html $ sudo apt install php -y
image 4
LAMP Server: Como Instalar Apache + MySQL + PHP (Raspberry PI) 7
[email protected]:/var/www/html $ sudo rm index.html
[email protected]:/var/www/html $ sudo nano index.php
[email protected]:/var/www/html $ sudo service apache2 restart

Instalar MySQL (MariaDB Server) no Raspberry Pi

[email protected]:/var/www/html $ sudo apt install mariadb-server php-mysql -y
image 5
LAMP Server: Como Instalar Apache + MySQL + PHP (Raspberry PI) 8
[email protected]:/var/www/html $ sudo mysql_secure_installation
[email protected]:/var/www/html $ sudo mysql --user=root --password
> create user [email protected] identified by 'poplab';
> grant all privileges on *.* to [email protected];
> FLUSH PRIVILEGES;
> exit;

Instalar phpMyAdmin no Raspberry Pi

[email protected]:/var/www/html $ sudo apt install phpmyadmin -y
[email protected]:/var/www/html $ sudo phpenmod mysqli
[email protected]:/var/www/html $ sudo service apache2 restart
[email protected]:/var/www/html $ sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin

Create a virtual server

Apos todos os serviços instalados vamos configurar o Apache para suportar virtual hosts

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    ServerAdmin [email protected]
    DocumentRoot /var/www/example.com/public_html

    <Directory /var/www/example.com/public_html>
        Options -Indexes +FollowSymLinks
        AllowOverride All
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/example.com-error.log
    CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined
</VirtualHost>

Hardening Web Server

[email protected]:~ $ ls -lh /var/www/
[email protected]:~ $ sudo chown -R rfs:www-data /var/www/html/
[email protected]:~ $ sudo chmod -R 770 /var/www/html/
[email protected]:~ $ ls -lh /var/www/
cd /var/www/html/
sudo find . -type f -exec chmod 0644 {} \;
sudo find . -type d -exec chmod 0755 {} \;