{"id":526,"date":"2020-01-02T23:59:18","date_gmt":"2020-01-02T23:59:18","guid":{"rendered":"http:\/\/blog.um-palembang.ac.id\/sayfudin\/?p=526"},"modified":"2020-01-02T23:59:18","modified_gmt":"2020-01-02T23:59:18","slug":"install-linux-apache-mysql-php-lamp-on-ubuntu","status":"publish","type":"post","link":"http:\/\/blog.um-palembang.ac.id\/sayfudin\/install-linux-apache-mysql-php-lamp-on-ubuntu\/","title":{"rendered":"Install Linux, Apache, MySQL, PHP (LAMP) on Ubuntu"},"content":{"rendered":"<div class=\"content-body tutorial-content\" data-growable-markdown=\"\">\n<h3 id=\"introduction\">Introduction<\/h3>\n<p>A \u201cLAMP\u201d stack is a group of open source software that is typically installed together to enable a server to host dynamic websites and web apps. This term is actually an acronym which represents the <strong>L<\/strong>inux operating system, with the <strong>A<\/strong>pache web server. The site data is stored in a <strong>M<\/strong>ySQL database, and dynamic content is processed by <strong>P<\/strong>HP.<\/p>\n<p>In this guide, we\u2019ll get a LAMP stack installed on an Ubuntu 16.04 Droplet. Ubuntu will fulfill our first requirement: a Linux operating system.<\/p>\n<p><a name=\"prerequisites\" data-unique=\"prerequisites\"><\/a><a name=\"prerequisites\" data-unique=\"prerequisites\"><\/a><\/p>\n<h2 id=\"prerequisites\">Prerequisites<\/h2>\n<p>Before you begin with this guide, you should have a separate, non-root user account with <code>sudo<\/code> privileges set up on your server. You can learn how to do this by completing steps 1-4 in the <a href=\"https:\/\/www.digitalocean.com\/community\/articles\/initial-server-setup-with-ubuntu-16-04\">initial server setup for Ubuntu 16.04<\/a>.<\/p>\n<p><a name=\"step-1-install-apache-and-allow-in-firewall\" data-unique=\"step-1-install-apache-and-allow-in-firewall\"><\/a><a name=\"step-1-install-apache-and-allow-in-firewall\" data-unique=\"step-1-install-apache-and-allow-in-firewall\"><\/a><\/p>\n<h2 id=\"step-1-install-apache-and-allow-in-firewall\">Step 1: Install Apache and Allow in Firewall<\/h2>\n<p>The Apache web server is among the most popular web servers in the world. It\u2019s well-documented, and has been in wide use for much of the history of the web, which makes it a great default choice for hosting a website.<\/p>\n<p>We can install Apache easily using Ubuntu\u2019s package manager, <code>apt<\/code>. A package manager allows us to install most software pain-free from a repository maintained by Ubuntu. You can learn more about <a href=\"https:\/\/www.digitalocean.com\/community\/articles\/how-to-manage-packages-in-ubuntu-and-debian-with-apt-get-apt-cache\">how to use <code>apt<\/code><\/a> here.<\/p>\n<p>For our purposes, we can get started by typing these commands:<\/p>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<ul class=\"prefixed\">\n<li class=\"line\">sudo apt-get update<\/li>\n<li class=\"line\">sudo apt-get install apache2<\/li>\n<\/ul>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<p>Since we are using a <code>sudo<\/code> command, these operations get executed with root privileges. It will ask you for your regular user\u2019s password to verify your intentions.<\/p>\n<p>Once you\u2019ve entered your password, <code>apt<\/code> will tell you which packages it plans to install and how much extra disk space they\u2019ll take up. Press <strong>Y<\/strong> and hit <strong>Enter<\/strong> to continue, and the installation will proceed.<\/p>\n<h3 id=\"set-global-servername-to-suppress-syntax-warnings\">Set Global ServerName to Suppress Syntax Warnings<\/h3>\n<p>Next, we will add a single line to the <code>\/etc\/apache2\/apache2.conf<\/code> file to suppress a warning message. While harmless, if you do not set <code>ServerName<\/code> globally, you will receive the following warning when checking your Apache configuration for syntax errors:<\/p>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<ul class=\"prefixed\">\n<li class=\"line\">sudo apache2ctl configtest<\/li>\n<\/ul>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<pre class=\"code-pre \"><code><\/code><\/pre>\n<div class=\"secondary-code-label \" title=\"Output\">Output<\/div>\n<pre class=\"code-pre \"><code><span class=\"highlight\">AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message<\/span>\r\nSyntax OK\r\n<\/code><\/pre>\n<p>Open up the main configuration file with your text edit:<\/p>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<ul class=\"prefixed\">\n<li class=\"line\">sudo nano \/etc\/apache2\/apache2.conf<\/li>\n<\/ul>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<p>Inside, at the bottom of the file, add a <code>ServerName<\/code> directive, pointing to your primary domain name. If you do not have a domain name associated with your server, you can use your server\u2019s public IP address:<\/p>\n<div class=\"code-label notes-and-warnings note\" title=\"Note\">Note<\/div>\n<p><span class=\"note\"> If you don\u2019t know your server\u2019s IP address, skip down to the section on <a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-16-04#how-to-find-your-server-39-s-public-ip-address\">how to find your server\u2019s public IP address<\/a> to find it.<br \/>\n<\/span><\/p>\n<div class=\"code-label \" title=\"\/etc\/apache2\/apache2.conf\">\/etc\/apache2\/apache2.conf<\/div>\n<pre class=\"code-pre \"><code>. . .\r\nServerName <span class=\"highlight\">server_domain_or_IP<\/span>\r\n<\/code><\/pre>\n<p>Save and close the file when you are finished.<\/p>\n<p>Next, check for syntax errors by typing:<\/p>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<ul class=\"prefixed\">\n<li class=\"line\">sudo apache2ctl configtest<\/li>\n<\/ul>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<p>Since we added the global <code>ServerName<\/code> directive, all you should see is:<\/p>\n<pre class=\"code-pre \"><code><\/code><\/pre>\n<div class=\"secondary-code-label \" title=\"Output\">Output<\/div>\n<pre class=\"code-pre \"><code>Syntax OK\r\n<\/code><\/pre>\n<p>Restart Apache to implement your changes:<\/p>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<ul class=\"prefixed\">\n<li class=\"line\">sudo systemctl restart apache2<\/li>\n<\/ul>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<p>You can now begin adjusting the firewall.<\/p>\n<h3 id=\"adjust-the-firewall-to-allow-web-traffic\">Adjust the Firewall to Allow Web Traffic<\/h3>\n<p>Next, assuming that you have followed the initial server setup instructions to enable the UFW firewall, make sure that your firewall allows HTTP and HTTPS traffic. You can make sure that UFW has an application profile for Apache like so:<\/p>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<ul class=\"prefixed\">\n<li class=\"line\">sudo ufw app list<\/li>\n<\/ul>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<pre class=\"code-pre \"><code><\/code><\/pre>\n<div class=\"secondary-code-label \" title=\"Output\">Output<\/div>\n<pre class=\"code-pre \"><code>Available applications:\r\n  <span class=\"highlight\">Apache<\/span>\r\n  <span class=\"highlight\">Apache Full<\/span>\r\n  <span class=\"highlight\">Apache Secure<\/span>\r\n  OpenSSH\r\n<\/code><\/pre>\n<p>If you look at the <code>Apache Full<\/code> profile, it should show that it enables traffic to ports 80 and 443:<\/p>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<ul class=\"prefixed\">\n<li class=\"line\">sudo ufw app info &#8220;Apache Full&#8221;<\/li>\n<\/ul>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<pre class=\"code-pre \"><code><\/code><\/pre>\n<div class=\"secondary-code-label \" title=\"Output\">Output<\/div>\n<pre class=\"code-pre \"><code>Profile: Apache Full\r\nTitle: Web Server (HTTP,HTTPS)\r\nDescription: Apache v2 is the next generation of the omnipresent Apache web\r\nserver.\r\n\r\nPorts:\r\n  <span class=\"highlight\">80,443\/tcp<\/span>\r\n<\/code><\/pre>\n<p>Allow incoming traffic for this profile:<\/p>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<ul class=\"prefixed\">\n<li class=\"line\">sudo ufw allow in &#8220;Apache Full&#8221;<\/li>\n<\/ul>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<p>You can do a spot check right away to verify that everything went as planned by visiting your server\u2019s public IP address in your web browser (see the note under the next heading to find out what your public IP address is if you do not have this information already):<\/p>\n<pre class=\"code-pre \"><code>http:\/\/<span class=\"highlight\">your_server_IP_address<\/span>\r\n<\/code><\/pre>\n<p>You will see the default Ubuntu 16.04 Apache web page, which is there for informational and testing purposes. It should look something like this:<\/p>\n<p class=\"growable\"><img decoding=\"async\" src=\"http:\/\/assets.digitalocean.com\/articles\/how-to-install-lamp-ubuntu-16\/small_apache_default.png\" alt=\"Ubuntu 16.04 Apache default\" \/><\/p>\n<p>If you see this page, then your web server is now correctly installed and accessible through your firewall.<\/p>\n<h3 id=\"how-to-find-your-server-39-s-public-ip-address\">How To Find your Server\u2019s Public IP Address<\/h3>\n<p>If you do not know what your server\u2019s public IP address is, there are a number of ways you can find it. Usually, this is the address you use to connect to your server through SSH.<\/p>\n<p>From the command line, you can find this a few ways. First, you can use the <code>iproute2<\/code> tools to get your address by typing this:<\/p>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<ul class=\"prefixed\">\n<li class=\"line\">ip addr show eth0 | grep inet | awk &#8216;{ print $2; }&#8217; | sed &#8216;s\/\\\/.*$\/\/&#8217;<\/li>\n<\/ul>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<p>This will give you two or three lines back. They are all correct addresses, but your computer may only be able to use one of them, so feel free to try each one.<\/p>\n<p>An alternative method is to use the <code>curl<\/code> utility to contact an outside party to tell you how <em>it<\/em> sees your server. You can do this by asking a specific server what your IP address is:<\/p>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<ul class=\"prefixed\">\n<li class=\"line\">sudo apt-get install curl<\/li>\n<li class=\"line\">curl http:\/\/icanhazip.com<\/li>\n<\/ul>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<p>Regardless of the method you use to get your IP address, you can type it into your web browser\u2019s address bar to get to your server.<\/p>\n<p><a name=\"step-2-install-mysql\" data-unique=\"step-2-install-mysql\"><\/a><a name=\"step-2-install-mysql\" data-unique=\"step-2-install-mysql\"><\/a><\/p>\n<h2 id=\"step-2-install-mysql\">Step 2: Install MySQL<\/h2>\n<p>Now that we have our web server up and running, it is time to install MySQL. MySQL is a database management system. Basically, it will organize and provide access to databases where our site can store information.<\/p>\n<p>Again, we can use <code>apt<\/code> to acquire and install our software. This time, we\u2019ll also install some other \u201chelper\u201d packages that will assist us in getting our components to communicate with each other:<\/p>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<ul class=\"prefixed\">\n<li class=\"line\">sudo apt-get install mysql-server<\/li>\n<\/ul>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<p><span class=\"note\"><strong>Note<\/strong>: In this case, you do not have to run <code>sudo apt-get update<\/code> prior to the command. This is because we recently ran it in the commands above to install Apache. The package index on our computer should already be up-to-date.<br \/>\n<\/span><\/p>\n<p>Again, you will be shown a list of the packages that will be installed, along with the amount of disk space they\u2019ll take up. Enter <strong>Y<\/strong> to continue.<\/p>\n<p>During the installation, your server will ask you to select and confirm a password for the MySQL \u201croot\u201d user. This is an administrative account in MySQL that has increased privileges. Think of it as being similar to the root account for the server itself (the one you are configuring now is a MySQL-specific account, however). Make sure this is a strong, unique password, and do not leave it blank.<\/p>\n<p>When the installation is complete, we want to run a simple security script that will remove some dangerous defaults and lock down access to our database system a little bit. Start the interactive script by running:<\/p>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<ul class=\"prefixed\">\n<li class=\"line\">mysql_secure_installation<\/li>\n<\/ul>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<p>You will be asked to enter the password you set for the MySQL root account. Next, you will be asked if you want to configure the <code>VALIDATE PASSWORD PLUGIN<\/code>.<\/p>\n<p><span class=\"warning\"><strong>Warning:<\/strong> Enabling this feature is something of a judgment call. If enabled, passwords which don\u2019t match the specified criteria will be rejected by MySQL with an error. This will cause issues if you use a weak password in conjunction with software which automatically configures MySQL user credentials, such as the Ubuntu packages for phpMyAdmin. It is safe to leave validation disabled, but you should always use strong, unique passwords for database credentials.<br \/>\n<\/span><\/p>\n<p>Answer <strong>y<\/strong> for yes, or anything else to continue without enabling.<\/p>\n<pre class=\"code-pre \"><code>VALIDATE PASSWORD PLUGIN can be used to test passwords\r\nand improve security. It checks the strength of password\r\nand allows the users to set only those passwords which are\r\nsecure enough. Would you like to setup VALIDATE PASSWORD plugin?\r\n\r\nPress y|Y for Yes, any other key for No:\r\n<\/code><\/pre>\n<p>You\u2019ll be asked to select a level of password validation. Keep in mind that if you enter <strong>2<\/strong>, for the strongest level, you will receive errors when attempting to set any password which does not contain numbers, upper and lowercase letters, and special characters, or which is based on common dictionary words.<\/p>\n<pre class=\"code-pre \"><code>There are three levels of password validation policy:\r\n\r\nLOW    Length &gt;= 8\r\nMEDIUM Length &gt;= 8, numeric, mixed case, and special characters\r\nSTRONG Length &gt;= 8, numeric, mixed case, special characters and dictionary                  file\r\n\r\nPlease enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: <span class=\"highlight\">1<\/span>\r\n<\/code><\/pre>\n<p>If you enabled password validation, you\u2019ll be shown a password strength for the existing root password, and asked you if you want to change that password. If you are happy with your current password, enter <strong>n<\/strong> for \u201cno\u201d at the prompt:<\/p>\n<pre class=\"code-pre \"><code>Using existing password for root.\r\n\r\nEstimated strength of the password: <span class=\"highlight\">100<\/span>\r\nChange the password for root ? ((Press y|Y for Yes, any other key for No) : <span class=\"highlight\">n<\/span>\r\n<\/code><\/pre>\n<p>For the rest of the questions, you should press <strong>Y<\/strong> and hit the <strong>Enter<\/strong> key at each prompt. This will remove some anonymous users and the test database, disable remote root logins, and load these new rules so that MySQL immediately respects the changes we have made.<\/p>\n<p>At this point, your database system is now set up and we can move on.<\/p>\n<p><a name=\"step-3-install-php\" data-unique=\"step-3-install-php\"><\/a><a name=\"step-3-install-php\" data-unique=\"step-3-install-php\"><\/a><\/p>\n<h2 id=\"step-3-install-php\">Step 3: Install PHP<\/h2>\n<p>PHP is the component of our setup that will process code to display dynamic content. It can run scripts, connect to our MySQL databases to get information, and hand the processed content over to our web server to display.<\/p>\n<p>We can once again leverage the <code>apt<\/code> system to install our components. We\u2019re going to include some helper packages as well, so that PHP code can run under the Apache server and talk to our MySQL database:<\/p>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<ul class=\"prefixed\">\n<li class=\"line\">sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql<\/li>\n<\/ul>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<p>This should install PHP without any problems. We\u2019ll test this in a moment.<\/p>\n<p>In most cases, we\u2019ll want to modify the way that Apache serves files when a directory is requested. Currently, if a user requests a directory from the server, Apache will first look for a file called <code>index.html<\/code>. We want to tell our web server to prefer PHP files, so we\u2019ll make Apache look for an <code>index.php<\/code> file first.<\/p>\n<p>To do this, type this command to open the <code>dir.conf<\/code> file in a text editor with root privileges:<\/p>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<ul class=\"prefixed\">\n<li class=\"line\">sudo nano \/etc\/apache2\/mods-enabled\/dir.conf<\/li>\n<\/ul>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<p>It will look like this:<\/p>\n<div class=\"code-label \" title=\"\/etc\/apache2\/mods-enabled\/dir.conf\">\/etc\/apache2\/mods-enabled\/dir.conf<\/div>\n<pre class=\"code-pre \"><code>&lt;IfModule mod_dir.c&gt;\r\n    DirectoryIndex index.html index.cgi index.pl <span class=\"highlight\">index.php<\/span> index.xhtml index.htm\r\n&lt;\/IfModule&gt;\r\n<\/code><\/pre>\n<p>We want to move the PHP index file highlighted above to the first position after the <code>DirectoryIndex<\/code> specification, like this:<\/p>\n<div class=\"code-label \" title=\"\/etc\/apache2\/mods-enabled\/dir.conf\">\/etc\/apache2\/mods-enabled\/dir.conf<\/div>\n<pre class=\"code-pre \"><code>&lt;IfModule mod_dir.c&gt;\r\n    DirectoryIndex <span class=\"highlight\">index.php<\/span> index.html index.cgi index.pl index.xhtml index.htm\r\n&lt;\/IfModule&gt;\r\n<\/code><\/pre>\n<p>When you are finished, save and close the file by pressing <strong>Ctrl-X<\/strong>. You\u2019ll have to confirm the save by typing <strong>Y<\/strong> and then hit <strong>Enter<\/strong> to confirm the file save location.<\/p>\n<p>After this, we need to restart the Apache web server in order for our changes to be recognized. You can do this by typing this:<\/p>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<ul class=\"prefixed\">\n<li class=\"line\">sudo systemctl restart apache2<\/li>\n<\/ul>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<p>We can also check on the status of the <code>apache2<\/code> service using <code>systemctl<\/code>:<\/p>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<ul class=\"prefixed\">\n<li class=\"line\">sudo systemctl status apache2<\/li>\n<\/ul>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<pre class=\"code-pre \"><code><\/code><\/pre>\n<div class=\"secondary-code-label \" title=\"Sample Output\">Sample Output<\/div>\n<pre class=\"code-pre \"><code>\u25cf apache2.service - LSB: Apache2 web server\r\n   Loaded: loaded (\/etc\/init.d\/apache2; bad; vendor preset: enabled)\r\n  Drop-In: \/lib\/systemd\/system\/apache2.service.d\r\n           \u2514\u2500apache2-systemd.conf\r\n   Active: active (running) since Wed 2016-04-13 14:28:43 EDT; 45s ago\r\n     Docs: man:systemd-sysv-generator(8)\r\n  Process: 13581 ExecStop=\/etc\/init.d\/apache2 stop (code=exited, status=0\/SUCCESS)\r\n  Process: 13605 ExecStart=\/etc\/init.d\/apache2 start (code=exited, status=0\/SUCCESS)\r\n    Tasks: 6 (limit: 512)\r\n   CGroup: \/system.slice\/apache2.service\r\n           \u251c\u250013623 \/usr\/sbin\/apache2 -k start\r\n           \u251c\u250013626 \/usr\/sbin\/apache2 -k start\r\n           \u251c\u250013627 \/usr\/sbin\/apache2 -k start\r\n           \u251c\u250013628 \/usr\/sbin\/apache2 -k start\r\n           \u251c\u250013629 \/usr\/sbin\/apache2 -k start\r\n           \u2514\u250013630 \/usr\/sbin\/apache2 -k start\r\n\r\nApr 13 14:28:42 ubuntu-16-lamp systemd[1]: Stopped LSB: Apache2 web server.\r\nApr 13 14:28:42 ubuntu-16-lamp systemd[1]: Starting LSB: Apache2 web server...\r\nApr 13 14:28:42 ubuntu-16-lamp apache2[13605]:  * Starting Apache httpd web server apache2\r\nApr 13 14:28:42 ubuntu-16-lamp apache2[13605]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerNam\r\nApr 13 14:28:43 ubuntu-16-lamp apache2[13605]:  *\r\nApr 13 14:28:43 ubuntu-16-lamp systemd[1]: Started LSB: Apache2 web server.\r\n<\/code><\/pre>\n<h3 id=\"install-php-modules\">Install PHP Modules<\/h3>\n<p>To enhance the functionality of PHP, we can optionally install some additional modules.<\/p>\n<p>To see the available options for PHP modules and libraries, you can pipe the results of <code>apt-cache search<\/code> into <code>less<\/code>, a pager which lets you scroll through the output of other commands:<\/p>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<ul class=\"prefixed\">\n<li class=\"line\">apt-cache search php- | less<\/li>\n<\/ul>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<p>Use the arrow keys to scroll up and down, and <strong>q<\/strong> to quit.<\/p>\n<p>The results are all optional components that you can install. It will give you a short description for each:<\/p>\n<pre class=\"code-pre \"><code>libnet-libidn-perl - Perl bindings for GNU Libidn\r\nphp-all-dev - package depending on all supported PHP development packages\r\nphp-cgi - server-side, HTML-embedded scripting language (CGI binary) (default)\r\nphp-cli - command-line interpreter for the PHP scripting language (default)\r\nphp-common - Common files for PHP packages\r\nphp-curl - CURL module for PHP [default]\r\nphp-dev - Files for PHP module development (default)\r\nphp-gd - GD module for PHP [default]\r\nphp-gmp - GMP module for PHP [default]\r\n\u2026\r\n:\r\n<\/code><\/pre>\n<p>To get more information about what each module does, you can either search the internet, or you can look at the long description of the package by typing:<\/p>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<ul class=\"prefixed\">\n<li class=\"line\">apt-cache show <span class=\"highlight\">package_name<\/span><\/li>\n<\/ul>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<p>There will be a lot of output, with one field called <code>Description-en<\/code> which will have a longer explanation of the functionality that the module provides.<\/p>\n<p>For example, to find out what the <code>php-cli<\/code> module does, we could type this:<\/p>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<ul class=\"prefixed\">\n<li class=\"line\">apt-cache show php-cli<\/li>\n<\/ul>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<p>Along with a large amount of other information, you\u2019ll find something that looks like this:<\/p>\n<pre class=\"code-pre \"><code><\/code><\/pre>\n<div class=\"secondary-code-label \" title=\"Output\">Output<\/div>\n<pre class=\"code-pre \"><code>\u2026\r\nDescription-en: command-line interpreter for the PHP scripting language (default)\r\n This package provides the \/usr\/bin\/php command interpreter, useful for\r\n testing PHP scripts from a shell or performing general shell scripting tasks.\r\n .\r\n PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used\r\n open source general-purpose scripting language that is especially suited\r\n for web development and can be embedded into HTML.\r\n .\r\n This package is a dependency package, which depends on Debian's default\r\n PHP version (currently 7.0).\r\n\u2026\r\n<\/code><\/pre>\n<p>If, after researching, you decide you would like to install a package, you can do so by using the <code>apt-get install<\/code> command like we have been doing for our other software.<\/p>\n<p>If we decided that <code>php-cli<\/code> is something that we need, we could type:<\/p>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<ul class=\"prefixed\">\n<li class=\"line\">sudo apt-get install php-cli<\/li>\n<\/ul>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<p>If you want to install more than one module, you can do that by listing each one, separated by a space, following the <code>apt-get install<\/code> command, like this:<\/p>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<ul class=\"prefixed\">\n<li class=\"line\">sudo apt-get install <span class=\"highlight\">package1<\/span> <span class=\"highlight\">package2<\/span> <span class=\"highlight\">&#8230;<\/span><\/li>\n<\/ul>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<p>At this point, your LAMP stack is installed and configured. We should still test out our PHP though.<\/p>\n<p><a name=\"step-4-test-php-processing-on-your-web-server\" data-unique=\"step-4-test-php-processing-on-your-web-server\"><\/a><a name=\"step-4-test-php-processing-on-your-web-server\" data-unique=\"step-4-test-php-processing-on-your-web-server\"><\/a><\/p>\n<h2 id=\"step-4-test-php-processing-on-your-web-server\">Step 4: Test PHP Processing on your Web Server<\/h2>\n<p>In order to test that our system is configured properly for PHP, we can create a very basic PHP script.<\/p>\n<p>We will call this script <code>info.php<\/code>. In order for Apache to find the file and serve it correctly, it must be saved to a very specific directory, which is called the \u201cweb root\u201d.<\/p>\n<p>In Ubuntu 16.04, this directory is located at <code>\/var\/www\/html\/<\/code>. We can create the file at that location by typing:<\/p>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<ul class=\"prefixed\">\n<li class=\"line\">sudo nano \/var\/www\/html\/info.php<\/li>\n<\/ul>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<p>This will open a blank file. We want to put the following text, which is valid PHP code, inside the file:<\/p>\n<div class=\"code-label \" title=\"info.php\">info.php<\/div>\n<pre class=\"code-pre \"><code>&lt;?php\r\nphpinfo();\r\n?&gt;\r\n<\/code><\/pre>\n<p>When you are finished, save and close the file.<\/p>\n<p>Now we can test whether our web server can correctly display content generated by a PHP script. To try this out, we just have to visit this page in our web browser. You\u2019ll need your server\u2019s public IP address again.<\/p>\n<p>The address you want to visit will be:<\/p>\n<pre class=\"code-pre \"><code>http:\/\/<span class=\"highlight\">your_server_IP_address<\/span>\/info.php\r\n<\/code><\/pre>\n<p>The page that you come to should look something like this:<\/p>\n<p class=\"growable\"><img decoding=\"async\" src=\"https:\/\/assets.digitalocean.com\/articles\/how-to-install-lamp-ubuntu-16\/small_php_info.png\" alt=\"Ubuntu 16.04 default PHP info\" \/><\/p>\n<p>This page basically gives you information about your server from the perspective of PHP. It is useful for debugging and to ensure that your settings are being applied correctly.<\/p>\n<p>If this was successful, then your PHP is working as expected.<\/p>\n<p>You probably want to remove this file after this test because it could actually give information about your server to unauthorized users. To do this, you can type this:<\/p>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<ul class=\"prefixed\">\n<li class=\"line\">sudo rm \/var\/www\/html\/info.php<\/li>\n<\/ul>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<p>You can always recreate this page if you need to access the information again later.<\/p>\n<p><a name=\"conclusion\" data-unique=\"conclusion\"><\/a><a name=\"conclusion\" data-unique=\"conclusion\"><\/a><\/p>\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>Now that you have a LAMP stack installed, you have many choices for what to do next. Basically, you\u2019ve installed a platform that will allow you to install most kinds of websites and web software on your server.<\/p>\n<p>As an immediate next step, you should ensure that connections to your web server are secured, by serving them via HTTPS. The easiest option here is to <a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-secure-apache-with-let-s-encrypt-on-ubuntu-16-04\">use Let\u2019s Encrypt<\/a> to secure your site with a free TLS\/SSL certificate.<\/p>\n<p>Some other popular options are:<\/p>\n<ul>\n<li><a href=\"https:\/\/www.digitalocean.com\/community\/articles\/how-to-install-wordpress-on-ubuntu-14-04\">Install WordPress<\/a> the most popular content management system on the internet.<\/li>\n<li><a href=\"https:\/\/www.digitalocean.com\/community\/articles\/how-to-install-and-secure-phpmyadmin-on-ubuntu-12-04\">Set Up PHPMyAdmin<\/a> to help manage your MySQL databases from web browser.<\/li>\n<li><a href=\"https:\/\/www.digitalocean.com\/community\/articles\/a-basic-mysql-tutorial\">Learn more about MySQL<\/a> to manage your databases.<\/li>\n<li><a href=\"https:\/\/www.digitalocean.com\/community\/articles\/how-to-use-sftp-to-securely-transfer-files-with-a-remote-server\">Learn how to use SFTP<\/a> to transfer files to and from your server.<\/li>\n<\/ul>\n<p><strong>Note<\/strong>: By <a href=\"https:\/\/www.digitalocean.com\/community\/users\/bpb\">Brennen Bearnes<\/a> on https:\/\/www.digitalocean.com<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Introduction A \u201cLAMP\u201d stack is a group of open source software that is typically installed together to enable a server to host dynamic websites and web apps. This term is actually an acronym which represents the Linux operating system, with the Apache web server. The site data is stored in a MySQL database, and dynamic [&hellip;]<\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/blog.um-palembang.ac.id\/sayfudin\/wp-json\/wp\/v2\/posts\/526"}],"collection":[{"href":"http:\/\/blog.um-palembang.ac.id\/sayfudin\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.um-palembang.ac.id\/sayfudin\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.um-palembang.ac.id\/sayfudin\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.um-palembang.ac.id\/sayfudin\/wp-json\/wp\/v2\/comments?post=526"}],"version-history":[{"count":1,"href":"http:\/\/blog.um-palembang.ac.id\/sayfudin\/wp-json\/wp\/v2\/posts\/526\/revisions"}],"predecessor-version":[{"id":527,"href":"http:\/\/blog.um-palembang.ac.id\/sayfudin\/wp-json\/wp\/v2\/posts\/526\/revisions\/527"}],"wp:attachment":[{"href":"http:\/\/blog.um-palembang.ac.id\/sayfudin\/wp-json\/wp\/v2\/media?parent=526"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.um-palembang.ac.id\/sayfudin\/wp-json\/wp\/v2\/categories?post=526"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.um-palembang.ac.id\/sayfudin\/wp-json\/wp\/v2\/tags?post=526"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}