How To Install Laravel PHP Framework With Nginx On CentOS 8
How To Install Laravel PHP Framework With Nginx On CentOS 8
How To Install Laravel PHP Framework With Nginx On CentOS 8
# dnf update
# dnf install nginx php php-fpm php-common php-xml php-
mbstring php-json php-zip mariadb-server php-mysqlnd
2. When the LEMP installation is complete, you need to start the PHP-
PFM, Nginx and MariaDB services using the following systemctl
commands.
3. Next, you need to secure and harden the MariaDB database engine using
the security script as shown.
# mysql_secure_installation
# firewall-cmd --reload
5. Finally, you can confirm that your LEMP stack is running using a browser
at your system’s IP address.
http://server-IP
# vi /etc/php-fpm.d/www.conf
listen.owner = nginx
listen.group = nginx
listen.mode = 066
Set Listen Socket Ownership to Nginx
8. Next, also set the system-wide time zone in the /etc/php.ini configuration
file.
# vi /etc/php.ini
Look for the line “;date.timezone” and uncomment it, then set its value as
shown in the screenshot (use values that apply to your region/continent and
country).
date.timezone = Africa/Kampala
Set Timezone
in PHP
9. To mitigate the risk of Nginx passing requests from malicious users who
use other extensions to execute PHP code to PHP-FPM, uncomment the
following parameter and set it’s value to 0.
cgi.fix_pathinfo=1
# mv composer.phar /usr/local/bin/composer
# chmod +x /usr/local/bin/composer
# cd /var/www/html/
# ls -la mysite.com/
List Laravel Files
14. Next, you need to configure the correct ownership and permissions on
the storage and the bootstrap/cache directories to be writable by the Nginx
web server.
# chown -R :nginx
/var/www/html/mysite.com/bootstrap/cache/
# chmod -R 0775
/var/www/html/mysite.com/bootstrap/cache/
15. If SELinux enabled on your server, you should also update the security
context of the storage and bootstrap/cache directories.
# vi /etc/nginx/conf.d/mysite.com.conf
Copy and paste the following configuration in the file. Take note of the root
and fastcgi_pass parameters.
server {
listen 80;
server_name mysite.com;
root /var/www/html/mysite.com/public;
index index.php;
charset utf-8;
gzip on;
location / {
location ~ \.php {
include fastcgi.conf;
fastcgi_split_path_info
^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php-fpm/www.sock;
location ~ /\.ht {
deny all;
}
17. Save the file and check if the Nginx configuration syntax is correct by
running.
# nginx -t
http://mysite.com