How to install LAMP Stack to Ubuntu 20.04 Server / Desktop
This tutorial goes to indicate you the best way to set up LAMP stack on Ubuntu 20.04 LTS. A software program stack is a set of software program instruments bundled collectively. LAMP stands for Linux, Apache, MariaDB/MySQL and PHP, all of that are open supply and free to make use of. It’s the most typical software program stack that powers dynamic web sites and net purposes. Linux is the working system; Apache is the online server; MariaDB/MySQL is the database server and PHP is the server-side scripting language accountable for producing dynamic net pages.
To observe this tutorial, you want an Ubuntu 20.04 OS operating in your native pc or on a distant server.
In case you are on the lookout for a VPS (Digital Non-public Server), then you possibly can register an account at DigitalOcean by way of this particular hyperlink to get $50 free credit score. (For brand new customers solely). In case you are already a DigitalOcean person, then you possibly can register an account on Vultr by way of this particular hyperlink to get $50 free credit score (for brand new customers solely).
And if you want to arrange LAMP stack with a site identify, I like to recommend shopping for domains from NameCheap as a result of the value is low and so they give whois privateness safety free for all times.
Step 1: Replace Software program Packages
Earlier than we set up the LAMP stack, it’s a good suggestion to replace repository and software program packages. Run the next instructions in your Ubuntu 20.04 OS.
sudo apt replace
sudo apt improve
Step 2: Set up Apache Net Server
Enter the next command to put in Apache Net server. The apache2-utils bundle will set up some helpful utilities like Apache HTTP server benchmarking software (ab).
sudo apt set up -y apache2 apache2-utils
After it’s put in, Apache needs to be robotically began. Verify its standing with systemctl.
systemctl standing apache2
● apache2.service – The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Energetic: energetic (operating) since Sat 2020-04-11 11:31:31 CST; 2s in the past
Course of: 53003 ExecStart=/usr/sbin/apachectl begin (code=exited, standing=0/SUCCESS)
Essential PID: 53011 (apache2)
Duties: 55 (restrict: 19072)
├─53011 /usr/sbin/apache2 -k begin
├─53012 /usr/sbin/apache2 -k begin
└─53013 /usr/sbin/apache2 -k begin
Trace: If the above command doesn’t give up instantly, you possibly can press Q key to realize again management of the terminal.
If it’s not operating, use systemctl to begin it.
sudo systemctl begin apache2
It’s additionally a good suggestion to allow Apache to robotically begin at system boot time.
sudo systemctl allow apache2
Verify Apache model:
Server model: Apache/2.4.41 (Ubuntu)
Server constructed: 2020-03-05T18:51:00
Now sort within the public IP tackle of your Ubuntu 20.04 server within the browser tackle bar. You must see the “It really works!” Net web page, which suggests Apache Net server is operating correctly. In case you are putting in LAMP in your native Ubuntu 20.04 pc, then sort 127.0.0.1 or localhost within the browser tackle bar.
If the connection is refused or failed to finish, there could be a firewall stopping incoming requests to TCP port 80. In case you are utilizing iptables firewall, then you want to run the next command to open TCP port 80.
sudo iptables -I INPUT -p tcp –dport 80 -j ACCEPT
In case you are utilizing UFW firewall, then run this command to open TCP port 80.
sudo ufw permit http
Now we have to set www-data (Apache person) because the proprietor of doc root (in any other case generally known as net root). By default it’s owned by the basis person.
sudo chown www-data:www-data /var/www/html/ -R
Step 3: Set up MariaDB Database Server
MariaDB is a drop-in substitute for MySQL. It’s developed by former members of MySQL workforce who’re involved that Oracle would possibly flip MySQL right into a closed-source product. Enter the next command to put in MariaDB on Ubuntu 20.04.
sudo apt set up mariadb-server mariadb-client
After it’s put in, MariaDB server needs to be robotically stared. Use systemctl to test its standing.
systemctl standing mariadb
● mariadb.service – MariaDB 10.3.22 database server
Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
Energetic: energetic (operating) since Fri 2020-04-10 14:19:16 UTC; 18s in the past
Essential PID: 9161 (mysqld)
Standing: “Taking your SQL requests now…”
Duties: 31 (restrict: 9451)
If it’s not operating, begin it with this command:
sudo systemctl begin mariadb
To allow MariaDB to robotically begin at boot time, run
sudo systemctl allow mariadb
Now run the put up set up safety script.
When it asks you to enter MariaDB root password, press Enter key as the basis password isn’t set but. Then enter y to set the basis password for MariaDB server.
Subsequent, you possibly can press Enter to reply all remaining questions, which is able to take away nameless person, disable distant root login and take away check database. This step is a fundamental requirement for MariaDB database safety. (Discover that Y is capitalized, which suggests it’s the default reply. )
By default, the MaraiDB bundle on Ubuntu makes use of unix_socket to authenticate person login, which principally means you need to use username and password of the OS to log into MariaDB console. So you possibly can run the next command to login with out offering MariaDB root password.
sudo mariadb -u root
To exit, run
Verify MariaDB server model data.
As you possibly can see, we’ve got put in MariaDB 10.3.22.
mariadb Ver 15.1 Distrib 10.3.22-MariaDB, for debian-linux-gnu (x86_64) utilizing readline 5.2
Step 4: Set up PHP7.4
On the the time of this writing, PHP7.Four is the newest steady model of PHP and has a minor efficiency edge over PHP7.3. Enter the next command to put in PHP7.Four and a few widespread PHP modules.
sudo apt set up php7.Four libapache2-mod-php7.Four php7.4-mysql php-common php7.4-cli php7.4-common php7.4-json php7.4-opcache php7.4-readline
Allow the Apache php7.Four module then restart Apache Net server.
sudo a2enmod php7.4
sudo systemctl restart apache2
Verify PHP model data.
PHP 7.4.3 (cli) (constructed: Mar 26 2020 20:24:23) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Applied sciences
with Zend OPcache v7.4.3, Copyright (c), by Zend Applied sciences
To check PHP scripts with Apache server, we have to create a information.php file within the doc root listing.
sudo nano /var/www/html/information.php
Paste the next PHP code into the file.
To save lots of a file in Nano textual content editor, press Ctrl+O, then press Enter to substantiate. To exit, press Ctrl+X. Now within the browser tackle bar, enter server-ip-address/information.php. Exchange sever-ip-address along with your precise IP. Should you observe this tutorial in your native pc, then sort 127.0.0.1/information.php or localhost/information.php.
You must see your server’s PHP data. This implies PHP scripts can run correctly with Apache net server.
The right way to Run PHP-FPM with Apache
There are principally two methods to run PHP code with Apache net server:
- Apache PHP module
Within the above steps, the Apache PHP7.Four module is used to deal with PHP code, which is often high quality. However in some circumstances, you want to run PHP code with PHP-FPM as a substitute. Right here’s how.
Disable the Apache PHP7.Four module.
sudo a2dismod php7.4
Set up PHP-FPM.
sudo apt set up php7.4-fpm
Allow proxy_fcgi and setenvif module.
sudo a2enmod proxy_fcgi setenvif
Allow the /and so forth/apache2/conf-available/php7.2-fpm.conf configuration file.
sudo a2enconf php7.4-fpm
Restart Apache for the modifications to take impact.
sudo systemctl restart apache2
Now in the event you refresh the information.php web page in your browser, one can find that Server API is modified from Apache 2.Zero Handler to FPM/FastCGI, which suggests Apache net server will go PHP requests to PHP-FPM.
Congrats! You will have efficiently put in LAMP stack (Apache, MariaDB and PHP7.4) on Ubuntu 20.04. On your server’s safety, you must delete information.php file now to stop prying eyes.
sudo rm /var/www/html/information.php
I hope this tutorial helped you put in LAMP stack on Ubuntu 20.04 LTS. You may additionally need to set up phpMyAdmin, which is a free and open-source web-based database administration software.
As at all times, in the event you discovered this put up helpful, then subscribe to our free e-newsletter to get extra ideas and methods. Take care 🙂
Fee this tutorial[Total: 2 Average: 5]
install lamp ubuntu,install phpmyadmin ubuntu 20.04 nginx,ubuntu 20.04 install lamp stack,ubuntu 20.04 lamp server,digitalocean ubuntu 20.04 phpmyadmin,ubuntu 20.04 mysql phpmyadmin,lamp server tutorial,ubuntu 20.04 lamp phpmyadmin