Skip to content

Instantly share code, notes, and snippets.

@rakibulinux
Last active May 20, 2021 17:32
Show Gist options
  • Save rakibulinux/4358a5cbc639875034a9284dbacaabb2 to your computer and use it in GitHub Desktop.
Save rakibulinux/4358a5cbc639875034a9284dbacaabb2 to your computer and use it in GitHub Desktop.
How to Install LAMP Stack on Ubuntu 20.04
#!/bin/bash
#https://youtu.be/KlV77BkVIck
#Install Apache2
sudo apt-get update
sudo apt-get install apache2
sudo systemctl start apache2.service
sudo systemctl enable apache2.service
sudo systemctl restart apache2.service
sudo systemctl stop apache2.service
sudo systemctl start apache2.service
sudo systemctl status apache2.service
apache2 -v
#Uninstall apache
sudo service apache2 stop
sudo apt-get purge apache2 apache2-utils apache2.2-bin apache2-common
sudo rm -rf /etc/apache2
sudo apt-get autoremove
sudo reboot
#If you are reinstalling Apache2 then use this command
#sudo apt-get remove --purge $(dpkg -l apache* | grep ii | awk '{print $2}') && sudo apt-get install apache2
#Install MariaDB
sudo apt install mariadb-server
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service
sudo systemctl restart mariadb.service
sudo systemctl stop mariadb.service
sudo systemctl start mariadb.service
sudo systemctl status mariadb.service
mysql --version
#Secure MariaDB
sudo mysql_secure_installation
#When prompted, answer the questions below by following the guide.
Enter current password for root (enter for none): Just press the Enter
Set root password? [Y/n]: Y
New password: Enter any password
Re-enter new password: Repeat same password
Remove anonymous users? [Y/n]: Y
Disallow root login remotely? [Y/n]: Y
Remove test database and access to it? [Y/n]: Y
Reload privilege tables now? [Y/n]: Y
#Now that MariaDB is installed, to test whether the database server was successfully installed
sudo mysql -u root -p
CREATE DATABASE rakib DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
GRANT ALL ON rakib.* TO 'rakib'@'localhost' IDENTIFIED BY 'R@k!b2@19P@';
FLUSH PRIVILEGES;
EXIT;
# uninstall MariaDB
sudo systemctl stop mariadb.service
sudo apt-get --purge remove "mysql*"
sudo rm -rf /etc/mysql/
sudo updatedb
sudo apt-get autoremove
#Install MySql
sudo apt install mysql-server
sudo systemctl start mysql.service
sudo systemctl enable mysql.service
sudo systemctl restart mysql.service
sudo systemctl stop mysql.service
sudo systemctl start mysql.service
sudo systemctl status mysql.service
mysql --version
# uninstall MySql
sudo systemctl stop mysql.service
sudo apt-get --purge remove "mysql*"
sudo rm -rf /etc/mysql/
sudo updatedb
sudo apt-get autoremove
#Install MongoDB Dependencies
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
sudo add-apt-repository 'deb [arch=amd64] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse'
sudo apt update
sudo apt install mongodb-org
sudo systemctl start mongod
sudo systemctl enable mongod
#Verifying MongoDB Installation
mongo --eval 'db.runCommand({ connectionStatus: 1 })'
#Configuring MongoDB
sudo nano /etc/mongod.conf
security:
authorization: enabled
sudo systemctl restart mongod
mongo
#If you get error Failed global initialization: BadValue Invalid or no user locale set. Please ensure LANG and/or LC_* environment variables are set correctly, try the command:
export LC_ALL=C
mongo
#Switch to the database admin
use admin
db.createUser({user:"admin", pwd:"admin123", roles:[{role:"root", db:"admin"}]})
exit
#Enable MongoDB authentication
sudo nano /lib/systemd/system/mongod.service
#On the 'ExecStart' line 9, add the new option '--auth'.
ExecStart=/usr/bin/mongod --auth --config /etc/mongod.conf
sudo systemctl daemon-reload
sudo service mongod restart
#MongoDB shell with this command
mongo -u admin -p admin123 --authenticationDatabase admin
#Enable external access and configure the UFW Firewall
sudo ufw status
sudo ufw allow ssh
sudo ufw enable
sudo ufw allow from <target> to <destination> port <port number>
sudo ufw allow 27017
sudo ufw status
#and add the IP address of the server in the bind_ip line like this:
sudo nano /etc/mongod.conf
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1,205,175.18.100
#Now save and exit
sudo service mongod restart
#Install PHP
sudo apt install php libapache2-mod-php
php --version
sudo systemctl restart apache2
#Install PHP 7.3 With Modules
sudo apt-get update && apt-get upgrade
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php7.3
#sudo apt-get install php7.3 libapache2-mod-php7.3 libaprutil1-dbd-sqlite3 php7.3-cli php7.3-common php7.3-json php7.3-opcache php7.3-readline
#Install PHP7.3 with PHP Modules
sudo apt-get install php7.3 php-pear php7.3-curl php7.3-dev php7.3-gd php7.3-mbstring php7.3-zip php7.3-mysql php7.3-xml
#Check PHP
sudo nano /var/www/html/phpinfo.php
<?php
phpinfo();
#Save and Exit
Visit: http://localhost/phpinfo.php
#UNInstall PHP
sudo apt-get remove –purge php*
sudo apt-get purge php*
sudo apt-get autoremove
#Install PHPMyAdmin
sudo apt-get install phpmyadmin php-mbstring php-gettext -y
#Make sure to select No
#add this line "Include /etc/phpmyadmin/apache.conf" at /etc/apache2/apache2.conf
#/etc/init.d/apache2 restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment