{"id":65935,"date":"2022-07-22T12:00:00","date_gmt":"2022-07-22T16:00:00","guid":{"rendered":"https:\/\/jumpcloud.com\/?p=65935"},"modified":"2022-11-02T15:37:41","modified_gmt":"2022-11-02T19:37:41","slug":"how-to-install-lamp-server-ubuntu-22-04","status":"publish","type":"post","link":"https:\/\/jumpcloud.com\/blog\/how-to-install-lamp-server-ubuntu-22-04","title":{"rendered":"How to Install LAMP Server on Ubuntu 22.04"},"content":{"rendered":"\n
Jump to Tutorial<\/a><\/p>\n\n\n\n LAMP is one of the most popular and widely used software stacks. It stands for Linux, Apache, MySQL, and PHP, and is used for hosting both static and dynamic web applications. It’s a common hosting stack among developers and sysadmins, and is well adopted by most major hosting companies. Let\u2019s briefly flesh out the components of the stack.<\/p>\n\n\n\n Apache HTTP server<\/a> is a free and open source cross-platform web server that is used for hosting websites and web apps. It’s fast, feature-rich, and highly customizable to suit your hosting requirements.<\/p>\n\n\n\n MySQL<\/a> is a popular relational database management system (RDBMS) that stores data in rows and columns inside tables. This is crucial when running applications that need to capture and handle data in a structured format. Over time, MariaDB<\/a> has proved to be a popular alternative.<\/p>\n\n\n\n This is due to its powerful storage engines, faster replication, better security features, and improved performance. MariaDB is a fork of MySQL that was created following Oracle\u2019s acquisition of the database. Other alternatives include Persona and Postgres. Read about MySQL and LDAP integration<\/a> (including other databases) with 探花大神.<\/p>\n\n\n\n PHP<\/a> is a popular backend scripting language used to develop dynamic applications and access the database. Code written in PHP is interpreted by the web server using the PHP processor module, which generates the resulting webpage. WordPress is an example of a popular PHP application that\u2019s the most common CMS on the web. It\u2019s commonly paired with MySQL or MariaDB as well as Apache on the back end.<\/p>\n\n\n\n In this guide, we take you through how to install and configure the LAMP stack on Ubuntu 22.04, also code named \u201cJammy Jellyfish\u201d.<\/p>\n\n\n\n Before getting started, ensure you have the following:<\/p>\n\n\n\n The Apache package is available in the default Ubuntu 22.04 repositories, so you can easily install it using the APT package manager.<\/p>\n\n\n\n First, log in to your server instance and update the local package index as follows:<\/p>\n\n\n\n Next, install Apache HTTP as follows:<\/p>\n\n\n\n Once installed, Apache HTTP service starts automatically and no intervention is required to start it. To verify that the service is running, run the following command:<\/p>\n\n\n\n Consider enabling the Apache service to start automatically as a daemon service at start up as follows:<\/p>\n\n\n\n Ubuntu 22.04 comes with the firewall already installed. When enabled, all inbound traffic is blocked by default. As such, you need to allow Apache traffic through the firewall in case it\u2019s enabled. To achieve this, run the command:<\/p>\n\n\n\n This profile opens both port 80 (normal, unencrypted web traffic) and port 443 (TLS\/SSL encrypted traffic). You could also use the profile \u201cApache\u201d which opens only port 80, or \u201cApache Secure\u201d which opens only port 443.<\/p>\n\n\n\n Then reload the firewall for the changes to come into effect.<\/p>\n\n\n\n To confirm the changes made on the firewall, run the following command: <\/p>\n\n\n\n To ensure that the web server is accessible from a web browser, browse your server\u2019s IP address or registered domain name.<\/p>\n\n\n\n The default Apache welcome page will be displayed:<\/p>\n\n\n\n If you are able to view this page, your web server has been set up successfully.<\/p>\n\n\n\n The next component of the LAMP stack is the MySQL database server. However, in this guide, we opt to install MariaDB instead due to its high performance, and wealth of features and functionality. <\/p>\n\n\n\n To install MariaDB on Ubuntu 22.04 run the following command:<\/p>\n\n\n\n Like the Apache service, MariaDB service starts automatically once MariaDB is installed. To confirm this, run the command:<\/p>\n\n\n\n Once the installation is complete, start and enable MariaDB as follows:<\/p>\n\n\n\n To check the version of MariaDB installed, run the command:<\/p>\n\n\n\n From the above output, you can see that we have installed MariaDB 10.6.7.<\/p>\n\n\n\n The default settings that come with MariaDB are weak in the face of database intrusions or breaches. Your database is easily prone to external attacks. As such, you need to take an extra step and secure the database by running the mysql_secure_installation <\/strong>script.<\/p>\n\n\n\n To start this process, run the shell script as follows:<\/p>\n\n\n\n The script walks you through a couple of prompts. First, you will be required to specify the root password for the database server. <\/p>\n\n\n\n Press \u201cENTER\u201d since you have configured it already and decline switching to Unix Socket authentication which is considered less secure. <\/p>\n\n\n\n Next, provide a strong root password and confirm.<\/p>\n\n\n\n For the remaining prompts, type \u201cY<\/strong>\u201d to secure MariaDB to the best security standards. This removes anonymous users, disallows root login from remote locations, removes the test database and access to it, and finally saves the changes.<\/p>\n\n\n\n Now that you have Apache and MariaDB installed, proceed to install PHP and the required extensions. PHP is available in the default Ubuntu repositories. You’ll also need php-mysql, a PHP module that enables PHP to interact with MySQL-based databases. To allow Apache to handle PHP files, you also need libapache2-mod-php.<\/p>\n\n\n\n The dependencies for core PHP packages will be installed automatically. Run the following command:<\/p>\n\n\n\n Once the installation is complete, confirm the version installed using the following command:<\/p>\n\n\n\n Now, let\u2019s test out PHP integration with Apache web server. Create a sample info.php <\/strong>file in the document root directory.<\/p>\n\n\n\n Restart Apache to apply the changes made.<\/p>\n\n\n\n Next, open a web browser and go to the following address:<\/p>\n\n\n\n http:\/\/server-ip\/info.php<\/strong><\/p>\n\n\n\n You should see the following webpage detailing the version of PHP and information regarding PHP modules:<\/p>\n\n\n\n A virtual host file is an Apache directive that enables you to host multiple websites on a single host. By default, Apache comes with a virtual host file called 000-default<\/strong> located in the \/etc\/apache2\/sites-available\/ <\/strong>path.<\/p>\n\n\n\n This section demonstrates how to set up a virtual host file for your registered domain. For illustrative purposes, we will use the linuxtechgeek.info<\/strong> domain.<\/p>\n\n\n\n First, create the website directory that will contain the websites.<\/p>\n\n\n\n Next, configure the required directory permissions and ownership for the website directory.<\/p>\n\n\n\n Then, create a sample HTML page for testing the virtual host on the browser.<\/p>\n\n\n\n Paste the sample HTML code as shown:<\/p>\n\n\n\n Save and exit. Next, create a virtual host configuration file. <\/p>\n\n\n\n Paste the following lines of code and be sure to replace every instance of linuxtechgeek.info<\/strong> with your own registered domain name.<\/p>\n\n\n\n Save the changes and exit the virtual host file. Next, enable the virtual host as follows:<\/p>\n\n\n\n Then reload Apache.<\/p>\n\n\n\n Confirm the Apache configuration file is error-free.<\/p>\n\n\n\n Now head over to your browser and check if the virtual host is enabled and working.<\/p>\n\n\n\n http:\/\/domain<\/strong><\/p>\n\n\n\n This guide demonstrated how to install the LAMP stack on Ubuntu 22.04 and configured a virtual host file for a sample domain.<\/p>\n\n\n\n Are you managing an Amazon Linux 2 system as well that needs the LAMP stack installed? Check out the following tutorial: How to Install LAMP Server on Amazon Linux 2<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":" Learn how to install and configure the LAMP stack on Ubuntu 22.04, aka \u201cJammy Jellyfish,\u201d in our step-by-step tutorial.<\/p>\n","protected":false},"author":150,"featured_media":45306,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_oasis_is_in_workflow":0,"_oasis_original":0,"_oasis_task_priority":"","inline_featured_image":false,"footnotes":""},"categories":[23],"tags":[],"collection":[2778],"platform":[],"funnel_stage":[3017],"coauthors":[2535],"acf":[],"yoast_head":"\nPrerequisites<\/h2>\n\n\n\n
Step 1: Install Apache HTTP Server<\/h2>\n\n\n\n
$ sudo apt update<\/code>\n\n\n\n
$ sudo apt install apache2 -y<\/code>\n\n\n\n
$ sudo systemctl status apache2<\/code>\n\n\n\n
<\/figure>\n\n\n\n
$ sudo systemctl enable –now apache2<\/code>\n\n\n\n
$ sudo ufw allow “Apache Full”<\/code>\n\n\n\n
$ sudo ufw reload<\/code>\n\n\n\n
<\/figure>\n\n\n\n
$ sudo ufw status<\/code>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
Step 2: Install MariaDB Database Server<\/h2>\n\n\n\n
$ sudo apt install mariadb-server -y<\/code>\n\n\n\n
$ sudo systemctl status mariadb<\/code>\n\n\n\n
<\/figure>\n\n\n\n
$ sudo systemctl enable mariadb<\/code>\n\n\n\n
$ mariadb –version<\/code>\n\n\n\n
<\/figure>\n\n\n\n
Hardening MariaDB<\/h3>\n\n\n\n
$$ sudo mysql_secure_installation<\/code>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
Step 3: Install PHP and PHP Extensions<\/h2>\n\n\n\n
$ sudo apt install php libapache2-mod-php php-mysql<\/code>\n\n\n\n
$ php -v<\/code>\n\n\n\n
<\/figure>\n\n\n\n
$ echo “” | sudo tee \/var\/www\/html\/info.php<\/code>\n\n\n\n
sudo systemctl restart apache2<\/code>\n\n\n\n
<\/figure>\n\n\n\n
Step 4: Set Up a Virtual Host for Your Website (Optional)<\/h2>\n\n\n\n
sudo mkdir -p \/var\/www\/html\/linuxtechgeek.info<\/code>\n\n\n\n
$ sudo chown www-data:www-data -R \/var\/www\/html\/linuxtechgeek.info<\/code>\n
$ sudo chmod 775 -R \/var\/www\/html\/linuxtechgeek.info<\/code>\n\n\n\n
$ sudo vim \/var\/www\/html\/linuxtechgeek.info\/index.html<\/code>\n\n\n\n
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n<\/code>\n\n\n\n
$ sudo vim \/etc\/apache2\/sites-available\/linuxtechgeek.info.conf<\/code>\n\n\n\n
\n\n\n\n\n\n\n\n\n\n\n\n\n<\/code>\n\n\n\n
$ sudo a2ensite linuxtechgeek.info<\/code>\n\n\n\n
$ sudo systemctl reload apache2<\/code>\n\n\n\n
$ sudo apache2ctl configtest<\/code>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
Conclusion<\/strong><\/h2>\n\n\n\n