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

WPS2's avatar
Level 1

Laravel Deployment on AWS EC2 Ubuntu 14.04

Hi All I am trying to deploy laravel 5.1 project on AWS EC2 cloud server and having an issue with laravel web site route URLs.

I ran following commands to configure the EC2 ubuntu 14.04 LTS server.

sudo apt-get install apache2
sudo apt-get install mysql-server php5-mysql
sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt
sudo apt-get install php5 php-pear
sudo apt-get install curl php5-curl php5-cli git
sudo a2enmod rewrite
sudo php5enmod mcrypt
sudo service apache2 restart

sudo chmod -R 777 storage

it loads the /var/www/html/mynewhost/resources/views/auth/login.blade.php template as the home page. So I think Route::get('/', 'Auth\AuthController@getLogin') route is working.

but i am getting the following error when I try access any other route URLs. (eg. www.mynewhost.com/register)

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /register was not found on this server.</p>
<hr>
<address>Apache/2.4.7 (Ubuntu) Server at xxxx.ap-southeast-2.compute.amazonaws.com Port 80
</address>
</body></html>

I have changed the apache route URL to the public folder of my laravel project. Also I tried 2 enable the following virtual host file while the apache root is /var/www/html, but still got the same error.

<VirtualHost *:80>
    ServerAdmin admin@mynewhost.com
    ServerName mynewhost.com
    ServerAlias www.mynewhost.com
    DocumentRoot /var/www/html/mynewhost/public
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

sudo a2ensite mynewhostl.com.conf
sudo service apache2 reload
sudo service apache2 restart

do I need to grant any permission to my laravel project folder?

appreciate any help.

PS. this is a duplicate post of https://laracasts.com/discuss/channels/laravel/laravel-deployment . re-posting again to clear the mess

0 likes
3 replies
Snapey's avatar
Snapey
Best Answer
Level 122

The page not found error you are seeing seems to be from apache and not from Laravel. This means that for anything other than / (where you would by default get index.php), the .htaccess is not catching the request and sending you to index.php

is mod_rewrite working I wonder?

is .htaccess in your public folder?

try the alternate .htaccess http://laravel.com/docs/master/installation#pretty-urls ?

1 like
WPS2's avatar
Level 1

@Snapey it worked. i think something wrong with my mod_rewrite module. I added the following lines to /etc/apache2/sites-available/000-default.conf file and now all routes are working fine. :)

<Directory "/var/www/html">
    AllowOverride All
</Directory>

thanks again for your help.

Please or to participate in this conversation.