Install & setup PHP 7.3 & Apache 2.4 on CentOS 8
In this post, I would focus on permission settings for website root folder of Apache. The rest of the other fairs are simpler than the permission settings, so that I wouldn’t describe too many details. However, you will finish these works if you follow this article step by step.
Install Apache and set it automatically start on boot.
1 2 3 |
$ sudo dnf install httpd $ sudo systemctl start httpd $ sudo systemctl enable httpd |
Setup permission of firewall. Allow the HTTP and HTTPS through firewall.
1 2 3 |
$ sudo firewall-cmd --zone=public --add-service=http $ sudo firewall-cmd --zone=public --add-service=https $ sudo firewall-cmd --reload |
You could open your server by Chrome or any kind of browser software when you had finished the settings of the firewall. Your browser should be able to display the default website of Apache.
Install PHP 7.3
Because the default version of PHP’s repository on CentOS is 7.0, so you have to install a new repository which carries PHP 7.3. After then you could install PHP 7.3 and some relevant packages through dnf
.
1 2 |
$ sudo dnf install http://rpms.remirepo.net/enterprise/remi-release-8.rpm $ sudo dnf install php73-php php73-php-gd php73-php-mbstring php73-php-mysqlnd php73-php-common |
Permission of website root.
Finally, this is the most important part of this post.
I assumed the root path of your website is “/var/www”, and you have to run the commands under below:
1 2 3 |
[andy@www ~]$ cd /var/www [andy@www /var/www]$ sudo chown -R apache:apache . [andy@www /var/www]$ sudo chcon -R --type=httpd_sys_content_t . |
The command in the line 2 and line 3 is to change the files’ owner and change the file type, respectively. Especially this file type is an attribute of SELinux in the line 3, and it’s also quite common for permission setting of Apache.
If your website is using the famous CMS, WordPress, then you could follow the recommendation for permission settings under below:
This example is based on the website root path was located at “/var/www”.
1 2 3 4 |
[andy@www /var/www]$ sudo find . -type f -exec chmod 0644 {} \; [andy@www /var/www]$ sudo find . -type d -exec chmod 0755 {} \; [andy@www /var/www]$ sudo chcon -R --type=httpd_sys_content_t . [andy@www /var/www]$ sudo chcon -R --type=httpd_sys_rw_content_t wp-content/ |
There is a file type called “httpd_sys_rw_content_t” which means that path was allowed apache to read and write files inside. Actually I would extremely recommend you permit Apache to read and write for the whole WordPress path, just like the command under below. The reason is this setting could allow your WordPress upgrade smoothly, otherwise, you may occur some permission problem while upgrading. Because
1 |
[andy@www /var/www]$ sudo chcon -R --type=httpd_sys_rw_content_t . |
Finally, your WordPress should be able to download/install plugins and upload images without any additional manual settings.
PHP-FPM
this is a special part of this post. If you modified php.ini
, then you have to restart this program “php-fpm”. Because, php-fpm controlled the server relevant parameters, for instance, the maximum memory size that PHP can allocate. To that end, you can restart it through the command under below:
1 |
$ sudo systemctl restart php73-php-fpm |
Pingback:Install MySQL 8 & phpMyAdmin on CentOS 8 - BrilliantCode.net
Pingback:Setup a LAMP web server using CentOS 8 - BrilliantCode.net
Pingback:CentOS 8 Apache 2.4, PHP7.3 安裝與設定 - BrilliantCode.net