How to Install Laravel 6.x stack on Linux Centos 7.x

1. Check your Linux Centos version

cat /etc/centos-release

2. First of all, you need to enable REMI and EPEL repositories in your Linux distribution to have the updated packages (PHP, Nginx, MariaDB, etc.) using following commands

rpm -Uvh

rpm -Uvh

3. Install Nginx server

yum install nginx

4. Enable Nginx

systemctl start nginx

systemctl enable nginx

systemctl status nginx

5.* (If you have a firewall*) To access nginx from public network, you need to open a port 80 on your system firewall to receive external requests as shown.

firewall-cmd --permanent --add-port=80/tcp

firewall-cmd --reload

6. Install MySQL

yum install mariadb-server php-mysql

systemctl start mariadb.service


7.1 Install PHP

yum install yum-utils
yum-config-manager --enable remi-php72
yum install php php-fpm php-common php-xml php-mbstring php-json php-zip php7.0-bcmath

7.2 Enable PHP-FPM

systemctl start php-fpm

systemctl enable php-fpm

systemctl status php-fpm

8. Install Composer

curl -sS | php

mv composer.phar /usr/local/bin/composer

chmod +x /usr/local/bin/composer

9. Install Laravel

cd /var/www/html/

sudo composer create-project --prefer-dist laravel/laravel mylaravelsite

10. Check if Laravel was installed

cd /var/www/html/mylaravelsite

ls -l

11. Configure Laravel Installation for Nginx

chmod -R 775 /var/www/html/mylaravelsite

chown -R apache.apache /var/www/html/mylaravelsite

chmod -R 777 /var/www/html/mylaravelsite/storage/

12. If you have SELinux enabled, you need to update the security context of the storage and bootstrap/cache directories using following commands.


semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/testsite/bootstrap/cache(/.*)?'

semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/testsite/storage(/.*)?'

restorecon -Rv '/usr/share/nginx/html/testapp'

13. Create a environment file for your Laravel application, using the sample file provided.

.env.example .env

14. Generate and set your application key to a random string using following command.

php artisan key:generate

15. Configure Nginx

vi /etc/nginx/conf.d/mylaravelsite.conf

server {
	listen      80;
	root        /var/www/html/mylaraveltsite/public;
	index       index.php;

	#log your server errors
	access_log /var/log/nginx/laravel-access.log;
	error_log /var/log/nginx/laravel-error.log;

	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)(/.+)$;
	location ~ /\.ht {
		deny all;

16. Restart Nginx

systemctl restart nginx

17. Access laravel website

If you do not have a fully registered domain name, you need to use the /etc/hosts file to create a local DNS for testing.

Check your server IP address

ip addr show

Add the the following line in your /etc/hosts file as shown (change the IP with your own);

18. Check if Laravel is working

If you are developing locally, you may employ PHP’s built-in development server to serve your application or site, as follows. This command will start a development server at http://localhost:8000 or On CentOS/REHL, this port should be opened in the firewall for you to serve your application this way.