Menu
iThemes
WordPress Security, Backups & Maintenance
  • Products
    • iThemes Security Pro
    • BackupBuddy
    • iThemes Sync
    • Why buy from iThemes?
  • Bundles
    • Essentials Bundle
    • Plugin Suite
    • WordPress Web Designer’s Toolkit
    • Customer Spotlights
  • Resources
    • Blog
    • WordPress 101 Tutorials
    • WordPress Ebooks
    • Weekly WordPress Vulnerability Report
    • The Ultimate Guide to Starting a Web Design Business
  • Training
    • Upcoming Webinars
    • Free Webinar Library
    • Premium Courses
    • Become a Member
    • Member Login
  • Support
    • Documentation
    • Get Help
    • Product Updates
    • Upgrade Policy
    • Contact
    • Our Mission: Make People’s Lives Awesome
  • Log In
WordPress News and Updates from iThemes
Categories
  • Product Updates
  • WordPress Backup
  • WordPress Block Editor
  • WordPress Ecommerce
  • WordPress for Freelancers
  • WordPress Security
  • WordPress Tutorials
  • WPprosper

How to Install a LAMP Stack

Written by iThemes Editorial Team on April 28, 2020

Last Updated on September 14, 2020

In this post, we cover how to set up your new WordPress site by installing a LAMP stack.

What is a LAMP Stack?

To put simply, a LAMP stack is an acronym.

  • The L stands for “Linux”, your server’s operating system.
  • The A stands for “Apache”, your web server software.
  • The M stands for “MySQL”, your web server’s database management system.
  • Lastly, the P stands for “PHP”, a scripting language used by WordPress.

Put together, you have a LAMP stack.

On a VPS, the LAMP stack provides the basic functionality needed to host WordPress on your new site. Every website needs an operating system, web server software, a database, and PHP. In order to follow along, you will need to have a Linux operating system on your server (preferably Ubuntu as we use Ubuntu in the tutorial). The operating system should have already been done when you purchased the VPS.

How to Install a LAMP Stack

To begin, you will need to be signed into your VPS. We will assume you already had experience with signing in to your new server. If you’re on a Windows machine, you can sign into the server with a tool such as PuTTY. If you’re on a Mac or running some Linux distro, you can simply use the Terminal. Once you’re signed into the server, we will install Apache2.

Installing Apache

To begin, simply type the following command in your terminal:

sudo apt update

Notice the sudo, that indicates you will need root privileges and will prompt you for your password. The above command will update Ubuntu’s package manager, apt. Now let’s install Apache2:

sudo apt install apache2

The package manager will tell you the packages that will be installed along with how much disk space that will be used, and if you wish to proceed. Enter Y and press enter to proceed with the installation.

Once the packages are done installing, you can verify Apache has been installed by typing your server’s IP address in a web browser:

http://ip-address/

You will see Ubuntu’s default web page:

Congratulations! Apache is now installed. Next, let’s install MySQL.

Installing MySQL

We will use apt again to install MySQL with the following command:

sudo apt install mysql-server

Again, the package manager will list all of the packages that will be installed along with the amount of disk space the installation will take up. Enter Y and press Enter to continue with the installation.

MySQL is now installed. However, by default, the root user will have no password. Let’s change the password for better security practices. Type the following command to change the root password:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';

Replace MyNewPass with a secure password of your choosing. You can now exit the MySQL command prompt by typing the command:

exit

Congratulations! We now have MySQL installed, so WordPress can properly communicate with the database. Now, let’s install the last piece of the LAMP stack – PHP.

Installing PHP

PHP can be installed by typing the following command, again, we will use the package manager:

sudo apt install php libapache2-mod-php php-mysql

The command will install helper packages so that PHP can work with both Apache and MySQL.

By default, Apache will serve files by first looking for index.html. However, WordPress is primarily composed of PHP files, so we don’t want that behavior. Let’s tell Apache to serve PHP files before the HTML files. To do that, type the following command:

sudo nano /etc/apache2/mods-enabled/dir.conf

The command will open the nano editor, and present the following file:

<IfModule mod_dir.c>
    DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
</IfModule>

Let’s move the index.php to replace index.html to ensure PHP files will be displayed first. The file should now look like the following:

<IfModule mod_dir.c>
    DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule&gt

The file can be saved within nano by entering CTRL+X. Confirm the changes by entering Y and hit Enter to save the file to the same location. Once that is done, then we will want to restart Apache:

sudo systemctl restart apache2

We now have installed all components needed for a proper LAMP stack. Let’s ensure that PHP is working properly.

Testing PHP

Let’s create a PHP file in the /var/www/html/ directory and ensure PHP is working properly. Enter the following command:

sudo vi /var/www/html/php-info.php

Add the following code to the file:

<?php
phpinfo();
?>

Once the code is added, press :wq to apply the changes and save the file. Now, open the web browser and enter the following URL:

http://ip-address/php-info.php

You will now see the PHP configuration file. Once you have verified the page loads, we will want to delete the file for security reasons. The file can be deleted by typing the command:

sudo rm php-info.php

We now have the core components needed for running a WordPress site!

iThemes Team
iThemes Editorial Team

Each week, the team at iThemes team publishes new WordPress tutorials and resources, including the Weekly WordPress Vulnerability Report. Since 2008, iThemes has been dedicated to helping you build, maintain, and secure WordPress sites for yourself or for clients. Our mission? Make People’s Lives Awesome.

Share via:

  • Facebook
  • Twitter
  • LinkedIn
  • More
Other related posts
common wordpress errors
How to Fix Common WordPress Errors
WordPress White Screen of Death
The WordPress White Screen of Death: A Guide to Recovery
why-wordpress
Why WordPress? 15 Reasons to Use WordPress
manage-wordpress
How to Manage WordPress Sites: 75 Tasks To Keep Your Site Running Smoothly

Respond

Click here to cancel reply.

Get updates on new themes & plugins plus special discounts

About iThemes

  • The Team
  • Contact Us
  • Website Accessibility Statement
  • Sitemap

Resources

  • Blog
  • Documentation
  • WordPress Tutorials
  • Free WordPress Ebooks
  • Free Webinar Library
  • Free Upcoming Webinars
  • iThemes Training
  • Affiliates

Customers

  • Member Panel Login
  • Support
  • FAQs
  • Upgrade Policy
  • Licensing
  • Terms and Conditions
  • Refund Policy

Top Products

  • BackupBuddy
  • iThemes Security Pro
  • iThemes Sync
  • Restrict Content Pro
  • WPComplete
  • WordPress Plugins
  • Content Upgrades
  • WordPress Landing Page Plugin
  • BackupBuddy Stash

iThemes Media LLC Copyright © 2023 All rights reserved | Privacy Policy

© 2022 All Rights Reserved.

Visit StellarWP Visit Nexcess
Share via
Facebook
Twitter
LinkedIn
Mix
Email
Print
Copy Link
Powered by Social Snap
Copy link
CopyCopied
Powered by Social Snap