{"id":10847,"date":"2024-12-17T07:18:46","date_gmt":"2024-12-17T07:18:46","guid":{"rendered":"https:\/\/blog.webystrata.co.uk\/?p=10847"},"modified":"2024-12-17T07:18:46","modified_gmt":"2024-12-17T07:18:46","slug":"how-to-install-configure-of-apache-in-linux","status":"publish","type":"post","link":"https:\/\/www.webystrata.co.uk\/blog\/how-to-install-configure-of-apache-in-linux\/","title":{"rendered":"How to Install\/Configure of Apache in Linux"},"content":{"rendered":"<h1><a href=\"https:\/\/www.webystrata.co.uk\/cpanel-hosting.html\"><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone wp-image-10848 size-full\" title=\"How to Install\/Configure of Apache in Linux\" src=\"https:\/\/blog.webystrata.co.uk\/wp-content\/uploads\/2024\/12\/10411026_4402130.jpg\" alt=\"How to Install\/Configure of Apache in Linux\" width=\"2000\" height=\"2000\" srcset=\"https:\/\/www.webystrata.co.uk\/blog\/wp-content\/uploads\/2024\/12\/10411026_4402130.jpg 2000w, https:\/\/www.webystrata.co.uk\/blog\/wp-content\/uploads\/2024\/12\/10411026_4402130-300x300.jpg 300w, https:\/\/www.webystrata.co.uk\/blog\/wp-content\/uploads\/2024\/12\/10411026_4402130-1024x1024.jpg 1024w, https:\/\/www.webystrata.co.uk\/blog\/wp-content\/uploads\/2024\/12\/10411026_4402130-150x150.jpg 150w, https:\/\/www.webystrata.co.uk\/blog\/wp-content\/uploads\/2024\/12\/10411026_4402130-768x768.jpg 768w, https:\/\/www.webystrata.co.uk\/blog\/wp-content\/uploads\/2024\/12\/10411026_4402130-1536x1536.jpg 1536w\" sizes=\"(max-width: 2000px) 100vw, 2000px\" \/><\/a><\/h1>\n<h1>How to Install\/Configure of Apache in Linux<\/h1>\n<h2>Install Apache<\/h2>\n<p>First things first, your server may not even have Apache installed on it.<\/p>\n<p>Install the latest version with\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">yum<\/span><\/code>, like so:<\/p>\n<div class=\"highlight-bash notranslate\">\n<div class=\"highlight\">\n<pre>yum install httpd\r\n<\/pre>\n<\/div>\n<\/div>\n<div class=\"admonition note\">\n<p>As with all CentOS\/Red Hat packages, \u2018latest\u2019 usually won\u2019t mean the current stable version that could be found on the project <a href=\"https:\/\/www.webystrata.co.uk\/cpanel-hosting.html\">website<\/a>, but rather than latest package provided by CentOS\/Red Hat.<\/p>\n<p>These typically include backported security patches, see the page on vulnerability scans for further information.\u00a0<span class=\"doc\">Vulnerability Scans<\/span><\/p>\n<\/div>\n<p>Most people will want their webserver to start on boot, use\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">chkconfig<\/span><\/code>\u00a0to make it so:<\/p>\n<div class=\"highlight-bash notranslate\">\n<div class=\"highlight\">\n<pre>chkconfig httpd on\r\n<\/pre>\n<\/div>\n<\/div>\n<section id=\"configure-virtual-hosts\">\n<h3>Configure Virtual Hosts<\/h3>\n<p>Virtual Hosts are Apache\u2019s way of pointing different sites to different directories whilst still allowing them to share the same IP. If you\u2019re familiar with IIS parlance, then they\u2019d be called bindings.<\/p>\n<p>All config files ending in\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">.conf<\/span><\/code>\u00a0in the\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">\/etc\/httpd\/conf.d<\/span><\/code>\u00a0directory will be parsed as Apache configuration files at the end of the main\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">\/etc\/httpd\/conf\/httpd.conf<\/span><\/code>\u00a0file.<\/p>\n<p>The following content, if added to a file called\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">\/etc\/httpd\/conf.d\/vhosts.conf<\/span><\/code>\u00a0will enable multiple Virtual Hosts on one IP and then set up two sites, one called\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">firstdomain.com<\/span><\/code>\u00a0and the other called\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">seconddomain.org<\/span><\/code>.<\/p>\n<div class=\"highlight-apacheconf notranslate\">\n<div class=\"highlight\">\n<pre><span class=\"nb\">NameVirtualHost<\/span> *:80\r\n\r\n<span class=\"nt\">&lt;VirtualHost<\/span> <span class=\"s\">*:80<\/span><span class=\"nt\">&gt;<\/span>\r\n   <span class=\"nb\">ServerName<\/span> firstdomain.com\r\n   <span class=\"nb\">ServerAlias<\/span> www.firstdomain.com\r\n   <span class=\"nb\">DocumentRoot<\/span> <span class=\"sx\">\/var\/www\/vhosts\/firstdomain.com\/public_html\/<\/span>\r\n   <span class=\"nb\">ErrorLog<\/span> <span class=\"sx\">\/var\/www\/vhosts\/firstdomain.com\/logs\/error.log<\/span>\r\n   <span class=\"nb\">CustomLog<\/span> <span class=\"sx\">\/var\/www\/vhosts\/firstdomain.com\/logs\/access.log<\/span> combined\r\n<span class=\"nt\">&lt;\/VirtualHost&gt;<\/span>\r\n\r\n<span class=\"nt\">&lt;VirtualHost<\/span> <span class=\"s\">*:80<\/span><span class=\"nt\">&gt;<\/span>\r\n   <span class=\"nb\">ServerName<\/span> seconddomain.org\r\n   <span class=\"nb\">ServerAlias<\/span> www.seconddomain.org\r\n   <span class=\"nb\">DocumentRoot<\/span> <span class=\"sx\">\/var\/www\/vhosts\/seconddomain.org\/public_html\/<\/span>\r\n   <span class=\"nb\">ErrorLog<\/span> <span class=\"sx\">\/var\/www\/vhosts\/seconddomain.org\/logs\/error.log<\/span>\r\n   <span class=\"nb\">CustomLog<\/span> <span class=\"sx\">\/var\/www\/vhosts\/seconddomain.org\/logs\/access.log<\/span> combined\r\n<span class=\"nt\">&lt;\/VirtualHost&gt;<\/span>\r\n<\/pre>\n<\/div>\n<\/div>\n<p>The paths involved in that config likely don\u2019t exist, so you\u2019ll need to create them with the\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">mkdir<\/span><\/code>\u00a0command.<\/p>\n<div class=\"highlight-bash notranslate\">\n<div class=\"highlight\">\n<pre>mkdir -p \/var\/www\/vhosts\/firstdomain.com\/public_html\r\nmkdir -p \/var\/www\/vhosts\/firstdomain.com\/logs\r\nmkdir -p \/var\/www\/vhosts\/seconddomain.org\/public_html\r\nmkdir -p \/var\/www\/vhosts\/seconddomain.org\/logs\r\n<\/pre>\n<\/div>\n<\/div>\n<p>You\u2019ll also want to create the log files that you specified:<\/p>\n<div class=\"highlight-bash notranslate\">\n<div class=\"highlight\">\n<pre>touch \/var\/www\/vhosts\/firstdomain.com\/logs\/error.log <span class=\"se\">\\<\/span>\r\n      \/var\/www\/vhosts\/firstdomain.com\/logs\/access.log <span class=\"se\">\\<\/span>\r\n      \/var\/www\/vhosts\/seconddomain.org\/logs\/error.log <span class=\"se\">\\<\/span>\r\n      \/var\/www\/vhosts\/seconddomain.org\/logs\/access.log\r\n<\/pre>\n<\/div>\n<\/div>\n<p>With a standard setup like this, the files will need to be owned by the Apache user and group:<\/p>\n<div class=\"highlight-console notranslate\">\n<div class=\"highlight\">\n<pre><span class=\"go\">chown -R  apache:apache \/var\/www\/vhosts\/firstdomain.com \\<\/span>\r\n<span class=\"go\">                        \/var\/www\/vhosts\/seconddomain.org<\/span>\r\n<\/pre>\n<\/div>\n<\/div>\n<p>You\u2019re nearly good to go, the only thing you need now is some content. The Apache directive\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">DirectoryIndex<\/span><\/code>\u00a0specifies which file is used as the default index file in a directory, and by default this will be\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">index.html<\/span><\/code>\u00a0or\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">index.htm<\/span><\/code>. You may want to add\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">index.php<\/span><\/code>\u00a0into this line.<\/p>\n<p>By that logic, if you create a file in\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">\/var\/www\/vhosts\/firstdomain.com\/public_html\/<\/span><\/code>\u00a0called\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">index.html<\/span><\/code>\u00a0with some content, then that\u2019s what will display on\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">www.firstdomain.com<\/span><\/code><\/p>\n<div class=\"admonition note\">\n<p>Don\u2019t forget to chown any website files to\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">apache:apache<\/span><\/code>\u00a0as well<\/p>\n<\/div>\n<p>In this example we\u2019ve added our vhost configurations into the\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">\/etc\/httpd\/conf.d\/vhost.conf<\/span><\/code>. When you have a lot of configuration files, it might be worth adding these into their own\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">.conf<\/span><\/code>\u00a0files. There will be examples of this at the bottom of this guide.<\/p>\n<\/section>\n<section id=\"start-it-all-up\">\n<h3>Start it all up<\/h3>\n<p>All that remains now is to test your Apache configuration and then start the webserver up.<\/p>\n<p>Testing can be done with the command\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">httpd<\/span>\u00a0<span class=\"pre\">-t<\/span><\/code>\u00a0and if all is well, it should spit out the following message:<\/p>\n<div class=\"highlight-bash notranslate\">\n<div class=\"highlight\">\n<pre>Syntax OK\r\n<\/pre>\n<\/div>\n<\/div>\n<p>To start Apache, the following command can be used:<\/p>\n<div class=\"highlight-bash notranslate\">\n<div class=\"highlight\">\n<pre>service httpd start\r\n<\/pre>\n<\/div>\n<\/div>\n<p>Or if it\u2019s already running, you can restart it:<\/p>\n<div class=\"highlight-bash notranslate\">\n<div class=\"highlight\">\n<pre>service httpd restart\r\n<\/pre>\n<\/div>\n<\/div>\n<\/section>\n<section id=\"htaccess-files\">\n<h3>.htaccess files<\/h3>\n<p>Apache makes use of a file named\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">.htaccess<\/span><\/code>\u00a0in its document root to allow web server configurations to be made per-vhost without requiring access to the Apache configuration files. To allow these to work you need to configure the\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">AllowOverride<\/span><\/code>\u00a0settings by adding the following to your vhost configuration file.<\/p>\n<div class=\"highlight-console notranslate\">\n<div class=\"highlight\">\n<pre><span class=\"go\">&lt;Directory \"\/var\/www\/vhosts\/firstdomain.com\/htdocs\"&gt;<\/span>\r\n<span class=\"go\">   Options FollowSymLinks<\/span>\r\n<span class=\"go\">   AllowOverride All<\/span>\r\n\r\n<span class=\"go\">   Order allow,deny<\/span>\r\n<span class=\"go\">   Allow from all<\/span>\r\n<span class=\"go\">&lt;\/Directory&gt;<\/span>\r\n<\/pre>\n<\/div>\n<\/div>\n<\/section>\n<section id=\"going-forward\">\n<h3>Going forward<\/h3>\n<p>Most sites now need more that just basic HTML, often using PHP to generate their dynamic content and some kind of database to store information.<\/p>\n<p>The following documents carry on the setup for those particular elements:<\/p>\n<ul class=\"simple\">\n<li><span class=\"doc\">PHP Installation<\/span><\/li>\n<li><span class=\"doc\">MySQL Installation<\/span><\/li>\n<\/ul>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>How to Install\/Configure of Apache in Linux Install Apache First things first, your server may not even have Apache installed on it. Install the latest version with\u00a0yum, like so: yum install httpd As with all CentOS\/Red Hat packages, \u2018latest\u2019 usually won\u2019t mean the current stable version that could be found on the project website, but [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":10848,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-10847","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.webystrata.co.uk\/blog\/wp-json\/wp\/v2\/posts\/10847","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webystrata.co.uk\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webystrata.co.uk\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webystrata.co.uk\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webystrata.co.uk\/blog\/wp-json\/wp\/v2\/comments?post=10847"}],"version-history":[{"count":1,"href":"https:\/\/www.webystrata.co.uk\/blog\/wp-json\/wp\/v2\/posts\/10847\/revisions"}],"predecessor-version":[{"id":10849,"href":"https:\/\/www.webystrata.co.uk\/blog\/wp-json\/wp\/v2\/posts\/10847\/revisions\/10849"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webystrata.co.uk\/blog\/wp-json\/wp\/v2\/media\/10848"}],"wp:attachment":[{"href":"https:\/\/www.webystrata.co.uk\/blog\/wp-json\/wp\/v2\/media?parent=10847"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webystrata.co.uk\/blog\/wp-json\/wp\/v2\/categories?post=10847"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webystrata.co.uk\/blog\/wp-json\/wp\/v2\/tags?post=10847"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}