{"id":1172,"date":"2015-09-08T21:25:49","date_gmt":"2015-09-08T20:25:49","guid":{"rendered":"http:\/\/www.venco.com.pl\/~cozy\/blog\/?p=1172"},"modified":"2015-09-08T21:25:49","modified_gmt":"2015-09-08T20:25:49","slug":"how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-14-04","status":"publish","type":"post","link":"http:\/\/u239160.webh.me\/jakisproblem.pl\/index.php\/2015\/09\/08\/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-14-04\/","title":{"rendered":"How To Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu 14.04"},"content":{"rendered":"<p>\u0179r\u00f3d\u0142o: <a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-14-04\">https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-14-04<\/a><\/p>\n<div class=\"content-body tutorial-content\" data-growable-markdown=\"\">\n<h3 id=\"introduction\">Introduction<\/h3>\n<p>A &#8222;LAMP&#8221; 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&#8217;ll get a LAMP stack installed on an Ubuntu 14.04 Droplet. Ubuntu will fulfill our first requirement: a Linux operating system.<\/p>\n<p><span class=\"note\"><strong>Note:<\/strong> The LAMP stack can be installed automatically on your Droplet by adding <a href=\"http:\/\/do.co\/1FOx1QV\">this script<\/a> to its User Data when launching it. Check out <a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/an-introduction-to-droplet-metadata\">this tutorial<\/a> to learn more about Droplet User Data.<br \/>\n<\/span><\/p>\n<div data-unique=\"prerequisites\"><\/div>\n<h2 id=\"prerequisites\">Prerequisites<\/h2>\n<p>Before you begin with this guide, you should have a separate, non-root user account 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-14-04\">initial server setup for Ubuntu 14.04<\/a>.<\/p>\n<div data-unique=\"step-one-\u2014-install-apache\"><\/div>\n<h2 id=\"step-one-\u2014-install-apache\">Step One \u2014 Install Apache<\/h2>\n<p>The Apache web server is currently the most popular web server in the world, which makes it a great default choice for hosting a website.<\/p>\n<p>We can install Apache easily using Ubuntu&#8217;s 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 \"><code>sudo apt-get update\nsudo apt-get install apache2\n<\/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&#8217;s password to verify your intentions.<\/p>\n<p>Afterwards, your web server is installed.<\/p>\n<p>You can do a spot check right away to verify that everything went as planned by visiting your server&#8217;s 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>http:\/\/<span class=\"highlight\">your_server_IP_address<\/span>\n<\/pre>\n<p>You will see the default Ubuntu 14.04 Apache web page, which is there for informational and testing purposes. It should look something like this:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/assets.digitalocean.com\/articles\/lamp_1404\/default_apache.png\" alt=\"Ubuntu 14.04 Apache default\" \/><\/p>\n<p>If you see this page, then your web server is now correctly installed.<\/p>\n<h3 id=\"how-to-find-your-server-39-s-public-ip-address\">How To Find your Server&#8217;s Public IP Address<\/h3>\n<p>If you do not know what your server&#8217;s 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 \"><code>ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's\/\\\/.*$\/\/'\n<\/code><\/pre>\n<p>This will give you one or two lines back. They are both 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 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 \"><code>curl http:\/\/icanhazip.com\n<\/code><\/pre>\n<p>Regardless of the method you use to get your IP address, you can type it into your web browser&#8217;s address bar to get to your server.<\/p>\n<div data-unique=\"step-two-\u2014-install-mysql\"><\/div>\n<h2 id=\"step-two-\u2014-install-mysql\">Step Two \u2014 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&#8217;ll also install some other &#8222;helper&#8221; packages that will assist us in getting our components to communicate with each other:<\/p>\n<pre class=\"code-pre \"><code>sudo apt-get install mysql-server php5-mysql\n<\/code><\/pre>\n<p><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.<\/p>\n<p>During the installation, your server will ask you to select and confirm a password for the MySQL &#8222;root&#8221; 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).<\/p>\n<p>When the installation is complete, we need to run some additional commands to get our MySQL environment set up securely.<\/p>\n<p>First, we need to tell MySQL to create its database directory structure where it will store its information. You can do this by typing:<\/p>\n<pre class=\"code-pre \"><code>sudo mysql_install_db\n<\/code><\/pre>\n<p>Afterwards, 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 \"><code>sudo mysql_secure_installation\n<\/code><\/pre>\n<p>You will be asked to enter the password you set for the MySQL root account. Next, it will ask you if you want to change that password. If you are happy with your current password, type &#8222;n&#8221; for &#8222;no&#8221; at the prompt.<\/p>\n<p>For the rest of the questions, you should simply hit the &#8222;ENTER&#8221; key through each prompt to accept the default values. This will remove some sample users and databases, 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<div data-unique=\"step-three-\u2014-install-php\"><\/div>\n<h2 id=\"step-three-\u2014-install-php\">Step Three \u2014 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&#8217;re going to include some helper packages as well:<\/p>\n<pre class=\"code-pre \"><code>sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt\n<\/code><\/pre>\n<p>This should install PHP without any problems. We&#8217;ll test this in a moment.<\/p>\n<p>In most cases, we&#8217;ll 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&#8217;ll 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 \"><code>sudo nano \/etc\/apache2\/mods-enabled\/dir.conf\n<\/code><\/pre>\n<p>It will look like this:<\/p>\n<pre>&lt;IfModule mod_dir.c&gt;\n    DirectoryIndex index.html index.cgi index.pl <span class=\"highlight\">index.php<\/span> index.xhtml index.htm\n&lt;\/IfModule&gt;\n<\/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<pre>&lt;IfModule mod_dir.c&gt;\n    DirectoryIndex <span class=\"highlight\">index.php<\/span> index.html index.cgi index.pl index.xhtml index.htm\n&lt;\/IfModule&gt;\n<\/pre>\n<p>When you are finished, save and close the file by pressing &#8222;CTRL-X&#8221;. You&#8217;ll have to confirm the save by typing &#8222;Y&#8221; and then hit &#8222;ENTER&#8221; 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 \"><code>sudo service apache2 restart\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 type this into your system:<\/p>\n<pre class=\"code-pre \"><code>apt-cache search php5-\n<\/code><\/pre>\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>php5-cgi - server-side, HTML-embedded scripting language (CGI binary)\nphp5-cli - command-line interpreter for the php5 scripting language\nphp5-common - Common files for packages built from the php5 source\nphp5-curl - CURL module for php5\nphp5-dbg - Debug symbols for PHP5\nphp5-dev - Files for PHP5 module development\nphp5-gd - GD module for php5\n. . .\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 in the package by typing:<\/p>\n<pre>apt-cache show <span class=\"highlight\">package_name<\/span>\n<\/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>php5-cli<\/code> module does, we could type this:<\/p>\n<pre class=\"code-pre \"><code>apt-cache show php5-cli\n<\/code><\/pre>\n<p>Along with a large amount of other information, you&#8217;ll find something that looks like this:<\/p>\n<pre class=\"code-pre \"><code>. . .\nSHA256: 91cfdbda65df65c9a4a5bd3478d6e7d3e92c53efcddf3436bbe9bbe27eca409d\nDescription-en: command-line interpreter for the php5 scripting language\n This package provides the \/usr\/bin\/php5 command interpreter, useful for\n testing PHP scripts from a shell or performing general shell scripting tasks.\n .\n The following extensions are built in: bcmath bz2 calendar Core ctype date\n dba dom ereg exif fileinfo filter ftp gettext hash iconv libxml mbstring\n mhash openssl pcntl pcre Phar posix Reflection session shmop SimpleXML soap\n sockets SPL standard sysvmsg sysvsem sysvshm tokenizer wddx xml xmlreader\n xmlwriter zip zlib.\n .\n PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used\n open source general-purpose scripting language that is especially suited\n for web development and can be embedded into HTML.\nDescription-md5: f8450d3b28653dcf1a4615f3b1d4e347\nHomepage: http:\/\/www.php.net\/\n. . .\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>php5-cli<\/code> is something that we need, we could type:<\/p>\n<pre class=\"code-pre \"><code>sudo apt-get install php5-cli\n<\/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>sudo apt-get install <span class=\"highlight\">package1<\/span> <span class=\"highlight\">package2<\/span> <span class=\"highlight\">...<\/span>\n<\/pre>\n<p>At this point, your LAMP stack is installed and configured. We should still test out our PHP though.<\/p>\n<div data-unique=\"step-four-\u2014-test-php-processing-on-your-web-server\"><\/div>\n<h2 id=\"step-four-\u2014-test-php-processing-on-your-web-server\">Step Four \u2014 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 &#8222;web root&#8221;.<\/p>\n<p>In Ubuntu 14.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 \"><code>sudo nano \/var\/www\/html\/info.php\n<\/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<pre class=\"code-pre \"><code>&lt;?php\nphpinfo();\n?&gt;\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&#8217;ll need your server&#8217;s public IP address again.<\/p>\n<p>The address you want to visit will be:<\/p>\n<pre>http:\/\/<span class=\"highlight\">your_server_IP_address<\/span>\/info.php\n<\/pre>\n<p>The page that you come to should look something like this:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/assets.digitalocean.com\/articles\/lamp_1404\/default_php.png\" alt=\"Ubuntu 14.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 \"><code>sudo rm \/var\/www\/html\/info.php\n<\/code><\/pre>\n<p>You can always recreate this page if you need to access the information again later.<\/p>\n<div data-unique=\"conclusion\"><\/div>\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&#8217;ve installed a platform that will allow you to install most kinds of websites and web software on your server.<\/p>\n<p>Some 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-create-a-ssl-certificate-on-apache-for-ubuntu-12-04\">Learn how to create an SSL Certificate<\/a> to secure traffic to your web server.<\/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>: We will be updating the links above to our 14.04 documentation as it is written.<\/p>\n<div class=\"author\">By Justin Ellingwood<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p class=\"excerpt\">\u0179r\u00f3d\u0142o: https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-14-04 Introduction A &#8222;LAMP&#8221; 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,&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"http:\/\/u239160.webh.me\/jakisproblem.pl\/index.php\/2015\/09\/08\/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-14-04\/\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[9],"class_list":["post-1172","post","type-post","status-publish","format-standard","hentry","category-bez-kategorii","tag-rozne"],"_links":{"self":[{"href":"http:\/\/u239160.webh.me\/jakisproblem.pl\/index.php\/wp-json\/wp\/v2\/posts\/1172","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/u239160.webh.me\/jakisproblem.pl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/u239160.webh.me\/jakisproblem.pl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/u239160.webh.me\/jakisproblem.pl\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/u239160.webh.me\/jakisproblem.pl\/index.php\/wp-json\/wp\/v2\/comments?post=1172"}],"version-history":[{"count":0,"href":"http:\/\/u239160.webh.me\/jakisproblem.pl\/index.php\/wp-json\/wp\/v2\/posts\/1172\/revisions"}],"wp:attachment":[{"href":"http:\/\/u239160.webh.me\/jakisproblem.pl\/index.php\/wp-json\/wp\/v2\/media?parent=1172"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/u239160.webh.me\/jakisproblem.pl\/index.php\/wp-json\/wp\/v2\/categories?post=1172"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/u239160.webh.me\/jakisproblem.pl\/index.php\/wp-json\/wp\/v2\/tags?post=1172"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}