Setting up LAMP Server Basics
In this quick guide we go over setting up a basic LAMP (Linux / Apache / Mysql / PHP) stack which is a primer for all kinds of other features.
- This simple guide is for the Ubuntu system:
- L - Linux A - Apache 2 M - Mysql P - PHP interpreter
- Start with a basic Ubuntu Installation (L)
Step 1: Install Apache 2
sudo apt-get install apache2
systemctl start apache2
- One can see if the port is open by installing nmap and then scanning the localhost
sudo apt-get install nmap -y && nmap localhost
It will show up as:
If your setup is working you should be able to see the apache serving the default page:
Step 2: Add php:
sudo apt install php libapache2-mod-php php-cli php-cgi php-mysql
- We want to test this and make sure that php is fully installed, migrate to /var/www/html/ and create the file phpinfo.php - put inside it:
<?php
phpinfo();
?>
One can then view it with:
http://localhost/phpinfo.php
http://127.0.0.1/phpinfo.php
http://<external ip>.php
- It should be noted here that we are bypassing SSL (http:) and raw polling the address of the server.
- It should show up as:
Step 3: Install mysql (and setup root accesses)
sudo apt-get install mysql-server mysql-client -y
It will automatically install and start up as:
- Note at this point port 3306 will only be visible by the localhost - it will not give an external port mapping.
- Initially if you are root at console inside you can easily access the mysql with:
mysql -u root
Old Method Of Setting up Root for external access (may no longer work)
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'secret' WITH GRANT OPTION;
FLUSH PRIVILEGES;
In Dos * is a wild-card. In Mysql % is a wildcard.
Now do it this way:
CREATE USER 'root'@'%' IDENTIFIED BY 'secret';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
Restart your mysql server:
systemctl restart mysql
If you want mysql to be externally visible to the world:
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
And add the following to it:
bind-address = 0.0.0.0
Summary: You have just completed your basic LAMP stack. From this you can add your applications etc.