2. Page | 1
Installing PHP 7.4 Nginx 1.14
PHP-FPM & Laravel 7.15 on
CENTOS 8
Contents
Step 1) Enable EPEL and Remi Repository.............................................................................................................2
Step 2) Enable latest PHP Module Stream (remi-7.4)........................................................................................2
Step 3) Install and Verify PHP 7.4..............................................................................................................................3
Step 4) Start Nginx Php-FPM......................................................................................................................................3
Step 5) Enabling HTTPS/HTTPS..................................................................................................................................3
Step 6) Configuring and Securing PHP-FPM and Nginx..................................................................................4
Step 7) Configuring Timezone ...................................................................................................................................4
Step 8) Configuring Pathinfo......................................................................................................................................5
Step 9) Configuring Security Limit............................................................................................................................5
Step 10) Installing Composer & Laravel Framework .........................................................................................6
Step 11) Creating Laravel Project..............................................................................................................................6
Step 12) Configuring Nginx Server Block for Laravel ........................................................................................7
Step 13) Update the Security Context.....................................................................................................................9
Step 14) Accessing Laravel Website from a Web Browser ........................................................................... 10
3. Page | 2
Step 1) Enable EPEL and Remi Repository
In the default CentOS 8 and RHEL 8 package repositories, PHP 7.2 / 7.3 is available
and to install latest version of PHP 7.4, we must configure EPEL and REMI
repositories, so to enable the repositories, run the following commands:
[root@centos8]# dnf install epel-release -y
[root@centos8]# dnf install
https://rpms.remirepo.net/enterprise/remi-release-8.rpm -y
[root@centos8]# dnf module list php
As we can see in above output, PHP 7.2 is the default package from CentOS-8
AppStream repository, so in the next step, we will enable latest PHP module stream
(redmi-7.4) so that when we install install PHP using dnf then it will automatically
pick packages from remi-7.4 module
Step 2) Enable latest PHP Module Stream
(remi-7.4)
[root@centos8]# dnf module list php
[root@centos8]# dnf module enable php:remi-7.4
5. Page | 4
Step 6) Configuring and Securing PHP-
FPM and Nginx
[root@centos8]# nano /etc/php-fpm.d/www.conf
Uncomment the following parameters and set their values to the user and group
to match the user and group Nginx is running as:
listen.owner = nginx
listen.group = nginx
listen.mode = 066
Step 7) Configuring Timezone
[root@centos8]# nano /etc/php.ini
8. Page | 7
Step 12) Configuring Nginx Server Block
for Laravel
[root@centos8]# nano /etc/nginx/conf.d/<<project_name>>.conf
# copy and paste the following into the <<project_name>>.conf
server {
listen 80;
server_name <<project_name>>.;
root /var/www/html/<<project_name>>/public;
index index.php;
charset utf-8;
gzip on;
gzip_types text/css application/javascript text/javascript
application/x-javascript image/svg+xml text/plain text/xsd text/xsl text/xml
image/x-icon;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ .php {
include fastcgi.conf;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass unix:/run/php-fpm/www.sock;
}
location ~ /.ht {
deny all;
}
}
9. Page | 8
# Save the file and check if the Nginx configuration syntax is correct by running.
[root@centos8]#nginx -t
[root@centos8]# systemctl restart php-fpm
[root@centos8]# systemctl restart nginx
10. Page | 9
Step 13) Update the Security Context
[root@centos8#yum -y install policycoreutils-python-utils
[root@centos8#semanage fcontext -a -t httpd_sys_rw_content_t
'/var/www/html/<<project_name>>(/.*)?'
[root@centos8#semanage fcontext -a -t httpd_sys_rw_content_t
'/var/www/html/<<project_name>>/public(/.*)?'
[root@centos8#semanage fcontext -a -t httpd_sys_rw_content_t
'/var/www/html/<<project_name>>/storage(/.*)?'
[root@centos8#semanage fcontext -a -t httpd_sys_rw_content_t
'/var/www/html/<<project_name>>/app(/.*)?'
[root@centos8#semanage fcontext -a -t httpd_sys_rw_content_t
'/var/www/html/<<project_name>>/bootstrap(/.*)?'
[root@centos8#semanage fcontext -a -t httpd_sys_rw_content_t
'/var/www/html/<<project_name>>/config(/.*)?'
[root@centos8#semanage fcontext -a -t httpd_sys_rw_content_t
'/var/www/html/<<project_name>>/database(/.*)?'
[root@centos8#semanage fcontext -a -t httpd_sys_rw_content_t
'/var/www/html/<<project_name>>/resources(/.*)?'
[root@centos8#semanage fcontext -a -t httpd_sys_rw_content_t
'/var/www/html/<<project_name>>/routes(/.*)?'
[root@centos8#semanage fcontext -a -t httpd_sys_rw_content_t
'/var/www/html/<<project_name>>/vendor(/.*)?'
[root@centos8#semanage fcontext -a -t httpd_sys_rw_content_t
'/var/www/html/<<project_name>>/tests(/.*)?'
[root@centos8#restorecon -Rv '/var/www/html/<<project_name>>/'
11. Page | 10
Step 14) Accessing Laravel Website from a
Web Browser
Type the following command to get the IP address of the current
server:
[root@centos8#ip ad
Create the host name inside the hosts file in /etc/hosts .
Next, open a web browser on the local machine and use the following address
to navigate.
http://<<project_name>>