Setting Up a LAMP Stack (Linux, Apache, MySQL, PHP) on Ubuntu

  • March 13, 2025
  • 0 Comments

Hey there! If you're looking to build a website or web application, you've probably heard of a LAMP stack. It's like a super team of software that works together to make websites run. LAMP stands for:

Linux (the operating system, which is Ubuntu in our case)
Apache (the web server, which you already installed in the last guide!)
MySQL (the database, where your website's information is stored)
PHP (the programming language, which makes websites interactive)

Today, we'll get that whole team working together on your Ubuntu server. And if you are hosting with Hostaira, this will be a breeze on our servers!

Step 1: Installing MySQL

First up, we need to install MySQL. This is like the library for your website, where all the important information is kept.

  1. Open your terminal (it's like a command center for your computer).
  2. Type this command and press Enter: sudo apt update && sudo apt install mysql-server -y
    This command does two things: it updates the list of available software and then installs MySQL. The -y part means "yes" to any questions the computer asks.
  3. Once it's installed, we need to make it secure. Type this: sudo mysql_secure_installation and press Enter.
  4. You'll be asked a few questions. It's important to set a strong password for the root user (the main administrator). Follow the prompts, and when in doubt, it is usually best to answer yes to the prompts.

Step 2: Installing PHP

Now, let's add PHP, the language that makes websites do cool things!

  1. In your terminal, type this command and press Enter: sudo apt install php libapache2-mod-php php-mysql -y
    This installs PHP and the tools that let Apache and MySQL work with it.
  2. To make sure PHP is installed correctly, type php -v and press Enter. This will show you the PHP version.

Step 3: Configuring Apache to Work with PHP

Apache is already installed from the previous article, and because we installed libapache2-mod-php most of the needed configuration is done. Now we just need to test that it is working.

  1. Let's create a test file. Type this: sudo nano /var/www/html/info.php and press Enter.
    nano is a simple text editor.
  2. Inside the file, type this code: <?php phpinfo(); ?>
    This code tells PHP to show us some information.
  3. Press Ctrl+X, then Y, then Enter to save and close the file.
  4. Open your web browser and type http://your_server_ip/info.php in the address bar (replace "your_server_ip" with your server's actual IP address).
  5. If you see a page with a bunch of PHP information, congratulations! PHP is working!
  6. For security reasons, it is a good idea to remove that file. In the terminal type: sudo rm /var/www/html/info.php and press enter.

Step 4: Restarting Apache

Just to make sure everything is running smoothly, let's restart Apache.

  1. In your terminal, type sudo systemctl restart apache2 and press Enter.

You've done it! You've set up a LAMP stack on your Ubuntu server. Now you can start building amazing websites and web applications. Remember, this is just the beginning. There's always more to learn and explore! And remember, Hostaira is here to support you on your web hosting journey.

Tips:

  • Take your time and follow the steps carefully.
  • If you get stuck, don't be afraid to search online for help. There are lots of resources available.
  • Have fun and enjoy the process of building your own websites!

How helpful was this article to you?

Posting has been disabled.