LAMP Stack,This educational goes to expose you a way to installation LAMP stack on Ubuntu 18.04 LTS. A software stack is a hard and fast of software gear bundled together. LAMP stands for Linux, Apache, MariaDB/MySQL and PHP, all of which might be open source and loose to use. It is the most not unusual software stack that powers dynamic web sites and internet applications. Linux is the operating gadget; Apache is the web server; MariaDB/MySQL is the database server and PHP is the server-side scripting language accountable for generating dynamic internet pages.
To follow this academic, you want an Ubuntu 18.04 OS jogging in your neighborhood pc or on a faraway server. If you are looking for a VPS (Virtual Private Server), then you could click on this unique link to get $one hundred unfastened credit on DigitalOcean. (For new users most effective). If you’re already a DigitalOcean user, then you can click this special link to get $50 loose credit score on Vultr (for new customers most effective).
LAMP Stack,Update Software Packages
LAMP Stack,Before we set up the LAMP stack, it’s a very good concept to update repository and software program applications. Run the following command on your Ubuntu 18.04 OS.
sudo apt update
sudo apt upgrade
LAMP Stack,Install Apache Web Server
LAMP Stack,Enter the subsequent command to put in Apache Web server. The apache2-utils package will deploy some beneficial utilities like Apache HTTP server benchmarking tool (ab).
sudo apt install -y apache2 apache2-utils
After it’s established, Apache should be robotically started. Check its popularity with systemctl.
systemctl status apache2
Sample output:
apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Drop-In: /lib/systemd/system/apache2.service.d
└─apache2-systemd.conf
Active: active (running) since Sat 2018-09-08 10:46:05 UTC; 3min 37s ago
Main PID: 1610 (apache2)
Tasks: 55 (limit: 505)
CGroup: /system.slice/apache2.service
├─1610 /usr/sbin/apache2 -k start
├─1612 /usr/sbin/apache2 -k start
└─1613 /usr/sbin/apache2 -k start
If it’s not running, use systemctl to start it.
sudo systemctl start apache2
It’s also a good idea to enable Apache to automatically start at system boot time.
sudo systemctl enable apache2
Check Apache version:
apache2 -v
Output:
Server version: Apache/2.4.29 (Ubuntu)
Server built: 2018-06-27T17:05:04
Now kind inside the public IP address of your Ubuntu 18.04 server inside the browser cope with bar. You should see the “It works!” Web web page, which means Apache Web server is strolling nicely.
If the connection is refused or failed to finish, there is probably a firewall preventing incoming requests to TCP port eighty. If you are using iptables firewall, then you definitely want to run the subsequent command to open TCP port 80.
sudo iptables -I INPUT -p tcp --dport 80 -j ACCEP
sudo ufw allow http
Now we want to set www-statistics (Apache person) as the owner of document root (otherwise referred to as net root). By default it’s owned with the aid of the root user.
sudo chown www-data:www-data /var/www/html/ -R
Install MariaDB Database Server
MariaDB is a drop-in replacement for MySQL. Enter the following command to install it on Ubuntu 18.04.
sudo apt install mariadb-server mariadb-client
After it’s mounted, MariaDB server must be mechanically stared. Use systemctl to test its fame.
systemctl status mariadb
Sample output:
mariadb.service - MariaDB 10.1.34 database server
Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2018-09-08 11:13:27 UTC; 21s ago
Docs: man:mysqld(8)
https://mariadb.com/kb/en/library/systemd/
Main PID: 3473 (mysqld)
Status: "Taking your SQL requests now..."
Tasks: 27 (limit: 505)
CGroup: /system.slice/mariadb.service
└─3473 /usr/sbin/mysqld
If it’s not running, start it with this command:
sudo systemctl start mariadb
To enable MariaDB to automatically start at system boot time, run
sudo systemctl enable mariadb
Now run the post installation security script.
sudo mysql_secure_installation
When it asks you to enter MariaDB root password, press Enter key as the foundation password isn’t set but. Then enter y to set the root password for MariaDB server.
Next, you may press Enter to reply all last questions, in an effort to eliminate nameless consumer, disable far flung root login and remove check database. This step is a basic requirement for MariaDB database safety. (Note that the letter Y is capitalized, which means it’s the default solution.)
By default, the MaraiDB bundle on Ubuntu makes use of unix_socket to authenticate user login, which basically means you may use username and password of the OS to log into MariaDB console. So you may run the subsequent command to login with out imparting MariaDB root password.
sudo mariadb -u root
To exit, run
exit;
Check MariaDB server version information.
mariadb --version
Output:
mariadb Ver 15.1 Distrib 10.1.34-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
LAMP Stack,Install PHP7.2
At the the time of this writing, PHP7.2 is the modern stable version of PHP and has a minor performance a
sudo a2enmod php7.2 sudo systemctl restart apache2
spect over PHP7.1. Enter the following command to put in PHP7.2.
sudo apt install php7.2 libapache2-mod-php7.2 php7.2-mysql php-common php7.2-cli php7.2-common php7.2-json php7.2-opcache php7.2-readline
Enable the Apache php7.2 module then restart Apache Web server.
sudo a2enmod php7.2
sudo systemctl restart apache2
Check PHP version information.
php --version
Output:
PHP 7.2.7-0ubuntu0.18.04.2 (cli) (built: Jul 4 2018 16:55:24) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.7-0ubuntu0.18.04.2, Copyright (c) 1999-2018, by Zend Technologies
To check PHP scripts with Apache server, we want to create a information.Personal home page report inside the record root directory.
sudo nano /var/www/html/info.php
Paste the following PHP code into the file.
<?php phpinfo(); ?>
To store a document in Nano text editor, press Ctrl+O, then press Enter to verify. To go out, press Ctrl+X. Now inside the browser cope with bar, enter server-ip-cope with/data.Hypertext Preprocessor. Replace sever-ip-deal with with your real IP. If you comply with this educational to your nearby laptop, then type 127.0.Zero.1/data.Hypertext Preprocessor or localhost/data.Hypertext Preprocessor.
You should see your server’s PHP statistics. This approach PHP scripts can run well with Apache internet server.
How to Run PHP-FPM with Apache
There are basically two ways to run PHP code with Apache net server:
- Apache PHP module
- PHP-FPM.
In the above steps, the PHP7.2 module is used to handle PHP code, that’s normally nice. But in a few instances, you want to run PHP code with PHP-FPM instead. Here’s how.
Disable the Apache PHP7.2 module.
sudo a2dismod php7.2
Install PHP-FPM.
sudo apt install php7.2-fpm
Enable proxy_fcgi and setenvif module.
sudo a2enmod proxy_fcgi setenvif
Enable the /etc/apache2/conf-to be had/php7.2-fpm.Conf configuration report.
sudo a2enconf php7.2-fpm
Restart Apache for the changes to take effect.
sudo systemctl restart apache2
Now if you refresh the information.Hypertext Preprocessor web page for your browser, you will find that Server API is changed to FPM/FastCGI, which means Apache net server will skip PHP requests to PHP-FPM.
Congrats! You have effectively established LAMP stack (Apache, MariaDB and PHP7.2) on Ubuntu 18.04. For your server’s security, you have to delete data.Personal home page record now to prevent prying eyes.
sudo rm /var/www/html/info.php
So you simply found out a way to set up LAMP stack on Ubuntu 18.04. What next? You may additionally need to read:
- How to put in LEMP stack (Nginx, MariaDB, PHP7.2) on Ubuntu 18.04