Click here to Skip to main content
13,794,250 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


2 bookmarked
Posted 13 Jan 2018
Licenced CPOL

Installing & Configuring Laravel

, 13 Jan 2018
Rate this:
Please Sign up or sign in to vote.
Set up laravel 5 and set permissions for the Apache user to write to storage directory

Many times, after installing laravel, there is usually an access error message of the storage directory when trying to access the laravel home page of your project. While doing a "chmod -R 777" (allowing full access) on the project folder solves the issue, it is not a safe approach but rather you should allow apache user write access to the necessary folders while denying everyone else.

In this article, I will take you through a typical laravel setup. I will assume you are using linux and xampp is already installed. If not, you can find the tutorial here.

Once xampp is installed, you will need to change ownership of the htdocs directory from root to your current user. This is because you will not be editing your code in this folder as the root user but as regular user. To do this, you should change owner of the htdocs directory and all directories within like this:


$ sudo chown username -R /opt/lampp/htdocs/

You will need to make PHP command available globally in the terminal because by default, for example, you will get an error if you run the following command:


$ php --version

Without making the php command globally available, you will always need to type the full path to php as shown below which is usually cumbersome:


$ /opt/lampp/bin/php --version


To correct this, edit your .bashrc to add the desired directory on the PATH environmental variable. The directory in this case is the bin folder located at /opt/lampp/bin. Type the following at the command line terminal.


$ export PATH=/opt/lampp/bin:$PATH

$  source ~/.bashrc

With /opt/lampp/bin directory set to the PATH environmental variable, navigate to this folder and install composer. This will create a file called "composer" in the bin directory. Note that the composer command will also be available system wide on the terminal.

php -r "copy('', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === 
) { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); 
} echo PHP_EOL;"
php composer-setup.php --filename=composer
php -r "unlink('composer-setup.php');"

Navigate to htdocs folder (/opt/lampp/htdocs) and install laravel:


composer create-project laravel/laravel yourprojectname

After installation is complete, you will then need to make sure the Apache user has write permissions to the storage folder and the bootstrap/cache folder of your just installed project. For xampp set up, the Apache user is called "daemon" but you can also create a small PHP script and run in to get the Apache username as follows:

// <?php
// echo exec(whoami);

This shows the Apache username on a web page. You then have to give this user write permissions on the boostrap/cache and storage folder of your project. Navigate to your project folder and type the following:


$ sudo chgrp -R daemon storage bootstrap/cache

$ sudo chmod -R ug+rwx storage bootstrap/cache

You should now be able to view the laravel home page of your new application with no errors.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Kenya Kenya
No Biography provided

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web02 | 2.8.181207.3 | Last Updated 13 Jan 2018
Article Copyright 2018 by fnjauke
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid