{"id":1062,"date":"2018-10-24T14:56:08","date_gmt":"2018-10-24T11:56:08","guid":{"rendered":"http:\/\/kifarunix.com\/?p=1062"},"modified":"2024-03-11T20:01:40","modified_gmt":"2024-03-11T17:01:40","slug":"how-to-install-lamp-stack-apachemariadb-php-7-2-on-ubuntu-18-04-lts","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/how-to-install-lamp-stack-apachemariadb-php-7-2-on-ubuntu-18-04-lts\/","title":{"rendered":"How to Install LAMP Stack (Apache,MariaDB, PHP 7.2) on Ubuntu 18.04 LTS"},"content":{"rendered":"\n

In this guide, you are going to learn how to Install LAMP Stack (Apache,MariaDB, PHP 7.2) on Ubuntu 18.04 LTS. LAMP Stack is a bundle of open-source softwares that is used to provide web services. It derives its name from the initials of its major components; the GNU\/L<\/strong>inux operating system, A<\/strong>pache HTTP Server, M<\/strong>ySQL relational database management system and P<\/strong>HP programming language.<\/p>\n\n\n\n

To kick off with, ensure that you have Ubuntu 18.04 server running so as to meet the first component of the L<\/strong>AMP stack.<\/p>\n\n\n\n

Update Ubuntu 18.04<\/h2>\n\n\n\n

Before you can proceed, run the following commands to update and upgrade you Ubuntu 18.04 server.<\/p>\n\n\n\n

apt update\napt upgrade<\/pre>\n\n\n\n

Once that is done, proceed as follows;<\/p>\n\n\n\n

Install Apache HTTP Server<\/h2>\n\n\n\n

Apache HTTP server is a free and open-source cross-platform web server. To install Apache, you can search for and install in the Software Centre, or by run the following command.<\/p>\n\n\n\n

apt install apache2 -y<\/pre>\n\n\n\n

Once the installation is done, enable Apache2 to run on system start up.<\/p>\n\n\n\n

systemctl enable apache2<\/pre>\n\n\n\n

Allow Apache through firewall if at all UFW firewall is running on your Ubuntu 18.04 server.<\/p>\n\n\n\n

Verify that UFW has an application profile for Apache;<\/p>\n\n\n\n

ufw app list<\/pre>\n\n\n\n
Available applications:\n  Apache\n  Apache Full\n  Apache Secure\n  Bind9\n  OpenSSH<\/pre>\n\n\n\n

If you intend to use both HTTP and HTTPS traffic, then allow Apache Full <\/strong>on UFW firewall.<\/p>\n\n\n\n

ufw allow \"Apache Full\"<\/pre>\n\n\n\n

Reload UFW firewall for the changes to take effect.<\/p>\n\n\n\n

ufw reload<\/pre>\n\n\n\n

To verify that you can access you web server, navigate to browser and enter your server IP address as in http:\/\/IP-Address\/.<\/strong><\/p>\n\n\n\n

If all is well, you should see Apache Default Page as shown below.<\/p>\n\n\n\n

\"apache-default-page\"<\/a>
apache-default-page<\/figcaption><\/figure>\n\n\n\n

Install MySQL<\/h2>\n\n\n\n

MySQL is an open-source relational database management system. In this tutorial, we are going to install MariaDB, a drop-in replacement for MySQL. To install MariaDB, run the following command; on your Ubuntu 18.04 server.<\/p>\n\n\n\n

apt install mariadb-server -y<\/pre>\n\n\n\n

If you would like to use MySQL instead, run the command below to install it.<\/p>\n\n\n\n

apt install mysql-server -y<\/pre>\n\n\n\n

Once the installation is done, you need to secure your DB server. Therefore, run the security script, mysql_secure_installation<\/strong>, that comes pre-installed with MariaDB, set the root password and secure your DB.<\/p>\n\n\n\n

mysql_secure_installation<\/pre>\n\n\n\n
...output snipped...<\/strong>\nEnter current password for root (enter for none): ENTER<\/strong>\nOK, successfully used password, moving on...\n\nSetting the root password ensures that nobody can log into the MariaDB\nroot user without the proper authorisation.\n\nSet root password? [Y\/n] y<\/strong>\nNew password: ENTER YOUR PASSWORD<\/strong>\nRe-enter new password: CONFIRM YOUR PASSWORD<\/strong>\nPassword updated successfully!\nReloading privilege tables..\n ... Success!\n\n\nBy default, a MariaDB installation has an anonymous user, allowing anyone\nto log into MariaDB without having to have a user account created for\nthem.  This is intended only for testing, and to make the installation\ngo a bit smoother.  You should remove them before moving into a\nproduction environment.\n\nRemove anonymous users? [Y\/n] y<\/strong>\n ... Success!\n\nNormally, root should only be allowed to connect from 'localhost'.  This\nensures that someone cannot guess at the root password from the network.\n\nDisallow root login remotely? [Y\/n] y<\/strong>\n ... Success!\n\nBy default, MariaDB comes with a database named 'test' that anyone can\naccess.  This is also intended only for testing, and should be removed\nbefore moving into a production environment.\n\nRemove test database and access to it? [Y\/n] y<\/strong>\n - Dropping test database...\n ... Success!\n - Removing privileges on test database...\n ... Success!\n\nReloading the privilege tables will ensure that all changes made so far\nwill take effect immediately.\n\nReload privilege tables now? [Y\/n] y<\/strong>\n ... Success!\n\nCleaning up...\n\nAll done!  If you've completed all of the above steps, your MariaDB\ninstallation should now be secure.\n\nThanks for using MariaDB!<\/pre>\n\n\n\n

Note, you can press Enter<\/strong> to accept the default the default Y<\/strong>es.<\/p>\n\n\n\n

Install PHP<\/h2>\n\n\n\n

PHP, Hypertext Preprocessor, is a server-side scripting language designed for Web development, but also used as a general-purpose programming language. Run the following command to install PHP and PHP modules for Apache and MySQL.<\/p>\n\n\n\n

apt install php libapache2-mod-php php-mysql -y<\/code><\/pre>\n\n\n\n

In case you want to install more PHP modules, you can just search the module you want from Ubuntu repos and install it as shown below.<\/p>\n\n\n\n

apt-cache search php- | more<\/pre>\n\n\n\n
libnet-libidn-perl - Perl bindings for GNU Libidn\nphp-all-dev - package depending on all supported PHP development packages\nphp-cgi - server-side, HTML-embedded scripting language (CGI binary) (default)\nphp-cli - command-line interpreter for the PHP scripting language (default)\nphp-common - Common files for PHP packages\nphp-curl - CURL module for PHP [default]\nphp-dev - Files for PHP module development (default)\nphp-gd - GD module for PHP [default]\nphp-gmp - GMP module for PHP [default]\nphp-ldap - LDAP module for PHP [default]\n--More--<\/pre>\n\n\n\n

So if you want to install GD module for example, run the command below;<\/p>\n\n\n\n

apt install php-gd -y<\/pre>\n\n\n\n

Once the installation is done, you need to test that PHP is actually working. Therefore, create a test php file for example, test.php<\/strong> under Apache root document folder, \/var\/www\/html<\/strong> and put the following content.<\/p>\n\n\n\n

vim \/var\/www\/html\/test.php<\/pre>\n\n\n\n
<?php\nphpinfo();\n?><\/pre>\n\n\n\n

After that, save the file and quit. Restart Apache service to effect the changes.<\/p>\n\n\n\n

systemctl restart apache2<\/pre>\n\n\n\n

Now, to test PHP processing, navigate to your browser and enter the following URL in your address bar.<\/p>\n\n\n\n

http:\/\/your-server-IP\/test.php<\/strong><\/pre>\n\n\n\n

You should be able to see a page similar to the one shown below.<\/p>\n\n\n\n

\"php-test-page\"<\/a>
php-test-page<\/figcaption><\/figure>\n\n\n\n

You can check the version of the PHP installed with the following command;<\/p>\n\n\n\n

php -v<\/strong>\nPHP 7.2.10<\/strong>-0ubuntu0.18.04.1 (cli) (built: Sep 13 2018 13:45:02) ( NTS )\nCopyright (c) 1997-2018 The PHP Group\nZend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies\n    with Zend OPcache v7.2.10-0ubuntu0.18.04.1, Copyright (c) 1999-2018, by Zend Technologies<\/pre>\n\n\n\n

Now that everything seems fine, remove the PHP test configuration file to avoid creating an attack surface.<\/p>\n\n\n\n

rm -rf \/var\/www\/html\/test.php<\/pre>\n\n\n\n

Big up yourself! You have successfully installed and configured a LAMP stack on Ubuntu 18.04 (LTS).<\/p>\n\n\n\n

Related Tutorials;<\/p>\n\n\n\n

Install LAMP Stack with MariaDB 10 on Debian 10 Buster<\/a><\/p>\n\n\n\n

Install LAMP Stack on Fedora 30<\/a><\/p>\n\n\n\n

Install LAMP Stack on Debian 9<\/a><\/p>\n\n\n\n

How To Install LAMP (Linux, Apache, MySQL, PHP) Stack on Fedora 28\/29<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"

In this guide, you are going to learn how to Install LAMP Stack (Apache,MariaDB, PHP 7.2) on Ubuntu 18.04 LTS. LAMP Stack is a bundle<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[121,201],"tags":[202,204,135,203],"class_list":["post-1062","post","type-post","status-publish","format-standard","hentry","category-howtos","category-lamp-stack","tag-apache","tag-lamp-stack","tag-mysql","tag-php","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/1062"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=1062"}],"version-history":[{"count":8,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/1062\/revisions"}],"predecessor-version":[{"id":21028,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/1062\/revisions\/21028"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=1062"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=1062"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=1062"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}