[KnowledgeBase] Install LAMP

Install & Configure Apache

  • install the apache2 package

    sudo apt-get install apache2
  • edit the config to contain the correct servername in /etc/apache2/apache2.conf

    ServerName your.server.com
  • restart the server to save changes

    sudo systemctl restart apache2
  • Allow http and https traffic in ufw

    sudo ufw allow http https

    Install & Configure MySQL

  • Install the package and then run the secure installation script

    sudo apt-get install mysql-server

Install PHP

  • Install the packages and restart apache after this

    sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql
    sudo systemctl restart apache2
  • If you want to test it, add a phpinfo.phpfile in your webroot containing the following code:


Install PHPMyAdmin

  • Install the package first. In the wizard, fill in the passwords

    sudo apt-get install phpmyadmin
  • In case something goes wrong, you can call the wizard again by running this

    sudo dpkg-reconfigure -plow phpmyadmin
  • next protect the page with .htaccess, edit /etc/phpmyadmin/apache.conf and add the following line: AllowOverride All

    <Directory /usr/share/phpmyadmin>
    Options FollowSymLinks
    DirectoryIndex index.php
    AllowOverride All <---- add this line
  • therefore create the file /usr/share/phpmyadmin/.htaccess and add the following there

    AuthType Basic
    AuthName "Restricted Files"
    AuthUserFile /etc/phpmyadmin/.htpasswd
    Require valid-user
  • setup the htpasswd for it

    sudo htpasswd -c /etc/phpmyadmin/.htpasswd USERNAME
  • finally restart the server

    sudo service apache2 restart