LAMP stack is a set of open sources software which can be installed on your computer to make your computer a web server.
LAMP is an Acronym of Linux operating system, Apache web server, MySQL database, Php programming language.
In this tutorial, you’ll install lamp using Tasksel on Ubuntu. Tasksel is a Debian/Ubuntu based command line utility which can be used to install a group of packages in linux.
Tasksel is a debian based package and can only be installed on Debian based distro such as Ubuntu linux.
- Launch a server in any cloud provider. If you would like to try Amazon web services( AWS) free tier for one year, you can follow this guide to launch a server. Launch EC2 Instance in AWS Step by step
- If you would like to have a server from a managed cloud hosting provider, you can use Cloudways. Using Cloudways, you can create servers from leading cloud providers like AWS, DigitalOcean, Vultr, Linode, Google Cloud.
- Have root user access or a user account with SUDO Privileges.
Step 1 – Updating Packages Repository
In this step, first you’ll update the package repository of Ubuntu. It’ll help you to get the latest version of the installed packages.
apt update command is used to perform the update of the package repository. Use the below command to update the packages.
sudo apt update
Now, your packages are updated. You’ll now install Tasksel to handle other package installations.
Step 2 – Installing Tasksel
In this step, you’ll install Tasksel and all its dependencies.
Use the apt install command to install Tasksel with its dependencies.
sudo apt install tasksel
Now, you’ll use the Tasksel to install the LAMP Stack.
Step 2 – Installing LAMP Using Tasksel
In this step, you’ll install LAMP stack using Tasksel.
Use the Tasksel install to install the LAMP package to your server.
sudo tasksel install lamp-server
You’ll have the lamp package installed in your server with the basic setup. You’ll need to secure the MYSQL installation to make your database secure.
Step 3 – Securing Mysql Installation
Mysql is installed without any password for the root user during the installation. Anybody can access your database since it doesn’t have a password authentication. This will make your database vulnerable to the attacks.
Hence, now you’ll set up the password authentication and remove other unnecessary access for your mysql server using the mysql commandline wizard.
Use mysql_secure_installation to enter into the command line wizard.
Mysql command line wizard will be opened.
The below three sections will be executed as a wizard. For the better understanding and reading experience, it is split as sections.
Setting password for root user
As a first part of the securing installation, you’ll set up the password authentication for the root user using the VALDATE PASSWORD PLUGIN. This plugin helps to check the strength of password allowing to set a highly secure password. Press Y to allow the usage of the Validate Password Plugin.
Securing the MySQL server deployment. Connecting to MySQL using a blank password. VALIDATE PASSWORD PLUGIN can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD plugin? Press y|Y for Yes, any other key for No: Y
This will display the different levels of secure password that will be validated by the Validate Password Plugin.
Level 0 = low, Level 1 = medium, and Level 2 = strong.
Medium level policy uses Length >=8, mixed case, numeric and special characters. It is sufficient enough to secure the mysql database. Hence, you’ll use the medium level password policy.
Enter 1 to opt for the medium level policy as shown below.
There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1
Now you’ll be asked to enter the password. Enter your desired password with length greater than 8, number, mixed case of alphabets and special characters.
Please set the password for root here. New password: ********** Re-enter new password: **********
Once you press enter after entering the password, the Validate password plugin will validate your password and display the estimated strength of the password. It will ask you to confirm if you would like to continue with the provided password. Press Y and Press Enter.
Estimated strength of the password: 100 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y
Removing Anonymous User Account
Now, you’ll proceed to remove the anonymous user accounts created during installation.
Anonymous user account is created during installation to making the installation smoother and its intended only for testing. It’ll allow everyone to connect to your database without user account created for them.
You MUST remove it before you move your database to the production environment.
Press Y for the question Remove anonymous users? and press enter.
By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y Success.
Disallowing Remote Login for Root User
Root user is a user with every privilege on the database. Its destructive if somebody from the network have guessed your password and login to your database. Hence root account must be protected with utmost security to avoid unauthorized access.
In this step, you’ll remove the Remote login your root account.
Press Y for the question Disallow root login remotely? and press enter.
Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y Success.
Removing Test Database and Its Access
By default, a test database is created during the Mysql installation without password and anybody is allowed to access it. This is also intended only for testing and MUST be removed before moving into Production environment.
In this step, you’ll remove the test database and its access.
Press Y for the question Remove test database and access to it? and press enter.
By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y - Dropping test database... Success. - Removing privileges on test database... Success.
Reloading Privilege Table
All the privileges for each table is stored in a table called privilege table. Since you have removed the privileges on the test database, you need to reload the privilege table to ensure that the changes you have made until now takes effect.
In this step you’ll reload the privileges table.
Press Y for the question Reload privilege tables? and press enter.
Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y Success. All done!
All done. You’ve secured your Mysql installation. Now you’ll proceed to test the LAMP stack installed to ensure if everything is installed properly.
Step 4 – Testing the LAMP Stack
In this step, you’ll test the LAMP stack. Linux is an operating system which you are already working and Mysql is working fine based on the above steps.
You’ll test the remaining Apache and PHP.
Open the web browser in you local computer and enter the public IP of your server. If you would like to test in the same Linux server, just type localhost in the browser address bar.
You’ll see the homepage like below. It means Apache is installed properly and its ready to serve webpages.
Apache is installed successfully. Now you’ll test PHP installation.
To test the php file, now you’ll create a php file which will display the php information.
To server the file via Apache, the files should be created under the directory /var/www/html/ .
Navigate to the /var/www/html/ directory using the below command.
Now create a file called info.php using the below command.
nano will open the file. Enter the below content.
<?php phpinfo(); ?>
The content is to display the information of the php. The method phpinfo() is used to display the information of the installed PHP.
Press Ctrl + O to write out the contents to file and press enter. Contents are written into the file. Now press Ctrl + X to exit the nano editor.
To check if the PHP is working fine, use your publicaddress/info.php in your web browser. You’ll see the PHP information as below.
This shows that the PHP is installed successfully.
You’ve installed the LAMP stack using Tasksel and also verified the installion of apache and PHP.
You’ve learnt how to install lamp using tasksel on ubuntu.
You can now serve file using this webserver.
<Watch this space for more updates on Blog>
Amazon Linux: apt-get: command not found
If you’re using Amazon Linux machine image, it’s CentOS-based, which is RedHat-based. Red hat based linux supports
apt-get. You can install packages using YUM install <Package name>.
To list the available packages, you can use yum search <Package name>.
What is Tasksel?
Tasksel is a Debian/Ubuntu based command line utility which can be used to install a group of packages in Linux.
How to install Tasksel on Ubuntu?
Tasksel can be installed using sudo apt install tasksel
How do I install lamp in Tasksel?
You can install lamp in tasksel using sudo tasksel install lamp-server.
Tasksel VS APT?
Tasksel is more powerful in processing and selecting tasks. where APT installs packages in a standard way.