{"id":82,"date":"2012-03-02T04:20:18","date_gmt":"2012-03-02T04:20:18","guid":{"rendered":"http:\/\/codebangers.com\/?p=82"},"modified":"2012-03-18T20:53:07","modified_gmt":"2012-03-18T20:53:07","slug":"82","status":"publish","type":"post","link":"https:\/\/codebangers.com\/82\/","title":{"rendered":"How to Install and Setup Apache in Ubuntu"},"content":{"rendered":"<p><strong>Installing Apache<\/strong><\/p>\n<p>Getting apache onto your Ubuntu machine is easy. Using either the Synaptic Package Manager, Ubuntu Software Center, search and install the \u201capache2\u201d module. Alternatively, you can open a terminal and type the following command:<br \/>\n<code><br \/>\nsudo apt-get install apache2<\/code><\/p>\n<p>Once the installation finished, open a browser and go to the URL \u201chttp:\/\/localhost\u201c. If you see the word \u201cIt Works!\u201c, then your installation of apache is successful.<\/p>\n<p><a href=\"http:\/\/codebangers.com\/wp-content\/uploads\/2012\/03\/apache-it-works-enfew.png\"><img decoding=\"async\" class=\"size-medium wp-image-86 alignnone\" title=\"Apache2\" src=\"http:\/\/codebangers.com\/wp-content\/uploads\/2012\/03\/apache-it-works-enfew-300x159.png\" alt=\"\" width=\"300\" height=\"159\" srcset=\"https:\/\/codebangers.com\/wp-content\/uploads\/2012\/03\/apache-it-works-enfew-300x159.png 300w, https:\/\/codebangers.com\/wp-content\/uploads\/2012\/03\/apache-it-works-enfew-555x295.png 555w, https:\/\/codebangers.com\/wp-content\/uploads\/2012\/03\/apache-it-works-enfew-500x265.png 500w, https:\/\/codebangers.com\/wp-content\/uploads\/2012\/03\/apache-it-works-enfew.png 635w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p><strong>Configuring Apache<\/strong><\/p>\n<p>Start, Stop and Restart Apache<br \/>\nAfter you have installed Apache, it will be added to the init.d list and will auto start whenever you boot up your computer. The following commands allow you to start, restart, stop Apache.<\/p>\n<p><code><br \/>\nsudo \/etc\/init.d\/apache2 start #start apache<br \/>\nsudo \/etc\/init.d\/apache2 stop #stop apache<br \/>\nsudo \/etc\/init.d\/apache2 restart #restart apache<br \/>\n<\/code><\/p>\n<p>&nbsp;<\/p>\n<p>To prevent <strong>Apache<\/strong> from autostart when booting up:<\/p>\n<p><code>sudo update-rc.d -f apache2 remove<\/code><\/p>\n<p>To restore <strong>Apache<\/strong> back to the autostart list:<\/p>\n<p><code>sudo update-rc.d apache2 defaults<\/code><\/p>\n<p>Note: the above commands will work in debian-based distro (including Ubuntu) only.<\/p>\n<p>Changing the default localhost folder<\/p>\n<p>By default, apache will operate on the \u201c\/var\/www\u201d folder. This means that whatever files you place in this \/var\/www folder will be visible from the URL http:\/\/localhost. In some instances, you may want the \u201clocalhost\u201d to point to another folder instead, say \/home\/user\/public_html. Here is how you do it:<\/p>\n<p>First, make sure the \/home\/damien\/public_html folder exists. Create a simple html file, name it index.html and place it in the public_html folder.<\/p>\n<p>Open a terminal and type:<\/p>\n<p><code>gksu gedit \/etc\/apache2\/sites-enabled\/000-default<\/code><br \/>\nChange DocumentRoot \/var\/www to DocumentRoot \/home\/user\/public_html.<\/p>\n<p>Change to.<\/p>\n<p><a href=\"http:\/\/codebangers.com\/wp-content\/uploads\/2012\/03\/apache-edit-virtual-host.png\"><img fetchpriority=\"high\" decoding=\"async\" class=\"size-medium wp-image-87 alignnone\" title=\"apache-edit-virtual-host\" src=\"http:\/\/codebangers.com\/wp-content\/uploads\/2012\/03\/apache-edit-virtual-host-300x207.png\" alt=\"\" width=\"300\" height=\"207\" srcset=\"https:\/\/codebangers.com\/wp-content\/uploads\/2012\/03\/apache-edit-virtual-host-300x207.png 300w, https:\/\/codebangers.com\/wp-content\/uploads\/2012\/03\/apache-edit-virtual-host.png 489w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Save and exit the file.<\/p>\n<p>Restart the apache<\/p>\n<p><code><br \/>\nsudo \/etc\/init.d\/apache2 restart<br \/>\n<\/code><br \/>\nNow, in your browser, reload the URL http:\/\/localhost. You should see the html file that you have placed in the public_html folder.<\/p>\n<p>Configuring different sites<\/p>\n<p>The above trick allows you to change the default operating folder of apache, however, some of you might not want to override the default settings. An alternative is to create multiple sites and<br \/>\npoint apache to the active site.<br \/>\nCreate a new settings file for your new site.<\/p>\n<p><code><br \/>\nsudo cp \/etc\/apache2\/sites-available\/default \/etc\/apache2\/sites-available\/site1<\/code><br \/>\nNext, edit this settings file.<\/p>\n<p><code><br \/>\ngksu gedit \/etc\/apache2\/sites-available\/site1<br \/>\n<\/code><br \/>\nChange DocumentRoot \/var\/www to DocumentRoot \/home\/user\/public_html.<\/p>\n<p>Change to .<\/p>\n<p>Save and exit the file.<\/p>\n<p>Disable the default setting and make active the site1 settings<\/p>\n<p><code>sudo a2dissite default &amp;&amp; sudo a2ensite site1<\/code><\/p>\n<p>Lastly, restart the apache.<\/p>\n<p><code>sudo \/etc\/init.d\/apache2 restart<\/code><br \/>\nWith this trick, you can create multiple site configuration file, each pointing to a different folder. You can then easily switch between the sites with the a2dissite and a2ensite command<\/p>\n<p>Enabling .htaccess file<br \/>\n.htaccess file is a powerful file that can be used to control and customize a site server behavior without editing the core Apache module. By default, the .htaccess functionality is turned off and<br \/>\nall instances of .htaccess files are completely ignored. The server will not even attempt to read .htaccess files in the filesystem.<\/p>\n<p>To enable .htaccess file, open up the settings file that you have created earlier:<\/p>\n<p><code><br \/>\ngksu gedit \/etc\/apache2\/sites-available\/site1<br \/>\n<\/code><br \/>\nScroll down the file until you see the part \u201c\u201c. Underneath that line of code, change AllowOverride None to AllowOverride All.<\/p>\n<p>Save and exit the file.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Installing Apache Getting apache onto your Ubuntu machine is easy. Using either the Synaptic Package Manager, Ubuntu Software Center, search and install [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":100,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,30,15,4,31,5],"tags":[],"class_list":["post-82","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-apache2","category-howto","category-linux-1","category-php","category-programming","category-ubuntu"],"_links":{"self":[{"href":"https:\/\/codebangers.com\/wp-json\/wp\/v2\/posts\/82","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codebangers.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codebangers.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codebangers.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/codebangers.com\/wp-json\/wp\/v2\/comments?post=82"}],"version-history":[{"count":18,"href":"https:\/\/codebangers.com\/wp-json\/wp\/v2\/posts\/82\/revisions"}],"predecessor-version":[{"id":223,"href":"https:\/\/codebangers.com\/wp-json\/wp\/v2\/posts\/82\/revisions\/223"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codebangers.com\/wp-json\/wp\/v2\/media\/100"}],"wp:attachment":[{"href":"https:\/\/codebangers.com\/wp-json\/wp\/v2\/media?parent=82"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codebangers.com\/wp-json\/wp\/v2\/categories?post=82"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codebangers.com\/wp-json\/wp\/v2\/tags?post=82"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}