If you are looking to set up a web server on Ubuntu, you will likely need to install and configure a LAMP stack. LAMP stands for Linux, Apache, MySQL, and PHP, and it is the most popular web development platform used today. In this tutorial, we will guide you through the process of installing and configuring LAMP stack on Ubuntu.
Before we begin, you will need to ensure that you have the following:
- A server running Ubuntu 18.04 LTS or later.
- A non-root user with sudo privileges.
Step-1: Install Apache
Apache is a popular web server that can be used to serve web pages. To install Apache, open up a terminal window and run the following command:
sudo apt-get update sudo apt-get install apache2
After the installation is complete, start the Apache service by running:
sudo systemctl start apache2
To check if Apache is running, open up a web browser and enter your server’s IP address. You should see the Apache2 Ubuntu Default Page.
Step-2: Install MySQL
MySQL is a popular relational database management system that is used to store and manage data. To install MySQL, run the following command:
sudo apt-get install mysql-server
During the installation process, you will be prompted to set a root password for MySQL. Make sure to set a strong password and keep it safe.
After the installation is complete, start the MySQL service by running:
sudo systemctl start mysql
To secure your MySQL installation, you can run the following command:
This command will prompt you to configure several security options for your MySQL installation.
Step-3: Install PHP
PHP is a popular scripting language that is used to create dynamic web pages. To install PHP, run the following command:
sudo apt-get install php libapache2-mod-php php-mysql
After the installation is complete, restart the Apache service by running:
sudo systemctl restart apache2
To test if PHP is working properly, create a new file called info.php in the /var/www/html directory with the following content:
<?php phpinfo(); ?>
Save the file and open up a web browser. Enter the following URL: http://your_server_ip_address/info.php. You should see a PHP info page that displays information about your PHP installation.
Step-4: Configure Firewall
By default, Ubuntu comes with a firewall called UFW (Uncomplicated Firewall). To allow traffic to your web server, you will need to configure UFW to allow incoming traffic on ports 80 (HTTP) and 443 (HTTPS).
In order to allow HTTP traffic, run the following command:
sudo ufw allow 80/tcp
To allow HTTPS traffic, run the following command:
sudo ufw allow 443/tcp
After allowing the traffic, you can check the status of the firewall by running:
sudo ufw status
Congratulations! You have successfully installed and configured a LAMP stack on Ubuntu. You can now start developing and deploying web applications on your server.
In this tutorial, we have covered the installation and configuration of Apache, MySQL, PHP, and UFW. We hope that this tutorial has been helpful to you, and we encourage you to continue learning and exploring the vast world of web development.