- Get started with LAMP applications
- Quickstart
- LAMP application install process
- Update LAMP applications
- How To Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu 20.04 [Quickstart]
- Prerequisites
- Step 1 — Install Apache
- Step 2 — Install MySQL
- Step 3 — Install PHP
- Step 4 — Create a Virtual Host for your Website
- Step 5 — Test PHP with Apache
- Related Tutorials
- Install a LAMP Stack on Ubuntu 22.04
- What is a LAMP Stack?
- Before You Begin
- Installing a LAMP Stack on Ubuntu
Get started with LAMP applications
LAMP installations (Linux + Apache + MySQL + PHP/Perl/Python) are a popular setup for Ubuntu servers. There are a plethora of Open Source applications written using the LAMP application stack. Some popular LAMP applications include wikis, management software such as phpMyAdmin, and Content Management Systems (CMSs) like WordPress.
One advantage of LAMP is the substantial flexibility for different database, web server, and scripting languages. Popular substitutes for MySQL include PostgreSQL and SQLite. Python, Perl, and Ruby are also frequently used instead of PHP. While Nginx, Cherokee and Lighttpd can replace Apache.
Quickstart
The fastest way to get started is to install LAMP using tasksel . Tasksel is a Debian/Ubuntu tool that installs multiple related packages as a co-ordinated “task” onto your system.
At a terminal prompt enter the following command:
sudo tasksel install lamp-server
LAMP application install process
After installing LAMP you’ll be able to install most LAMP applications in this way:
- Download an archive containing the application source files.
- Unpack the archive, usually in a directory accessible to a web server.
- Depending on where the source was extracted, configure a web server to serve the files.
- Configure the application to connect to the database.
- Run a script, or browse to a page of the application, to install the database needed by the application.
- Once the steps above, or similar steps, are completed you are ready to begin using the application.
A disadvantage of using this approach is that the application files are not placed in the file system in a standard way, which can cause confusion as to where the application is installed.
Update LAMP applications
When a new LAMP application version is released, follow the same installation process to apply updates to the application.
Fortunately, a number of LAMP applications are already packaged for Ubuntu, and are available for installation in the same way as non-LAMP applications (some applications may need extra configuration and setup steps). Two popular examples are phpMyAdmin and WordPress.
Refer to our guides on how to install phpMyAdmin and how to install WordPress for more information on those applications.
How To Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu 20.04 [Quickstart]
In this quickstart guide, we’ll install a LAMP stack on an Ubuntu 20.04 server.
For a more detailed version of this tutorial, with more explanations of each step, please refer to How To Install Linux, Apache, MySQL, PHP (LAMP) Stack on Ubuntu 20.04
Prerequisites
To follow this guide, you’ll need access to an Ubuntu 20.04 server as a sudo user.
Step 1 — Install Apache
Update your package manager cache and then install Apache with:
Once the installation is finished, you’ll need to adjust your firewall settings to allow HTTP traffic on your server. Run the following command to allow external access on port 80 (HTTP):
With the new firewall rule added, you can test if the server is up and running by accessing your server’s public IP address or domain name from your web browser. You’ll see a page like this:
Step 2 — Install MySQL
We’ll now install MySQL, a popular database management system used within PHP environments.
Again, use apt to acquire and install this software:
When the installation is finished, it’s recommended that you run a security script that comes pre-installed with MySQL. Start the interactive script by running:
This will ask if you want to configure the VALIDATE PASSWORD PLUGIN . Answer Y for yes, or anything else to continue without enabling. If you answer “yes”, you’ll be asked to select a level of password validation.
Your server will next ask you to select and confirm a password for the MySQL root user. Even though the default authentication method for the MySQL root user dispenses the use of a password, even when one is set, you should define a strong password here as an additional safety measure.
For the rest of the questions, press Y and hit the ENTER key at each prompt.
Note: At the time of this writing, the native MySQL PHP library mysqlnd doesn’t support caching_sha2_authentication , the default authentication method for MySQL 8. For that reason, when creating database users for PHP applications on MySQL 8, you’ll need to make sure they’re configured to use mysql_native_password instead. Please refer to step 6 of our detailed LAMP on Ubuntu 20.04 guide to learn how to do that.
Step 3 — Install PHP
To install PHP and its dependencies, run:
Once the installation is finished, you can run the following command to confirm your PHP version:
OutputPHP 7.4.3 (cli) (built: Mar 26 2020 20:24:23) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies
Step 4 — Create a Virtual Host for your Website
In this guide, we’ll set up a domain called your_domain, but you should replace this with your own domain name.
Apache on Ubuntu 20.04 has one server block enabled by default that is configured to serve documents from the /var/www/html directory. Instead of modifying /var/www/html , we’ll create a directory structure within /var/www for the your_domain site, leaving /var/www/html in place as the default directory to be served if a client request doesn’t match any other sites.
Create the directory for your_domain as follows:
Next, assign ownership of the directory with the $USER environment variable, which will reference your current system user:
Then, open a new configuration file in Apache’s sites-available directory using your preferred command-line editor:
This will create a new blank file. Paste in the following bare-bones configuration:
ServerName your_domain ServerAlias www.your_domain ServerAdmin webmaster@localhost DocumentRoot /var/www/your_domain ErrorLog $/error.log CustomLog $/access.log combined
Save and close the file when you’re done. If you’re using nano , you can do that by pressing CTRL+X , then Y and ENTER .
You can now use a2ensite to enable the new virtual host:
To disable Apache’s default website, type:
To make sure your configuration file doesn’t contain syntax errors, run:
Finally, reload Apache so these changes take effect:
Your new website is now active, but the web root /var/www/ your_domain is still empty. Create an index.html file in that location so that we can test that the virtual host works as expected:
Include the following content in this file:
Hello World!
This is the landing page of your_domain.
Now go to your browser and access your server’s domain name or IP address once again:
You’ll see a page like this:
Step 5 — Test PHP with Apache
We’ll now create a PHP test script to confirm that Apache is able to handle and process requests for PHP files.
Create a new file named info.php inside your custom web root folder:
This will open a blank file. Add the following content inside the file:
When you are finished, save and close the file.
Go to your web browser and access your server’s domain name or IP address, followed by the script name, which in this case is info.php :
http://server_domain_or_IP/info.php
You’ll see a page similar to this:
After checking the relevant information about your PHP server through that page, it’s best to remove the file you created as it contains sensitive information about your PHP environment -and your Ubuntu server. You can use rm to do so:
Related Tutorials
Here are links to more detailed guides related to this tutorial:
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
Install a LAMP Stack on Ubuntu 22.04
Estamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.
The LAMP Stack includes an operating system, web server, programming language, and database. These applications are collectively able to implement web applications and other computing solutions. This guide provides some background about the LAMP stack and explains how to install and configure it on Ubuntu 22.04 LTS. It also explains how to quickly test interactions between the applications.
What is a LAMP Stack?
The LAMP Stack is an acronym for Linux, Apache, MySQL, and PHP. It includes an operating system, a web server, a database, and a versatile programming language. All components are available through the default Ubuntu software repositories.
The LAMP Stack is sufficient to host web applications and implement a modern computing environment. Many other Ubuntu applications rely on some or all of these programs. In some cases, substitutions to the LAMP stack can be made. For example, the NGINX web server can be used instead of Apache. Each component has a role within the software stack.
- Linux: Linux is an operating system based on UNIX. Linux is available for free as open source technology. There are several distinct implementations of Linux, which are known as distributions. Ubuntu is one of the most popular distributions. Other alternatives include Debian, Red Hat, Arch, and many, many others. Each distribution of Linux is associated with a software library. This library is used to install other software, including the other LAMP stack components.
- Apache HTTP Server: Apache is the most common web server for Ubuntu and throughout the public internet. The Apache Software Foundation develops and releases Apache as free and open source software. The standard version of Apache includes all components required to host a web site. However, extra modules can be used to add features including authentication and programming language APIs.
- MySQL: MySQL is a relational database management system (RDBMS). Although owned by Oracle, MySQL is free. Its source code is available under the GNU General Public License. MariaDB or PostgreSQL sometimes replace MySQL in the stack.
- PHP: PHP is the server-side scripting and programming language used in the stack. It is commonly used in web development and is firmly integrated with the rest of the stack. An Ubuntu system interprets PHP code using a PHP processor. PHP commands can be efficiently embedded within an HTML page. PHP software is available for free under the PHP License. Alternatives to PHP include Perl and Python, which can also serve as the P in the LAMP stack.
Before You Begin
- If you have not already done so, create a Linode account and Compute Instance. See our Getting Started with Linode and Creating a Compute Instance guides.
- Follow our Setting Up and Securing a Compute Instance guide to update your system. You may also wish to set the timezone, configure your hostname, create a limited user account, and harden SSH access.
This guide is written for a non-root user. Commands that require elevated privileges are prefixed with sudo . If you are not familiar with the sudo command, see the Users and Groups guide.
Installing a LAMP Stack on Ubuntu
This section explains how to install a LAMP Stack on Ubuntu 22.04 LTS. These instructions are also generally valid for Ubuntu 20.04 LTS.
These instructions are valid with or without a registered domain name. If a domain name maps to the IP address of the server, a virtual host should also be configured. For information on domain names and pointing the domain name to a Linode, see the Linode DNS Manager guide.
To install the LAMP stack on Ubuntu 22.04 LTS, follow these steps. In all cases, enter y to proceed with the installation when asked for confirmation.
- Using apt , update the Ubuntu packages: