Skip to content

Instantly share code, notes, and snippets.

@poudelmadhav

poudelmadhav/lamp.md

Last active Nov 9, 2020
Embed
What would you like to do?
LAMP Setup in ubuntu

Install Apache, Mysql, PHP

https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-ubuntu-18-04

Apache2

sudo apt install apache2
sudo systemctl enable apache2
sudo service apache2 status
sudo ufw app list
sudo ufw allow in "Apache Full"
sudo a2enmod rewrite

PHP

sudo apt install php php-cli php-fpm php-json php-common php-mysql php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath
sudo apt install php libapache2-mod-php php-mysql

https://computingforgeeks.com/how-to-install-php-on-ubuntu/

MySQL

sudo apt-get install mysql-server
sudo mysql_secure_installation
sudo mysql
SELECT user,authentication_string,plugin,host FROM mysql.user;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
FLUSH PRIVILEGES;
exit

Create sudo user

https://www.digitalocean.com/community/tutorials/how-to-create-a-sudo-user-on-ubuntu-quickstart

adduser username
usermod -aG sudo username

Giving file permission

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/install-LAMP.html

ls -l /var/www
sudo usermod -a -G www-data ec2-user
groups
sudo chown -R ec2-user:www-data /var/www
sudo chmod 2775 /var/www
find /var/www -type d -exec sudo chmod 2775 {} \;
find /var/www -type f -exec sudo chmod 0664 {} \;

Alow rewrite in apache configuration

Allow override all for /etc/apache2/apache2.conf

Create virtual host

Create a file like this as domain.conf

<VirtualHost *:80>   
  ServerAdmin webmaster@localhost
     DocumentRoot /var/www/html/domain
     ServerName domain
     
     <Directory /var/www/html/domain>
        Options +FollowSymlinks
        AllowOverride All
        Require all granted
     </Directory>

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

Save the file and run:

sudo a2ensite domain
sudo service apache2 restart

Lets encrypt

https://www.digitalocean.com/community/tutorials/how-to-secure-apache-with-let-s-encrypt-on-ubuntu-20-04

sudo apt install certbot python3-certbot-apache
sudo certbot --apache
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment