Skip to content

Instantly share code, notes, and snippets.



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

Install Apache, Mysql, PHP


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


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


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';

Create sudo user

adduser username
usermod -aG sudo username

Giving file permission

ls -l /var/www
sudo usermod -a -G www-data ec2-user
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

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

Save the file and run:

sudo a2ensite domain
sudo service apache2 restart

Lets encrypt

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