{"id":1465,"date":"2020-07-14T02:50:28","date_gmt":"2020-07-14T00:50:28","guid":{"rendered":"https:\/\/itsimple.info\/?p=1465"},"modified":"2020-07-14T02:50:30","modified_gmt":"2020-07-14T00:50:30","slug":"how-to-install-apache-on-centos-8","status":"publish","type":"post","link":"https:\/\/itsimple.info\/?p=1465","title":{"rendered":"How To Install Apache on CentOS 8"},"content":{"rendered":"<h2>\u00a0<\/h2>\n<h2 class=\"h2\"><span id=\"htoc-apache-files-and-directories\">Installing Apache<\/span><\/h2>\n<p>The first this is to install CentOS , Logon as root , updtae apache to the latest:<\/p>\n<p class=\"chroma\"><code class=\"language-output\" data-lang=\"output\">dnf update<\/code><br \/><br \/>Now we can start the installation which is straight forward :<\/p>\n<pre>dnf install httpd<\/pre>\n<p>Make it start and run with boot automatic :<br \/><code class=\"language-output\" data-lang=\"output\">systemctl start httpd<\/code><br \/><code class=\"language-output\" data-lang=\"output\">systemctl enable httpd<\/code><\/p>\n<p>Check the status of the server :<\/p>\n<p><code class=\"language-output\" data-lang=\"output\">systemctl status httpd<br \/><br \/><\/code>Now allow acces through the Linux firewall<\/p>\n<p><code>sudo firewall-cmd --permanent --zone=public --add-service=http\nsudo firewall-cmd --permanent --zone=public --add-service=https\nsudo firewall-cmd --reload<\/code><br \/><br \/>Then check to see if the site online and responding :<\/p>\n<p class=\"chroma\"><code class=\"language-output\" data-lang=\"output\">hostname -I | awk '{print $1}'<\/code> <br \/>Or<br \/>curl [your_system&#8217;s_IP_address]:80<br \/><br \/>You can also just open a browser and surf to your IP and get:<\/p>\n<p><a href=\"https:\/\/itsimple.info\/wp-content\/uploads\/2020\/07\/apache-test-page-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1471\" src=\"https:\/\/itsimple.info\/wp-content\/uploads\/2020\/07\/apache-test-page-1.png\" alt=\"\" width=\"1838\" height=\"1328\" srcset=\"https:\/\/itsimple.info\/wp-content\/uploads\/2020\/07\/apache-test-page-1.png 1838w, https:\/\/itsimple.info\/wp-content\/uploads\/2020\/07\/apache-test-page-1-300x217.png 300w, https:\/\/itsimple.info\/wp-content\/uploads\/2020\/07\/apache-test-page-1-1024x740.png 1024w, https:\/\/itsimple.info\/wp-content\/uploads\/2020\/07\/apache-test-page-1-768x555.png 768w, https:\/\/itsimple.info\/wp-content\/uploads\/2020\/07\/apache-test-page-1-1536x1110.png 1536w\" sizes=\"auto, (max-width: 1838px) 100vw, 1838px\" \/><\/a><\/p>\n<div class=\"heading-text el-text\">\n<h2 class=\"h2\"><span id=\"htoc-apache-files-and-directories\">Apache Files and Directories<\/span><\/h2>\n<\/div>\n<div class=\"uncode_text_column\">\n<p>Apache is controlled by applying <strong>directives<\/strong> in configuration files:<\/p>\n<ul>\n<li><strong>\/etc\/httpd\/conf\/httpd.conf<\/strong> \u2013 Main Apache config file<\/li>\n<li><strong>\/etc\/httpd\/<\/strong> \u2013 Location for all config files<\/li>\n<li><strong>\/etc\/httpd\/conf.d\/<\/strong> \u2013 All config files in this directory are included in the main confog file<\/li>\n<li><strong>\/etc\/httpd\/conf.modules.d\/<\/strong> \u2013 Location for Apache module config files<\/li>\n<li><strong>\/var\/log\/httpd\/<\/strong> \u2013 Location of Apache log files<\/li>\n<\/ul>\n<\/div>\n<ul>\n<li><strong>\/var\/log\/httpd\/access_log<\/strong> \u2013 Shows a log of systems that accessed the server<\/li>\n<li><strong>\/var\/log\/httpd\/error_log<\/strong> \u2013 Shows a list of any errors Apache encounters<\/li>\n<\/ul>\n<p class=\"chroma\">To install Apache modules use The default installation directory for Apache modules is the <code data-wg-notranslate=\"manual\">\/etc\/httpd\/modules\/<\/code> directory. Configuration directives for the default modules are located in <code data-wg-notranslate=\"manual\">\/etc\/httpd\/conf\/httpd.conf<\/code>, while configuration options for optional modules installed with yum are generally placed in <code data-wg-notranslate=\"manual\">.conf<\/code> files in <code data-wg-notranslate=\"manual\">\/etc\/httpd\/conf.d\/<\/code>.<\/p>\n<ol>\n<li>\n<p>List available Apache modules:<\/p>\n<pre><code data-wg-notranslate=\"manual\">sudo yum search mod_\n<\/code><\/pre>\n<\/li>\n<li>\n<p>Install any desired modules:<\/p>\n<pre><code data-wg-notranslate=\"manual\">sudo yum install [module-name]\n<\/code><\/pre>\n<p>Modules should be enabled and ready to use following installation.<\/p>\n<\/li>\n<\/ol>\n<p>The following commands install Apache support for server-side scripting in Perl, Python, and PHP. Support for these languages is optional based on your server environment.<\/p>\n<p>Install the EPEL repository:<\/p>\n<pre><code data-wg-notranslate=\"manual\">sudo yum install epel-release\n<\/code><\/pre>\n<p>To install:<\/p>\n<ul>\n<li>\n<p>Perl support:<\/p>\n<pre><code data-wg-notranslate=\"manual\">sudo yum install mod_perl\n<\/code><\/pre>\n<\/li>\n<li>\n<p>Python support:<\/p>\n<pre><code data-wg-notranslate=\"manual\">sudo yum install mod_wsgi\n<\/code><\/pre>\n<\/li>\n<li>\n<p>PHP support:<\/p>\n<pre><code data-wg-notranslate=\"manual\">sudo yum install php php-pear\n<\/code><\/pre>\n<\/li>\n<\/ul>\n<h2 id=\"controlling-apache\">Controlling Apache <span class=\"sr-only\">Permalink<\/span><\/h2>\n<p>You can control the server in the following ways.<\/p>\n<ol>\n<li>\n<p>Stopping the server when it\u2019s running:<\/p>\n<pre><code data-wg-notranslate=\"manual\">sudo systemctl stop httpd\n<\/code><\/pre>\n<\/li>\n<li>\n<p>Start the server when it\u2019s stopped:<\/p>\n<pre><code data-wg-notranslate=\"manual\">sudo systemctl start httpd\n<\/code><\/pre>\n<\/li>\n<li>\n<p>Stop and start the server when it\u2019s running:<\/p>\n<pre><code data-wg-notranslate=\"manual\">sudo systemctl restart httpd\n<\/code><\/pre>\n<\/li>\n<li>\n<p>Reload the configurations while the server is running without stopping it:<\/p>\n<pre><code data-wg-notranslate=\"manual\">sudo systemctl reload httpd\n<\/code><\/pre>\n<\/li>\n<li>\n<p>You can disable Apache so that it stops and doesn\u2019t restart again when rebooting the system:<\/p>\n<pre><code data-wg-notranslate=\"manual\">sudo systemctl disable httpd\n<\/code><\/pre>\n<\/li>\n<li>\n<p>To re-enable Apache if it\u2019s been disabled. This will also enable it to restart when the system reboots:<\/p>\n<pre><code data-wg-notranslate=\"manual\">sudo systemctl enable httpd\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<h3><span id=\"Creating_a_virtual_host_file_on_CentOS_8\" class=\"ez-toc-section\">Creating a virtual host file on CentOS 8<\/span><\/h3>\n<p>As discussed earlier, in order to publish your website, we are going to create a virtual host file.<\/p>\n<p>Similarly to NGINX, we are going to create two directories :<\/p>\n<ul>\n<li><strong>sites-available<\/strong> : that contains the entire list of websites available on our web server. Those websites are not necessarily enabled by default which is the purpose of the second folder.<\/li>\n<li><strong>sites-enabled<\/strong> : that containers the list of websites that are accessible to users. A symbolic link will be created in this directory in order to activate and desactivate websites on demand.<\/li>\n<\/ul>\n<p>First, create those two directories on your host.<\/p>\n<pre class=\"wp-block-code\"><code>$ sudo mkdir -p \/etc\/httpd\/sites-enabled \/etc\/httpd\/sites-available<\/code><\/pre>\n<p>Now that your folders are created, edit your default Apache configuration and find the following line.<\/p>\n<pre class=\"wp-block-code\"><code>$ sudo vi \/etc\/httpd\/conf\/httpd.conf\n\n# Load config files in the \"\/etc\/httpd\/conf.d\" directory if any\nIncludeOptional conf.d\/*.conf<\/code><\/pre>\n<p>Replace this line with the following line.<\/p>\n<pre class=\"wp-block-code\"><code>IncludeOptional sites-enabled\/*.conf<\/code><\/pre>\n<p>Now that your Apache Web Server configuration is updated, create a virtual host file for your \u201cwebsite.com\u201d website.<\/p>\n<pre class=\"wp-block-code\"><code>$ sudo vi \/etc\/httpd\/sites-available\/website.com.conf<\/code><\/pre>\n<p>Paste the following configuration in it.<\/p>\n<pre class=\"wp-block-code\"><code>&lt;VirtualHost *:80&gt;\n    ServerName website.com\n    ServerAlias www.website.com\n    DocumentRoot \/var\/www\/website.com\/html\n    ErrorLog \/var\/www\/website.com\/log\/error.log\n    CustomLog \/var\/www\/website.com\/log\/requests.log combined\n&lt;\/VirtualHost&gt;<\/code><\/pre>\n<p>Save your file, and make sure that your configuration is okay by running the following command.<\/p>\n<pre class=\"wp-block-code\"><code>$ sudo apachectl configtest\nSyntax OK<\/code><\/pre>\n<p>Now, your website won\u2019t be directly available just by restarting your Apache Web server, it needs to be located in the sites-enabled folder.<\/p>\n<p>To link it to the sites-enabled directory, create a symbolic link using this command.<\/p>\n<pre class=\"wp-block-code\"><code>$ sudo ln -s \/etc\/httpd\/sites-available\/website.com.conf \/etc\/httpd\/sites-enabled\/website.com.conf<\/code><\/pre>\n<h3><span id=\"Update_your_SELinux_firewall_rules\" class=\"ez-toc-section\">Update your SELinux firewall rules<\/span><\/h3>\n<p>By default, SELinux is configured to work with default Apache configuration folders.<\/p>\n<p>As you created custom ones, you need to enable them in SELinux.<\/p>\n<p>In order for the Apache Web Server to start correctly, you need to modify your Apache policy to include custom log directories.<\/p>\n<p>To enable custom directories, run the following command<\/p>\n<pre class=\"wp-block-code\"><code>$ sudo setsebool -P httpd_unified 1<\/code><\/pre>\n<h3><span id=\"Restart_your_Apache_server\" class=\"ez-toc-section\">Restart your Apache server<\/span><\/h3>\n<p>Now that everything is correctly set up, it is time for you to restart your server to see your changes.<\/p>\n<pre class=\"wp-block-code\"><code>$ sudo systemctl restart httpd<\/code><\/pre>\n<p class=\"chroma\"><a href=\"https:\/\/itsimple.info\/wp-content\/uploads\/2020\/07\/website-VirtualSite.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1470\" src=\"https:\/\/itsimple.info\/wp-content\/uploads\/2020\/07\/website-VirtualSite.png\" alt=\"\" width=\"918\" height=\"366\" srcset=\"https:\/\/itsimple.info\/wp-content\/uploads\/2020\/07\/website-VirtualSite.png 918w, https:\/\/itsimple.info\/wp-content\/uploads\/2020\/07\/website-VirtualSite-300x120.png 300w, https:\/\/itsimple.info\/wp-content\/uploads\/2020\/07\/website-VirtualSite-768x306.png 768w\" sizes=\"auto, (max-width: 918px) 100vw, 918px\" \/><\/a><br \/><br \/><\/p>\n<p>\u00a0<\/p>\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0 Installing Apache The first this is to install CentOS , Logon as root , updtae apache to the latest: dnf update Now we can start the installation which is straight forward : dnf install httpd Make it start and run with boot automatic :systemctl start httpdsystemctl enable httpd Check the status of the server [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16,13,12],"tags":[],"class_list":["post-1465","post","type-post","status-publish","format-standard","hentry","category-centos","category-linux","category-tutorials"],"_links":{"self":[{"href":"https:\/\/itsimple.info\/index.php?rest_route=\/wp\/v2\/posts\/1465","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itsimple.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itsimple.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itsimple.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itsimple.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1465"}],"version-history":[{"count":0,"href":"https:\/\/itsimple.info\/index.php?rest_route=\/wp\/v2\/posts\/1465\/revisions"}],"wp:attachment":[{"href":"https:\/\/itsimple.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1465"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itsimple.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1465"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itsimple.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1465"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}