Skip to content

Instantly share code, notes, and snippets.

@nawazm92
Last active April 27, 2021 21:31
Show Gist options
  • Save nawazm92/d9ff43266e75483ac54b043a76e9d987 to your computer and use it in GitHub Desktop.
Save nawazm92/d9ff43266e75483ac54b043a76e9d987 to your computer and use it in GitHub Desktop.

Setup LAMP, on AWS EC2 (Ubuntu 18.04)

First step connect to SSH,

ssh -i .pem ubuntu@<PUBLIC-DNS / IP>

Once you're in console you can start by following steps to setup lamp

sudo apt update

sudo apt install -y apache2

(optional) sudo apt install -y curl

(optional) sudo apt install -y composer

sudo apt install -y mysql-server

sudo apt update

Setup PHP (PHP7.2 is available ubuntu 18.04)

sudo apt-get install php -y

sudo apt install -y libapache2-mod-php php-mysql php-xml php-zip

Setup PHPMyAdmin

sudo apt install -y phpmyadmin php-mbstring php-gettext

sudo phpenmod mbstring

Setup root user password

sudo mysql

  • ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'SomePassWord';
  • FLUSH PRIVILEGES;

AWS mysql allow remote access

sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

Change bind-address to 0.0.0.0

bind-address = 0.0.0.0

Restart apache sudo service apache2 restart

Create new mysql user and allow access to that user

mysql -u root -p enter root password if any, if this does not work, just enter sudo mysql

CREATE USER 'aws_dba'@'localhost' IDENTIFIED BY 'SomePassword';

CREATE USER 'aws_dba'@'%' IDENTIFIED BY 'SomePassword';

GRANT ALL ON *.* TO 'aws_dba'@'localhost';

GRANT ALL ON *.* TO 'aws_dba'@'%';

FLUSH PRIVILEGES;

EXIT;

Enabling mod_rewrite

sudo a2enmod rewrite

sudo systemctl restart apache2

Setting Up .htaccess

sudo nano /etc/apache2/sites-available/000-default.conf

Inside that file, you will find a <VirtualHost *:80> block starting on the first line. Inside of that block, add the following new block so your configuration file looks like the following:

<VirtualHost :80>
    ...
    <Directory /var/www/html>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require all granted
    </Directory>
    ...
</VirtualHost>

Finally restart apache

sudo systemctl restart apache2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment