Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Installing lamp on Ubuntu 20.4 LTS

(A little complex article, but works very fine after installing LA of LAMP : https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-ubuntu-18-04)
(Easier article : https://www.tecmint.com/install-lamp-with-phpmyadmin-in-ubuntu-18-04/)

Setting up the L:Linux

we are assuming you are on a linux machine. Although it would be good,if you have an ssh with you and have set up the machine to act as server with one of the firewalls.
More details Here

Setting up the A: Apache

  1. install apache 2
$ sudo apt install apache2
  1. Verify State After the installation process is complete, the apache service should start automatically and will be enabled to start at system boot time. To verify , run this command:
$ sudo systemctl status apache2

If this shows active, then good and proceed to next step. If not, then proceed anyway, step 3 is gonna handle this.

3. start Apache2 service :

$ sudo systemctl start apache2

This will start apache2 server. to verify , goto:

You will be seeing this image:
https://www.tecmint.com/install-lamp-with-phpmyadmin-in-ubuntu-18-04/

Though your server is up and running, it is very important to handle security:

  • stop the apache2 service when you don't need it: $ systemctl stop apache2
  • using a firewall

4. allow the firewall permissions:

$ sudo ufw allow in "Apache Full" 
$ sudo ufw allow 80/tcp
$ sudo ufw allow 443/tcp
$ sudo ufw reload

(note : you can skip 1st line if error occurs)
(note : the server is now PUBLICALLY ACCESSIBLE, BE CAREFUL . If the previous step urls were not working, they would definitely work now


Setting the M :MySQL/Maria DB

1. Install the dependencies:

sudo apt install mariadb-server mariadb-client

2. Verify State: : most of the times it is already running by some software, so it would be better to stop it before running a new instance. check its state via $ sudo systemctl status mysql. if running, stop it via $ sudo systemctl stop mysql

3. setup security password : this is both recommended on digital ocean and techmint article but am skipping it. if you really wanna do so, then first start mysql ($ sudo systemctl start mysql) and then perform some configuration steps via $ sudo mysql_secure_installation command (checkout the article links for more info)

Note: Again. WE SHOULD ALWAYS WORRY ABOUT THE SECURITY and NOT ALLOW ANY UNAUTHORIZED LOGIN. So do apply those security steps in my sql

4. Setting up the P : PHP and PHPmyAdmin

1. installing php: sudo apt install php libapache2-mod-php php-common php-mysql php-gd php-cli

2. verify : by running any of th above localurls/info.php . eg run http:localhost/info.php and this would show up this image :

Again, SECURITY FIRST setup a virtual host @ https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-ubuntu-18-04

3. installing phpmyadmin : $ sudo apt install phpmyadmin. this will ask for a few checks and some passwords if you added before

4. Integrating with apache server: run the commands:

$ sudo cp /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf 
$ sudo a2enconf phpmyadmin
$ sudo systemctl restart apache2

This will enable phpmyadmin . check by calling localhost/phpmyadmin


good read: https://www.tecmint.com/secure-phpmyadmin-centos-ubuntu/

@root-ansh

This comment has been minimized.

Copy link
Owner Author

root-ansh commented May 3, 2020

update : looks like i got locked out from the phpmyadmin because i tried to install it without password. so i guess i do have to create a password with all that security stuff. his way is good.

Good read : https://www.tecmint.com/secure-phpmyadmin-centos-ubuntu/

@root-ansh

This comment has been minimized.

Copy link
Owner Author

root-ansh commented May 3, 2020

@root-ansh

This comment has been minimized.

Copy link
Owner Author

root-ansh commented May 3, 2020

better way to stop mysql :

sudo kill `/var/run/mariadb/mariadb.pid`

@root-ansh

This comment has been minimized.

Copy link
Owner Author

root-ansh commented May 3, 2020

php files can be hosted on local host as http://localhost/myfile.php if they are placed in /var/www/html/myfile.php location

@root-ansh

This comment has been minimized.

Copy link
Owner Author

root-ansh commented May 3, 2020

@root-ansh

This comment has been minimized.

Copy link
Owner Author

root-ansh commented May 3, 2020

all content of the /var/www/html/ folder will be visible on localhost if you simply delete index.html file present there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.