To install a LAMP (Linux, Apache, MySQL, PHP) server on Ubuntu 20.04, follow these steps :
Update the Package Lists: Open a terminal window and update the package lists to ensure you have the latest information about available packages:
sudo apt update
Install Apache Web Server: You can install Apache using the apt package manager:
apt
sudo apt install apache2
After the installation is complete, start Apache and enable it to start on boot:
sudo systemctl start apache2 sudo systemctl enable apache2
Install MySQL Server: You can install MySQL using the following command. During the installation, you will be prompted to set a root password:
sudo apt install mysql-server
After the installation is complete, start MySQL and enable it to start on boot:
sudo systemctl start mysql sudo systemctl enable mysql
You should also run the MySQL security script to improve the server's security:
sudo mysql_secure_installation
Install PHP: Install PHP and some commonly used PHP extensions:
sudo apt install php libapache2-mod-php php-mysql
Configure Apache for PHP: To configure Apache to work with PHP, you need to edit the Apache configuration file:
sudo nano /etc/apache2/mods-enabled/dir.conf
Move the index.php file so it comes before index.html within the section. It should look like this:
index.php
index.html
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
Save the file and exit the text editor.
Restart Apache to apply the changes:
sudo systemctl restart apache2
Test Your LAMP Setup: Create a test PHP file to ensure that PHP is working correctly with Apache:
echo "" | sudo tee /var/www/html/info.php
You can access this file in your web browser by visiting http://your_server_ip/info.php. Replace your_server_ip with your server's IP address or domain name.
http://your_server_ip/info.php
your_server_ip
(Optional) Secure MySQL Installation: You can further enhance the security of your MySQL installation by running the MySQL security script:
This script will allow you to set a new root password, remove anonymous users, and more.
That's it! You've successfully installed a LAMP server on Ubuntu 20.04. You can now start building and hosting web applications on your server.
Running sudo mysql_secure_installation is an important step in securing your MySQL installation on Ubuntu. When you run this command, you'll be guided through a series of prompts to improve the security of your MySQL server. Here's a step-by-step breakdown of what happens when you run sudo mysql_secure_installation:
Set Root Password: You will be prompted to set a new root password for MySQL. This is the password you'll use to log in as the MySQL root user, which has administrative privileges. Enter a strong password and make sure to remember it.
Remove Anonymous Users: You'll be asked if you want to remove anonymous MySQL users. It's a good idea to remove anonymous users, as they can potentially be a security risk. Answer "Y" (yes) to this prompt.
Disallow Root Login Remotely: You'll be asked if you want to disallow root login from remote machines. It's generally a good security practice to disallow root login remotely. Answer "Y" (yes) to this prompt.
Remove Test Database: You'll be asked if you want to remove the test database that is included by default with MySQL. Answer "Y" (yes) to this prompt. This is another security measure to prevent unauthorized access.
Reload Privilege Tables: The script will reload the privilege tables to apply the changes you've made.
After completing these steps, your MySQL installation will be more secure. Make sure to keep your MySQL root password in a safe place, as it's essential for administrative tasks on the MySQL server.