Kunok Kunok - 3 months ago 17
PHP Question

After deploying CakePHP3 application to Ubuntu server, all assets return 404 response

When I deployed my CakePHP3 application to the Ubuntu server into

var/www/html/{project_name}
directory using git push, all assets such as images, css files, javascripts, etc...from the webroot folder are not loading. They return 404 response.

enter image description here

This is my
.htaccess
file inside
webroot
directory:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^$ / [L]
RewriteRule (.*) /$1 [L]
AllowOverride All
</IfModule>


And this is my
.htaccess
inside root directory:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>


<IfModule mod_rewrite.c>
RewriteEngine On
ReWriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

Answer

I fixed this by running composer install from the root project directory.

Note that if your server uses PHP7 rather than PHP5 for your app, you should install universal packages rather than dropped PHP5 packages.