A LAMP stack is a group of four open-source software components that khung the foundation of building và running high-performance dynamic websites & web applications. It"s an acronym for Linux, Apache, MySQL/MariaDB và PHP.
The LAMP stack is simple, stable, and powerful, & its first layer is comprised of the popular Linux Operating System with flexible configuration options and tight security. Apache is the second layer in the pile và offers you compiled module support for major scripting languages such as PHP, Perl, Python, Node.js, etc. This HTTP web hệ thống delivers web content through the internet. When it comes to the database layer, you"ve two options when deploying a LAMP stack. You can either use MySQL or MariaDB as an Relational Database Management System (RDMS) for your website applications. The last package in the list is PHP. This is a scripting language that you can easily embed in HTML documents khổng lồ create static or dynamic websites.
The majority of modern content Management Systems (CMS) such as WordPress, Joomla, Drupal, & Magento require a LAMP stack to work. Therefore, in this guide, you"ll learn how to configure the right environment for them. The same cài đặt will also work for any custom website application that you may intend lớn build with the LAMP stack technology.
To follow along with this guide, you need the following:
1. Install Apache Webserver
SSH lớn your Ubuntu vps as a non-root user, then update the package information index và upgrade your packages.
$ sudo apt update && sudo apt -y upgradeNext, run the command below to install the Apache web server.
$ sudo apt install -y apache2Visit the URL below on a web browser & replace the 192.0.2.1 with the public IP address of your hệ thống or tên miền name.
You should see the mặc định Apache website page as shown below.
After setting up the website server, you"ll install a database in the next step.
2. Install a Database Server
You can either install MySQL or MariaDB server when deploying a LAMP stack. To lớn install the MySQL server, run the command below.
$ sudo apt install -y mysql-serverTo phối up a MariaDB server, execute the command below.
$ sudo apt install -y mariadb-server mariadb-clientIrrespective of the database that you"ve chosen, run the command below khổng lồ secure it.
$ sudo mysql_secure_installationEnter the below choices & press ENTER in each prompt lớn proceed.
Would you lượt thích to cài đặt VALIDATE PASSWORD component? Press y|Y for Yes, any other key for No: n Please phối the password for root here. New password: EXAMPLE_PASSWORD Re-enter new password: EXAMPLE_PASSWORD Remove anonymous users? (Press y|Y for Yes, any other key for No) : y Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y Remove kiểm tra database và access khổng lồ it? (Press y|Y for Yes, any other key for No): y Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
MariaDB ServerEnter current password for root (enter for none): ENTER set root password?
$ sudo mysql -u root -pEnter your database hệ thống root password và press ENTER to proceed. Then, type the command below to create your first test_database database.
mysql> CREATE database test_database;MariaDB server.
MariaDB <(none)>> CREATE database test_database;Output.
Query OK, 1 row affected (0.00 sec)Next, list the databases in the hệ thống by running the SHOW DATABASES command.
mysql> SHOW DATABASES;MariaDB server.
MariaDB <(none)>> SHOW DATABASES;Your test_database should be in the danh mục below.
+--------------------+| Database |+--------------------+| information_schema || mysql || performance_schema || sys || test_database |+--------------------+5 rows in mix (0.01 sec)Create a test_user & assign full privileges khổng lồ the database you"ve just created. You"ll require the details of this user when testing database connectivity with PHP. Replace EXAMPLE_PASSWORD with a strong value.
mysql> CREATE USER "test_user"
"localhost" IDENTIFIED WITH mysql_native_password BY "EXAMPLE_PASSWORD"; GRANT ALL PRIVILEGES ON test_database.* to lớn "test_user"
"localhost" IDENTIFIED BY "EXAMPLE_PASSWORD"; GRANT ALL PRIVILEGES ON test_database.* to lớn "test_user"
"localhost"; FLUSH PRIVILEGES; EXIT;Your database vps is now ready and you can move ahead to installing a scripting language.
3. Install PHP
In this step, you"ll install the PHP package. Run the command below.
$ sudo apt install -y phpSince most website applications rely on some PHP extensions, install the most common ones using the command below.
$ sudo apt install -y php-common,mysql,xml,xmlrpc,curl,gd,imagick,cli,dev,imap,mbstring,opcache,soap,zip,intlRestart the Apache webserver khổng lồ load PHP.
$ sudo systemctl restart apache2To chạy thử PHP, create an info.php tệp tin in the root directory of your web server.
$ sudo nano /var/www/html/info.phpThen, enter the information below into the file.
Save và close the tệp tin by pressing CTRL + X, then Y & ENTER. Then, in a website browser, visit the URL below & replace 192.0.2.1 with your server"s correct public IP address.
You should get a detailed PHP page as shown below.
Next, thử nghiệm PHP connectivity with the database that you created earlier. Open a new file for editing using nano.
$ sudo nano /var/www/html/database_test.phpThen, enter the information below into the file.
connect_error) die("Database connection failed: " . $conn->connect_error);echo "Database connection was successful";Save and close the file. Then, visit the address below in a website browser & replace 192.0.2.1 with your server"s correct public IP address.
You should get the đầu ra below that shows that the script has successfully connected to the database.
echo "Database connection was successful";
ConclusionYour LAMP stack is now ready on Ubuntu 20.04, và you can now go ahead and build a dynamic website or cloud-based web application.
From here, consider reading about One-Click LAMP stack installation guides & securing your web vps with Let"s Encrypt.