Skip to content

Instantly share code, notes, and snippets.

@erdemarslan
Last active January 25, 2022 23:31
Show Gist options
  • Select an option

  • Save erdemarslan/062213803b20dc64d442d6fcac8d67ba to your computer and use it in GitHub Desktop.

Select an option

Save erdemarslan/062213803b20dc64d442d6fcac8d67ba to your computer and use it in GitHub Desktop.
Install LAMP and Samba Server on Raspberry Pi
# Change default Pi password
sudo passwd pi
# Update and Upgrade Pi
sudo apt-get update -y
sudo apt-get upgrade -y
# Change Servername of Pi
# Change TimeZone
sudo raspi-config
# System Options -> Hostname -> write your hostname
# Localisation Options -> Timezone -> Select your time zone
sudo reboot
# Change Swap Size
# Stop Swap
sudo dphys-swapfile swapoff
# Edit Swap Size on swap file
sudo nano /etc/dphys-swapfile
# Disable CONF_SWAPSIZE and enable CONF_SWAPFACTOR for auto swap size with Pi's RAM
# Generate new swap file
sudo dphys-swapfile setup
# Enable Swap File
sudo dphys-swapfile swapon
# Restart Pi
sudo reboot
# Install Apache2 Server
sudo apt-get install apache2 -y
# Enable mod_rewrite
sudo a2enmod rewrite
# Restart Apache2 service
sudo systemctl restart apache2
# Change www folder. Its optional but i prefered this.
sudo mkdir /home/pi/server
sudo mkdir /home/pi/server/public
sudo chown -R pi:www-data /home/pi/server
sudo chmod -R 770 /home/pi/server
# Edit Apache2 Conf File
sudo nano /etc/apache2/apache2.conf
# Change -> MaxKeepAliveRequests 0
# Change -> <Directory /var/www/> -> <Directory /home/pi/server/public/>
# Change -> AllowOverwrite None -> AllowOverwrite All
# Edit Default Site Conf
sudo nano /etc/apache2/sites-available/000-default.conf
# Change DocumentRoot /var/www/html -> DocumentRoot /home/pi/server/default
# Restart Apache2 Service
sudo service apache2 restart
# Install PHP
sudo apt-get install php php-curl php-gd php-xml php-zip php-mysql php-mbstring -y
# Create index.php file for server root with contains php info
echo "<?php phpinfo(); ?>" > /home/pi/server/public/index.php
# Reload your browser.
# Install Mariadb (MySQL)
sudo apt-get install mariadb-server -y
# MariaDB Configuration
sudo mysql_secure_installation
# Current password is blank. Only press enter
# Switch to unix_socket authentication -> n
# Change root password -> Y
# Remove anonymous user -> Y
# Disallow root login remotely -> n (because we set mysql to remote connection after)
# Remove test database and access to it -> Y
# Reload privilege tables now -> Y
# All done.
# Set MySQL server to remote connection
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
# Edit -> bind-address = 127.0.0.1 -> bind-address = 0.0.0.0
# Connect to MySQL on CLI
sudo mysql -u root -p
# Run this command but change your password on command.
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'your_secret_password' WITH GRANT OPTION;
# It returns -> Query OK
exit
# Restart MySQL service
sudo service mariadb restart
# or
sudo service mysql restart
# I use HeidiSQL on Windows for manage my MySQL databases. Now you can connet your mariadb (mysql) server remotely.
# Install Samba Server
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment