LAMP Commands for Ubuntu – Cheatsheet

You might have already installed Ubuntu on your system/server. So you already have L- Linux. Below are the commands you would require to setup others.

Basic

sudo apt-get update
sudo apt-get upgrade

A-Apache

sudo apt-get install apache2
sudo a2enmod ssl
sudo a2enmod vhost_alias
sudo a2enmod rewrite
sudo service apache2 restart

M-MySQL 5.7

sudo apt-get install mysql-server mysql-client

P-PHP 7.1

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php7.1 php7.1-mbstring php7.1-mcrypt php7.1-mysql 
sudo apt-get install php7.1-bcmat php7.1-xml php7.1-curl
sudo apt-get install php7.1-zip php7.1-gd php7.1-intl php7.1-soap php7.1-xmlrpc

Securing Apache

In apache2.conf

ServerSignature Off 
ServerTokens Prod

VHost Setup

We can setup virtual hosts in apache.  In /etc/apache2/sites-available, copy 000-default.conf to xxxhost.local  (Rename this as per your need)

<VirtualHost www.website.com:80>
ServerAdmin root@localhost
DocumentRoot /var/www/website/www_website_com/
ServerName www.website.com
ServerAlias www.website.com
ErrorLog /var/www/website/logs/www.website.com.error_log
CustomLog /var/www/website/logs/www.website.com.access_log common
<Directory /var/www/website/www_website_com/>
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>

Certbot (Lets Encrypt)

Note: Certbot does not work for localhost and IP based servers. A domain name is required.

sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install python-certbot-apache
sudo certbot --apache

FOR ONLY CERT:

sudo certbot --apache certonly

For renewing SSL

sudo certbot renew --dry-run

Put certbot renew <– in cron