{"id":2022,"date":"2019-01-12T11:12:29","date_gmt":"2019-01-12T08:12:29","guid":{"rendered":"http:\/\/kifarunix.com\/?p=2022"},"modified":"2019-01-12T11:13:50","modified_gmt":"2019-01-12T08:13:50","slug":"install-lamp-stack-on-debian-9","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/install-lamp-stack-on-debian-9\/","title":{"rendered":"Install LAMP Stack on Debian 9"},"content":{"rendered":"
Welcome to our guide on how to install LAMP Stack on Debian 9. LAMP Stack basically stands for Linux server, Apache web server, MariaDB\/MySQL relational database and PHP the server side scripting language. These all components are installed together on a server so that it can be able host websites and web applications.<\/p>\n
The first component of LAMP stack is the Linux server, which in this case is your Debian 9 server your are working on. Hence, run the command below to upgrade your system packages.<\/p>\n
apt update\r\napt upgrade<\/code><\/pre>\nOnce the upgrade is done, proceed as follows.<\/p>\n
Install Apache Web server<\/h3>\n
Apache web server packages are available on the default Debian 9 repositories. Hence, you can simply run the command below to install it.<\/p>\n
apt install apache2<\/code><\/pre>\nBy default, Apache is set to start after installation. It is also enabled to run in system boot. Verify by running the commands below;<\/p>\n
systemctl status apache2\r\n\u25cf<\/span> apache2.service - The Apache HTTP Server\r\n Loaded: loaded (\/lib\/systemd\/system\/apache2.service; enabled; vendor preset: enabled)\r\n Active: active (running)<\/span> since Sat 2019-01-12 01:36:47 EST; 2min 23s ago\r\n Main PID: 2915 (apache2)\r\n CGroup: \/system.slice\/apache2.service\r\n \u251c\u25002915 \/usr\/sbin\/apache2 -k start\r\n \u251c\u25002918 \/usr\/sbin\/apache2 -k start\r\n \u2514\u25002919 \/usr\/sbin\/apache2 -k start<\/code><\/pre>\n
systemctl list-unit-files --state=enabled | grep apache\r\napache2.service enabled<\/strong><\/code><\/pre>\nIf UFW is running, allow Apache through it. To open both TCP ports 80 and 443, simply run the command;<\/p>\n
ufw allow in \u201cWWW Full\u201d<\/code><\/pre>\n
Navigate to your and enter the IP address of your server,
http:\/\/server-IP<\/code> to verify that your web server is ready to server your web content. You should be welcomed by Apache2 Default Page.<\/p>\n
<\/a><\/p>\n
That is great. Apace web server is ready.<\/p>\n
Install MariaDB on Debian 9<\/h3>\n
MariaDB is a fork of the famous MySQL. As a result, MySQL defaults to MariaDB when installation is done. That is to say, even if you use the MySQL installation package,
mysql-server<\/code>, it will install MariaDB. Hence, it is a good idea to install MariaDB using its installation package,
mariadb-server<\/code>.<\/p>\n
apt install mariadb-server<\/code><\/pre>\n
Just like Apache, MariaDB is started and enabled to run on system boot after the installation is done.<\/p>\n
By default, MariaDB ships with a simple security script that can be run to remove anonymous database users, disallow remote root login, remove test databases in a move to perform preliminary database security. Hence run the script as shown below;<\/p>\n
mysql_secure_installation<\/code><\/pre>\nWhen the script is run, it prompts you to enter the current root password. Since there is none yet, press Enter to set a new root password.<\/p>\n
...\r\nEnter current password for root (enter for none): Press Enter<\/strong>\r\nOK, successfully used password, moving on...\r\n\r\nSetting the root password ensures that nobody can log into the MariaDB\r\nroot user without the proper authorisation.\r\n\r\nSet root password? [Y\/n] y<\/strong>\r\nNew password: P@SSW0rd<\/strong>\r\nRe-enter new password: P@SSW0rd<\/strong>\r\nPassword updated successfully!\r\nReloading privilege tables..\r\n ... Success!<\/code><\/pre>\nBy default, MariaDB ships with anonymous users that can login to the database without requiring a user account. This poses a security risk. Hence, remove these users.<\/p>\n
Remove anonymous users? [Y\/n] y<\/strong>\r\n ... Success!<\/code><\/pre>\nDisable remote root login such that root user can only login to database locally.<\/p>\n
Disallow root login remotely? [Y\/n] y<\/strong>\r\n ... Success!<\/code><\/pre>\nRemove the test database<\/p>\n
Remove test database and access to it? [Y\/n] y<\/strong>\r\n - Dropping test database...\r\n ... Success!\r\n - Removing privileges on test database...\r\n ... Success!<\/code><\/pre>\nNext, reload privilege tables to effect the changes we have made.<\/p>\n
Reload privilege tables now? [Y\/n] y<\/strong>\r\n ... Success!\r\n\r\nCleaning up...<\/code><\/pre>\nThe MariaDB is successfully set on Debian 9<\/p>\n
Install PHP on Debian 9<\/h3>\n
PHP being the server-side scripting language processes PHP code to generate dynamic web content. PHP and its extensions is available on the default Debian 9 repositories. Hence, run the command below to install PHP and other common PHP extensions.<\/p>\n
apt install php libapache2-mod-php php-mysql php-common php-gd php-mbstring php-curl php-xml<\/code><\/pre>\nNow that the installation is done, we need to configure Apache to be able to process PHP content. This can be done by editing the file,
\/etc\/apache2\/mods-available\/dir.conf<\/code><\/span> and adding
index.php<\/code> as the first value of the
DirectoryIndex<\/code> such that the configuration looks like;<\/p>\n
vim \/etc\/apache2\/mods-enabled\/dir.conf<\/code><\/pre>\n<IfModule mod_dir.c>\r\n DirectoryIndex index.php<\/strong> index.html index.cgi index.pl index.php index.xhtml index.htm\r\n<\/IfModule>\r\n\r\n# vim: syntax=apache ts=4 sw=4 sts=4 sr noet<\/code><\/pre>\nSave the file and quit.<\/p>\n
Run PHP tests to confirm the web server can server PHP content correctly.<\/p>\n
Create a PHP test page with
<?php phpinfo(); ?><\/code> content under the web server root directory.<\/p>\n
vim \/var\/www\/html\/test.php<\/code><\/pre>\nPlace the above content in this file. Save and quit.<\/p>\n
Restart Apache and navigate to the browser and enter the URL,
http:\/\/server-IP\/test.php<\/code>. You should see a PHP info page.<\/p>\n
systemctl restart apache2<\/code><\/pre>\n
<\/a><\/p>\n
That is beautiful. Upto that far, you have learnt how to Install LAMP Stack on Debian 9. But before we call it a day, it is wise to remove the PHP test page to avoid exposing your environment to the internet script-kiddies.<\/p>\n
rm -rf \/var\/www\/html\/test.php<\/code><\/pre>\nEnjoy.<\/p>\n
You can also check our previous articles on;<\/p>\n
\n
- How To Install LAMP (Linux, Apache, MySQL, PHP) Stack on Fedora 28\/29<\/a><\/li>\n
- How to Install LAMP Stack (Apache,MariaDB, PHP 7.2) on Ubuntu 18.04 LTS<\/a><\/li>\n
- How to Install LEMP (Nginx,MariaDB,PHP7.2) Stack on Fedora 28 \/ Fedora 29<\/a><\/li>\n
- How To Setup LEMP Stack (Nginx, MariaDB, PHP 7.2) on Ubuntu 18.04<\/a><\/li>\n
- Install Nginx, MySQL, PHP (FEMP) Stack on FreeBSD 12<\/a><\/li>\n
- Install Apache, MySQL, PHP (FAMP) Stack on FreeBSD 12<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"
Welcome to our guide on how to install LAMP Stack on Debian 9. LAMP Stack basically stands for Linux server, Apache web server, MariaDB\/MySQL relational<\/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":[287,204],"class_list":["post-2022","post","type-post","status-publish","format-standard","hentry","category-howtos","category-lamp-stack","tag-debian-9","tag-lamp-stack","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/2022"}],"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=2022"}],"version-history":[{"count":3,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/2022\/revisions"}],"predecessor-version":[{"id":2027,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/2022\/revisions\/2027"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=2022"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=2022"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=2022"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}