Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Linux Tutorials»How To Install LAMP Stack on Ubuntu 22.04 LTS

    How To Install LAMP Stack on Ubuntu 22.04 LTS

    RahulBy RahulApril 5, 20225 Mins ReadUpdated:April 20, 2022

    The LAMP (Linux, Apache, MySQL, and PHP) stack is wildly used for deploying PHP-based applications on Linux systems. The LAMP server installation is pretty easy and straightforward. You need some basic knowledge of the Linux package manager to complete this setup.

    Here Linux is an open-source operating system. Apache is a popular web server. MySQL is a relational database server and PHP is the programming language.

    This tutorial will help you to install PHP, Apache & MySQL on Ubuntu 22.04 LTS Linux system.

    Before We Begin

    Assuming that you have a running Ubuntu 22.04 Linux system with sudo (or root) privileged access.

    Access your system and open a terminal. It will be good to update package manager cache and upgrade currently installed packages. To do this execute:

    sudo apt update && sudo apt upgrade 
    

    Let’s begin the LAMP (Linux, Apache, MySQL, and PHP) stack installation on Ubuntu 22.04 Jammy Jellyfish Linux system.

    PHP Installation

    First, you need to decide on the PHP version to install on your system. You can also install multiple PHP versions on a single system. Currently the repository contains PHP 5.6, PHP 7.1, 7.2, 7.3, 7.4 and PHP 8.0, 8.1. The below instruction will install PHP 8.1. Please change the version as per your requirements.

    The ondrej/php ppa contains all PHP version’s for Ubuntu systems. So add this repository in your system with command below:

    sudo add-apt-repository ppa:ondrej/php 
    

    Now update the apt cache and install PHP 8.1.

    sudo apt update 
    sudo apt install php8.1 
    

    This will install PHP on your Ubuntu system along with some useful PHP extension.

    Apache Installation

    Generally, the PHP installation also installs the Apache and its module on your system. Still, you can run the following commands to confirm the installations.

    sudo apt install apache2 libapache2-mod-php8.1 -y 
    

    This will install Apache and start the service.

    Now, you need to allow webserver ports in the firewall. To allow ports 80 and 443 in the UFW firewall, execute the following commands.

    sudo ufw allow 80/tcp 
    sudo ufw allow 43/tcp 
    

    Open a web browser on your system and type the server’s IP in the address bar. You will get the default Apache server page

    How to Install LAMP Stack on Ubuntu 22.04
    Apache default page

    MySQL Installation

    The default Ubuntu repositories contain MySQL 8.0. Which can be directly installed using the package manager. To install the available MySQL server version, execute the following command.

    sudo apt-get install mysql-server 
    

    Once the installation is finished, you can secure the MySQL server by executing the following command.

    sudo mysql_secure_installation 
    

    This will ask for a few questions to secure the MySQL server.

    1. Press ‘y’ to enable validate password plugin. This will allow you to set a strict password policy for user accounts.
      VALIDATE PASSWORD COMPONENT can be used to test passwords
      and improve security. It checks the strength of password
      and allows the users to set only those passwords which are
      secure enough. Would you like to setup VALIDATE PASSWORD component?
      
      Press y|Y for Yes, any other key for No: y
      
    2. Chose the password complexity level. Read the all 3 options and choose one:
      LOW    Length >= 8
      MEDIUM Length >= 8, numeric, mixed case, and special characters
      STRONG Length >= 8, numeric, mixed case, special characters and dictionary file
      
      Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1
      
    3. Enter a new password and re-enter it. Make sure it matches the complexity level as described above.
      New password: *************
      Re-enter new password: *************
      
    4. Press ‘y’ to continue with provided password.
      Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
      
    5. Remove default anonymous users from MySQL server:
      Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
      
    6. Disable root login from remote systems
      Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
      
    7. Remove test database form MySQL created by default during installation.
      Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
      
    8. Reload all privileges to apply above changes immediately.
      Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
      

    You have secured the MySQL server in the LAMP stack on Ubuntu 22.04 Linux system.

    Remember that the above password set for the root accounts is used for remote users only. To log in from the same system, just type mysql on terminal.

    sudo mysql 
    
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 14
    Server version: 8.0.28-0ubuntu4 (Ubuntu)
    
    Copyright (c) 2000, 2022, Oracle and/or its affiliates.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql>
    

    Installing Other Required Packages

    You may also need to install modules like MySQL and other extensions for PHP based on the application requirements. Use the following command to find our available PHP extensions.

    sudo apt search php8.1-* 
    

    Above command will list all available PHP7 modules for installation, Let’s begin installation of modules.

    sudo apt install php8.1-mysql php8.1-curl php8.1-xml 
    

    Verify Setup

    You have successfully completed the installation of Apache, MySQL, and PHP on the Ubuntu 22.04 Linux system. To verify the PHP integration with Apache, create a PHP script (example: info.php) on the website document root and write the below content.

    PHP
    1
    2
    3
    <?php
       phpinfo();
    ?>

    Now access this file in the web browser. It will so all the details about versions and installation.

    http://server-ip-address/info.php 
    How to Setup LAMP Stack on Ubuntu 22.04
    PHP details by phpinfo() function.

    Conclusion

    This tutorial helped you to set up the LAMP stack on Ubuntu 22.04 LTS system. Now, you can host PHP-based web applications on your server.

    Apache lamp MySQL PHP Ubuntu 22.04
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleJava HashMap – How to Get Value from Key
    Next Article How To Install MySQL Server on Ubuntu 22.04

    Related Posts

    How To Install PHP (8.1, 7.4 or 5.6) on Ubuntu 22.04

    Updated:May 9, 20223 Mins Read

    (Resolved) userauth_pubkey: key type ssh-rsa not in PubkeyAcceptedAlgorithms

    Updated:May 10, 20221 Min Read

    How to Check IPv4 Address on Ubuntu 22.04

    2 Mins Read

    How to Install Apache ActiveMQ on Ubuntu 22.04

    3 Mins Read

    How To Enable SSH Server on Ubuntu 22.04

    Updated:April 22, 20222 Mins Read

    How To Install Node.js on Ubuntu 22.04

    Updated:April 16, 20223 Mins Read

    32 Comments

    1. Mário Davi on April 23, 2022 4:42 pm

      Failed to start The Apache HTTP Server.
      Job for apache2.service failed because the control process exited with error code.
      See “systemctl status apache2.service” and “journalctl -xeu apache2.service” for details.

      Reply
      • Rahul on April 25, 2022 6:28 am

        Kindly, paste the output of “systemctl status apache2.service”.

        Reply
    2. Anh Tran on January 26, 2018 4:45 am

      To install the latest version of PHP, use “php-fpm” instead of “php7.0-fpm”.

      Reply
    3. malik on September 1, 2017 11:36 am

      Thanx a lot it helped me to set up my site at AWS…

      Reply
    4. Bhagirath on August 11, 2017 5:26 am

      Reading state information… Done
      E: Unable to locate package php7.0
      E: Couldn’t find any package by regex ‘php7.0’

      got this error,

      Reply
    5. franciscorenef on April 29, 2017 10:14 pm

      gracias amigo

      Reply
    6. Xabi Tortilla on February 27, 2017 5:55 pm

      How can i solve this problem ?
      The following packages have unmet dependencies:
      mysql-server-5.6 : Depends: mysql-common (>= 5.6.22-1~) but 5.5.54-0ubuntu0.14.04.1 is to be installed
      E: Unable to correct problems, you have held broken packages.

      Reply
    7. adelval on September 21, 2016 9:03 pm

      I followed the instructions, and while running info.php (with the phpinfo command) from the shell gave a version number of 7.0.11, accessing this file from the browser displayed php 5.x.

      You need to disable the module php5 and enable php7 for apache, with the following commands:

      $ sudo a2dismod php5
      $ sudo service apache2 restart
      $ sudo service a2enmod php7.0
      $ sudo service apache2 restart

      After running these commands, apache uses php7, as shown by accesing test.php from the browser.

      Reply
    8. Azatrie on July 27, 2016 6:28 pm

      I try to insttall php7 using above mentioned command and i automatically end up installing apache2 from offical ubuntu repo.

      Should i install apache2 before php?

      Reply
    9. James on May 19, 2016 9:31 pm

      Correct me if I’m wrong on this but shouldn’t the prompt be # and not $?

      Reply
      • morcen on July 17, 2016 10:30 am

        `#` is an indication that the user is “root”, otherwise it will display `$`. That’s also the reason why this tutorial is using `sudo` because the commands needs admin privileges.

        Reply
    10. Shahzad on April 28, 2016 11:41 am

      How to install phpmyadmin?

      Reply
      • Maulik Gangani on April 30, 2016 4:01 am

        apt-get install phpmyadmin

        Reply
    11. Maulik Gangani on April 27, 2016 12:52 pm

      Thank You Very Much 😀

      Reply
    12. lxl on April 16, 2016 8:07 pm

      thank you for your wonderful tutorial but im getting problem when im trying to visit my phpmyadmin, can you tell me about it since on less version u just need to include. “Include /etc/phpmyadmin/apache.conf” inside the “sudo nano /etc/apache2/apache2.conf”

      Reply
      • Franks on May 24, 2016 12:38 am

        you can download the file from phpmyadmin.net and uncompress that.

        Reply
    13. Vitalicus on April 5, 2016 11:11 pm

      Can’t install phpmyadmin 🙁
      Please help.
      “Depends: libapache2-mod-php5 but it is not going to be installed”

      Reply
      • Who on October 30, 2016 5:22 pm

        sudo apt-get -f install

        Reply
    14. Kalpesh on March 14, 2016 9:54 am

      Mysql not working for me, I am using ubuntu 14.04

      getting following error while installing :
      ——————-
      invoke-rc.d: initscript mysql, action “start” failed.
      dpkg: error processing package mysql-server-5.6 (–configure):
      subprocess installed post-installation script returned error exit status 1
      Processing triggers for ureadahead (0.100.0-16) …
      E: Sub-process /usr/bin/dpkg returned an error code (1)
      ——————-

      Reply
      • Jasom Dotnet on May 19, 2016 9:11 am

        same here

        Reply
      • Jasom Dotnet on May 19, 2016 10:58 am

        Install MariaDB instead

        Reply
        • Kalpesh on May 23, 2016 4:44 am

          What is MariaDB ?

          Reply
          • Bret on May 31, 2016 3:21 pm

            the non-oracle fork of MySQL.

            Reply
    15. Dhruv Tiwari on February 19, 2016 6:03 am

      Thanks for your tutorial but tell me it is possible to run in VMWare workstation.

      Reply
    16. LongDono on February 10, 2016 11:34 pm

      Thank you! This is the first site that clued me in to the need to install libapache2-mod-php7.0… without that, Apache was either giving an error (because the old PHP5 mod was still enabled) or it was just displaying PHP files as plain text. Once I installed that, everything was finally working!

      Reply
      • Brandon on February 29, 2016 6:29 pm

        That doesn’t work for me, still plaintext. Can anyone help!?

        Reply
    17. Kingsley on January 28, 2016 8:52 am

      Nice, thanks for this….

      Reply
    18. Tomas on January 23, 2016 3:05 pm

      Awesome tutorial, thank you!

      Reply
    19. jorge on January 16, 2016 1:01 am

      the connection with mysql is different in php 7.0

      http://php.net/manual/es/pdo.construct.php

      Reply
    20. Abdussami on January 10, 2016 5:02 pm

      Thanks brother, good work.

      Reply
    21. Ahmad on January 1, 2016 6:42 am

      Thanks brother…

      Reply
    22. Miuccia on December 20, 2015 8:28 pm

      Great tutorial, thank you very much! It worked right away!

      Reply

    Leave A Reply Cancel Reply

    Recent Posts
    • How to Enable / disable Firewall in Windows
    • How to Install JAVA on Ubuntu 22.04
    • Switching Display Manager in Ubuntu – GDM, LightDM & SDDM
    • Changing the Login Screen Background in Ubuntu 22.04 & 20.04
    • How To Install PHP (8.1, 7.4 or 5.6) on Ubuntu 22.04
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.