Saturday, October 28, 2017

Install Apache and PHP on Ubuntu

[Summarized from Digital Ocean]

Install Apache:

sudo apt-get update
sudo apt-get install apache2
sudo apache2ctl configtest
sudo systemctl restart apache2
sudo ufw status
sudo ufw app list
sudo ufw app info "Apache Full"
sudo ufw allow in "OpenSSH"
sudo ufw allow in "Apache Full"
sudo ufw allow in "Apache"
sudo ufw allow in "Apache Secure"
sudo ufw enable

This will tell you the instance's public IP address so you can test the site:
curl http://icanhazip.com

Install PHP:

sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql

Make PHP handling the default:

sudo vi /etc/apache2/mods-enabled/dir.conf

Change this line:
DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm

To be like this:
DirectoryIndex index.php index.html index.cgi index.pl  index.xhtml index.htm

[We simply moved index.php from the fourth option to the first.]

Restart Apache:
sudo systemctl restart apache2

Check Apache status:
sudo systemctl status apache2

Install command-line interpreter for PHP for easier debugging:

apt-cache show php-cli
sudo apt-get install php-cli

Might as well add perl DBI and CGI modules:

sudo apt-get install libdbi-perl libdbd-mysql-perl libcgi-pm-perl