LAMP setup notes

Platform: VM on Windows Server 2012 Hypervisor

OS: Ubuntu 18.04 LTS [Download]



sudo apt update

sudo apt upgrade


Install net-tools (ifconfig etc)

sudo apt install net-tools


Configure SSH

sudo apt install openssh-server

sudo systemctl enable ssh

sudo systemctl start ssh

ssh user@server-name


Disable GUI autostart

Should take basic memory usage down from about 2GB to about 320MB

sudo nano /etc/default/grub


sudo update-grub

sudo systemctl enable --force

sudo systemctl set-default

You can undo this with: sudo systemctl set-default

And X can still be started manually with:

startx (quick Gnome)

sudo /etc/init.d/gdm3 start (full Ubuntu)


Install LAMP


Install Tasksel if not already installed

sudo apt install tasksel

Use Tasksel to install the LAMP stack:

sudo tasksel install lamp-server

MySQL extras

sudo apt install mysql-client libmysqlclient-dev

PHP extras

sudo apt install php php-curl php-dev php-gd php-imagick php-ps libapache2-mod-php php-soap php-bz2

sudo systemctl restart apache2



sudo apt install mysql-server mysql-client libmysqlclient-dev


sudo apt-get install apache2 apache2-doc apache2-utils libexpat1 ssl-cert


sudo apt install php libapache2-mod-php php php-common php-curl php-dev php-gd php-pear php-imagick php-mysql php-ps php-xsl libapache2-mod-php php-soap php-bz2

…both options…

sudo systemctl restart apache2

MySQL setup

sudo mysqladmin -u root password newpassword

sudo mysql —user=root

mysql> GRANT ALL PRIVILEGES ON *.* to ‘phpmyadmin’@‘localhost’;

PHP config

sudo nano /etc/php/7.2/apache2/php.ini

Uncomment the following lines: 





Note: If you get some errors like:
PHP Warning: Module ‘sockets’ already loaded in Unknown on line 0

Then comment out modules in relevant files here:



Install PHPMyAdmin

sudo apt install phpmyadmin

Make sure you hit spacebar to select auto configure for apache2 [*] when prompted. If you assume that the highlight means it is selected and hit next without selecting it, then all is not lost: you can go back and re-initialize the phpmyadmin config:

sudo dpkg-reconfigure phpmyadmin

Also note that PHPMyAdmin credentials can be recovered from: /etc/phpmyadmin/config-db.php








I received an error message in PHPMyAdmin when I first tried to run an SQL query:

Warning in ./libraries/sql.lib.php#613  count(): Parameter must be an array or an object that implements Countable

This seemed to fix it:

sudo sed -i "s/|\s*\((count(\$analyzed_sql_results\['select_expr'\]\)/| (\1)/g" /usr/share/phpmyadmin/libraries/sql.lib.php

[Source: Stackoverflow]


Set Timezone

System timezone

sudo timedatectl set-timezone Asia/Riyadh

PHP timezone

sudo nano /etc/php/7.2/apache2/php.ini

sudo nano /etc/php/7.2/cli/php.ini

date.timezone = Asia/Riyadh 

It seems that some programs or scripts don’t support Asia/Riyadh for some reason, so for greater compatibility you could try an alternative GMT+3 timezone such as:

date.timezone = Europe/Moscow 


Install VSFTPD

sudo apt install vsftpd

sudo systemctl status vsftpd

sudo systemctl start vsftpd

sudo nano /etc/vsftpd.conf






sudo add_user newftpuser

Sometimes at this stage I have received the error message:

Authentication Token Manipulation Error

If so, restarting has seemed to fix the problem, after which I needed to run:

sudo passwd newftpuser

echo "newftpuser" | sudo tee -a /etc/vsftpd.user_list

Make the home folder of ftpuser the web directory:

sudo usermod --home /var/www/ newftpuser

And set permissions on /var/www

sudo adduser newftpuser www-data

sudo chown newftpuser:www-data -R /var/www

sudo chmod u=rwX,g=srX,o=rX -R /var/www

Install Composer

php -r "copy('', 'composer-setup.php');"

php -r "if (hash_file('sha384', 'composer-setup.php') === '48e3236262b34d30969dca3c37281b3b4bbe3221bda826ac6a9a62d6444cdb0dcd0615698a5cbe587c3f0fe57a54d8f5') { echo 'Installer verified'; } else { echo 'Installer corrupt';

unlink('composer-setup.php'); } echo PHP_EOL;"

php composer-setup.php

php -r "unlink('composer-setup.php');"

sudo mv composer.phar /usr/local/bin/composer


Leave a Reply