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:
Quote:
$ 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:
Quote:
$ 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:
Quote:
$ /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.
Quote:
$
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.
Quote:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') ===
'544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061'
) { 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:
Quote:
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:
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:
Quote:
$ 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.