Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Bruin's avatar
Level 1

Installing Laravel is a &^$%#HELL

what am i using:

ubuntu0.18.04.2 PHP Version 7.2.24-0

site location: /var/www/vhosts/maindomain/subdomain/laravelproject

what did I do to install laravel

sudo apt-get upgrade

sudo add-apt-repository ppa:ondrej/php

sudo apt-get update

sudo apt-get install apache2 libapache2-mod-php7.2 php7.2 php7.2-xml php7.2-gd php7.2-opcache php7.2-mbstring

cd /tmp

curl -sS https://getcomposer.org/installer | php

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

cd /var/www/vhosts/maindomain/subdomain/

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

sudo chgrp -R www-data ./laravel

sudo chmod -R 775 ./laravel/storage

cd /etc/apache2/sites-available

nano laravel.conf

the laravel.conf

"<VirtualHost *:80>

ServerName subdomainname.nl

DocumentRoot "/var/www/vhosts/domainname.nl/subdomainname/laravel"

<Directory /var/www/vhosts/domainname.nl/subdomainname/laravel>

     DirectoryIndex index.php

     AllowOverride All

     Require all granted

</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log

CustomLog ${APACHE_LOG_DIR}/access.log combined

"

sudo a2dissite 000-default.conf

sudo a2ensite laravel.conf

sudo a2enmod rewrite

sudo service apache2 restart

cd /var/www/vhosts/domainname.nl/subdomainname/laravel

nano .htaccess

the .htaccess file:

"

<IfModule mod_negotiation.c>

    Options -MultiViews -Indexes

</IfModule>

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)/$ / [L,R=301]

RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^ index.php [L]

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_URI} !^/public/

RewriteRule ^(css|js|images)/(.*)$ public// [L,NC]

RewriteRule ^\.env$ - [R=404,L,NC]

"

sudo find laravel/ -type f -exec chmod 644 {} ;

sudo find laravel/ -type d -exec chmod 775 {} ;

Question: Where do I go wrong!!!!

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

0 likes
16 replies
Bruin's avatar
Level 1

Hi Tray2,

Thanks for the reply.

But, not that easy...

sudo: add-apt-repository: command not found

That's mostly te thing, the default tutorials are missing some things.

Tray2's avatar

I've followed that guide myself without any issues.

What user are you logged in as?

Have you done sudo su?

Just ran the command on my server and no issue.

Bruin's avatar
Level 1

And after:

sudo apt-get install software-properties-common

the command: sudo composer create-project laravel/laravel your-project --prefer-dist was working, but still error 500

rawilk's avatar

If your linux skills aren't very strong, I'd highly recommend using a service like Laravel Forge to set the server up for you.

1 like
Tray2's avatar

You should never use sudo when running composer. All the files it generates belongs to root if you do and www-data can't read them.

To get it working you need to sudo chown -R www-data:www-data /var/www/<your-site>then you need to `sudo chmod -R 755 /var/www/<your-site>/storage

It's better to remove the folder and then create new Laravel project.

Updated to 755 since it's "bad" practice.

Sinnbeck's avatar

Shouldn't that have been

sudo chmod -R 755 /var/www/<your-site>/storage

:)

Bruin's avatar
Level 1

`sudo chmod -R 777 /var/www/<your-site>/storage lets not do that.... never never never put 777 on you server!

If you do so the whole world can write on your files

Sinnbeck's avatar

To be fair, it requires others to have access to the server. But best practice is 755

Bruin's avatar
Level 1

Thank Sinnbeck ;-) but still not working

Sinnbeck's avatar

Get errors? Using apache or nginx? Check the log files under /var/log

Tray2's avatar

@sinnbeck You are correct but for the storge folder it's no biggie imho.

@bruin Well I wouldn't worry too much about that 777 on that folder.

Sinnbeck's avatar

@tray2 Well don't want to highjack this thread but let's say I put in a php file in the public storage directory that extracts all config variables, and then call it using the website though public storage

Tray2's avatar

@sinnbeck True but wouldn't that also be true with 755, since when you hit that file it's run as www-data?

Sinnbeck's avatar

@tray2 yes but as other users can't add files, they can't add the php file. 5 is read and execute :)

Sorry. I will focus on the issue at hand now

Snapey's avatar

in your virtual host config, the document root needs to be the public folder

DocumentRoot "/var/www/vhosts/domainname.nl/subdomainname/laravel/public"

Please or to participate in this conversation.