Command Line

Setup: PHP

2018-12-30 08:00 CST
2020-03-26 19:16 CST
[![Creative Commons License](](

Set up VM

sudo apt update
adduser newuser
usermod -aG sudo newuser
sudo nano /etc/ssh/sshd\_config
# change PasswordAuthentication from no to yes (Afterwards you can change it back)
sudo systemctl restart sshd
ssh-keygen -f .ssh/id\_rsa\_new # local
ssh-copy-id newuser@server #local, and edit .ssh/config
sudo apt install curl git unzip build-essential

Set up Apache

sudo apt install apache2
sudo apache2ctl configtest
sudo nano /etc/apache2/apache2.conf
# change ServerName -domain-
sudo apache2ctl configtest
sudo systemctl restart apache2
#sudo ufw app list
#sudo ufw app info "Apache Full"
#sudo ufw allow in "Apache Full"

Set up Apache Virtual Hosts

sudo mkdir -p /var/www/
sudo mkdir -p /var/www/
sudo chown -R $USER:$USER /var/www/
sudo chown -R $USER:$USER /var/www/
sudo chmod -R 755 /var/www
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/
# change ServerAdmin,DocumentRoot, add ServerName, ServaerAlias
sudo a2ensite
sudo a2ensite
sudo a2dissite 000-default.conf
sudo systemctl restart apache2

Set up TLS/SSL certificate

sudo add-apt-repository ppa:certbot/certbot
sudo apt update
sudo apt install python-certbot-apache
sudo certbot --apache -d -d
# sudo certbot renew --dry-run

Set up MySQL

sudo apt-get install mysql-server

Set up PHP

sudo apt-get install php libapache2-mod-php  php-mysql
sudo nano /etc/apache2/mods-enabled/dir.conf
# change the position
sudo systemctl restart apache2
# sudo systemctl status apache2

Set up phpMyadmin

sudo apt install phpmyadmin php-mbstring php-gettext php-cli
sudo phpenmod mbstring
sudo systemctl restart apache2
sudo mysql
# mysql> SELECT user,authentication\_string,plugin,host FROM mysql.user;
# ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql\_native\_password BY 'password';
# Above Enable root to log in
# CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
# Above create a new user
sudo ln -s /usr/share/phpmyadmin /var/www/domain/

Set up Composer

curl -sS -o composer-setup.php
export HASH=# SHA value from
php -r "if (hash\_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP\_EOL;"
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer

To use Composer:

  • Search on packagist
  • composer require vendor/package
  • Or add in composer.json and run composer install
  • in php file, require vendor/autoload.php

Use PHPmailer

See following tutorials: