{"id":1046,"date":"2024-09-19T13:05:35","date_gmt":"2024-09-19T11:05:35","guid":{"rendered":"https:\/\/www.gonscak.sk\/?p=1046"},"modified":"2024-09-19T20:19:18","modified_gmt":"2024-09-19T18:19:18","slug":"install-wordpress-on-centos-9-stream-with-apache-httpd","status":"publish","type":"post","link":"https:\/\/www.gonscak.sk\/?p=1046","title":{"rendered":"Install WordPress on Centos-9-stream with apache (httpd)"},"content":{"rendered":"\n<p>I started on clean centos-8 server, created from netinstall cd. It is minimal instalation. So, lets begun. Check the version, to be installed:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">dnf info httpd<br>Name         : httpd<br>Version      : 2.4.62<br>Release      : 1.el9<\/pre>\n\n\n\n<p>So, let install it and allow http port on firewalld. And start apache server itself.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">dnf install httpd<br>firewall-cmd --add-service=http --permanent<br>firewall-cmd --reload<br>systemctl enable httpd.service --now<\/pre>\n\n\n\n<p>Now, you can point you web browser to IP on this server and you should see the welcome page of apache web server on centos.<\/p>\n\n\n\n<p>Now create a directory, where we place our content and simple web page to test, if its working.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mkdir -p \/var\/www\/vhosts\/com.example.www\nvim \/var\/www\/vhosts\/com.example.www\/index.html<\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;html&gt;\n  &lt;head&gt;\n    &lt;title&gt;Welcome to www.example.com!&lt;\/title&gt;\n  &lt;\/head&gt;\n  &lt;body&gt;\n    &lt;h1&gt;Success!  The www.example.com virtual host is working!&lt;\/h1&gt;\n  &lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<p>And now, create for this page own configuration in httpd:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">vim \/etc\/httpd\/conf.d\/com.example.www.conf<\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;VirtualHost *:80&gt;\n    ServerAdmin admin@example.com\n    DocumentRoot \"\/var\/www\/vhosts\/com.example.www\"\n    ServerName www.example.com\n\nErrorLog \/var\/log\/httpd\/com.example.www-error_log\nCustomLog \/var\/log\/httpd\/com.example.www-access_log common\n&lt;\/VirtualHost&gt;<\/code><\/pre>\n\n\n\n<p>And now, gracefully restart your web server and point your browser to you domain: www.example.com (I edit my \/etc\/hosts to point this domain at my internal IP).<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">apachectl graceful<\/pre>\n\n\n\n<p>If you test page is working, lets begin with more thinks. We must install additional packages (software) for wordpress. Its mysql server and php. As mysql server, I use mariadb. Then create an initial configuration for mysql and create database for wordpress. I set no password for mysql.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">dnf install <code>mariadb-server mariadb<\/code><br><code>systemctl enable mariadb<\/code> --now<br><code>mysql_secure_installation<\/code><br>   Switch to unix_socket authentication [Y\/n]<br>   Change the root password? [Y\/n] n<br>   Remove anonymous users? [Y\/n] y<br>   Disallow root login remotely? [Y\/n] y<br>   Remove test database and access to it? [Y\/n] y<br>   Reload privilege tables now? [Y\/n] y<br><br>mysql -u root -p<br>   <code>CREATE DATABASE wordpress;<\/code><br>   GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost IDENTIFIED BY 'BESTpassword';<br>   FLUSH PRIVILEGES;<br>   exit;<\/pre>\n\n\n\n<p>When we find, which version of php will be standard installed, I decided to use another package sources and install newer php version 8.3<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">dnf info php<br> Available Packages<br> Name         : php<br> Version      : 8.0.30<br><br><br>dnf install dnf-utils http:\/\/rpms.remirepo.net\/enterprise\/remi-release-9.rpm<br>dnf update<br>dnf module list php<br>dnf module reset php<br>dnf module enable php:remi-8.3<br>dnf info php<br>  Available Packages<br>  Name         : php<br>  Version      : 8.3.11<br>  Release      : 1.el9.remi<br>  Architecture : x86_64<br>  Size         : 1.8 M<br>  Source       : php-8.3.11-1.el9.remi.src.rpm<br>  Repository   : remi-modular<br><br>dnf install php php-mysql php-gd php-pecl-zip php-intl php-pecl-imagick<br>php -v<br>...<br>PHP 8.3.11 (cli) (built: Aug 27 2024 19:16:34) (NTS gcc x86_64)<\/pre>\n\n\n\n<p>Now, create simple test php page, to view php by apache if its working.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">vim \/var\/www\/vhosts\/com.example.www\/foo.php<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;?php\n  phpinfo();\n?&gt;<\/pre>\n\n\n\n<p>Restart apache web server and point your browser to php:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">systemctl restart httpd.service\nwww.example.com\/foo.php<\/pre>\n\n\n\n<p>And now you can see informationa page about php on system.<\/p>\n\n\n\n<p>Now we can download wordpress and unpack it.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>cd ~ <\/code>\n<code>wget http:\/\/wordpress.org\/latest.tar.gz<\/code>\n<code>tar xzvf latest.tar.gz<\/code>\nrsync -avP wordpress\/ \/var\/www\/vhosts\/com.example.www\/\nchown -R apache:apache \/var\/www\/vhosts\/<\/pre>\n\n\n\n<p>Now, we edit configuration and add directory variables about default loding index.php. And remove test files \u2013 foo.php, index.html.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">rm \/var\/www\/vhosts\/com.example.www\/foo.php\nrm \/var\/www\/vhosts\/com.example.www\/index.html\nvim \/etc\/httpd\/conf.d\/com.example.www.conf<\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;Directory \/var\/www\/vhosts\/com.example.www&gt;\nDirectoryIndex index.php\n&lt;\/Directory&gt;<\/code><\/pre>\n\n\n\n<p>And restart apache web server<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">systemctl restart httpd.service<\/pre>\n\n\n\n<p>Now we can continue with setting our wordpress via web browser and our www.example.com page (click refresh in your web browser). Follow the instructions and fill your variables (database name, user, password\u2026).<\/p>\n\n\n\n<p>My installation step 2 tells me, that it cannot write config.php in our content directory. So, I can manually creaty config.php, or find out, what happens. Install selinux troubleshoot packages and run command sealert, which tell us what happend.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">dnf install setroubleshoot\nsealert -a \/var\/log\/audit\/audit.log<\/pre>\n\n\n\n<p>I can see this messages:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELinux is preventing \/usr\/sbin\/php-fpm from write access on the directory \/var\/www\/vhost\/com.example.www.\nIf you want to allow php-fpm to have write access on the com.example.www directory\nThen you need to change the label on 'com.example.www'\nDo\n# semanage fcontext -a -t httpd_sys_rw_content_t 'com.example.www'\n# restorecon -v 'com.example.www'\nAdditional Information:\nSource Context                system_u:system_r:httpd_t:s0\nTarget Context                unconfined_u:object_r:httpd_sys_content_t:s0\nTarget Objects                com.example.www &#91; dir ]<\/code><\/pre>\n\n\n\n<p>So I do, what it want. I adapt permissions, that apache\/php can write into this directory.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">semanage fcontext -a -t httpd_sys_rw_content_t '\/var\/www\/vhosts\/com.example.www(\/.*)?'\nrestorecon -Rv \/var\/www\/vhosts\/com.example.www\/<\/pre>\n\n\n\n<p>Now I can continue with installation. And everything works fine. Have a nice day.<\/p>\n\n\n\n<p><\/p>\n ","protected":false},"excerpt":{"rendered":"<p>I started on clean centos-8 server, created from netinstall cd. It is minimal instalation. So, lets begun. Check the version, to be installed: dnf info httpdName : httpdVersion : 2.4.62Release : 1.el9 So, let install it and allow http port on firewalld. And start apache server itself. dnf install httpdfirewall-cmd &#8211;add-service=http &#8211;permanentfirewall-cmd &#8211;reloadsystemctl enable httpd.service &hellip; <a href=\"https:\/\/www.gonscak.sk\/?p=1046\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Install WordPress on Centos-9-stream with apache (httpd)<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1046","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=\/wp\/v2\/posts\/1046","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1046"}],"version-history":[{"count":5,"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=\/wp\/v2\/posts\/1046\/revisions"}],"predecessor-version":[{"id":1052,"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=\/wp\/v2\/posts\/1046\/revisions\/1052"}],"wp:attachment":[{"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1046"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1046"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1046"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}