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

Hi Guys,

I have couple of projects that I am planning to deploy on amazon ec2 cloud server. As i have two projects, i cannot make the laravel "public" folder the root directory in the settings. is there a better way to deploy 2 laravel projects on same web server?

I am going to deploy on apache web server ( LAMP server ) on ubuntu 14.04. what is the best web server to deploy laravel project? is Nginx better then Apache?

updating the post : for the testing purposes i am deploying this on ubuntu server running on a virtual box. i have created the following virtual host.

<VirtualHost *:80>
        ServerName 192.168.0.6
        DocumentRoot /var/www/html/mysite/public

        <Directory /var/www/html/mysite/public>
            AllowOverride All
            Require all granted
        </Directory>
</VirtualHost>

and granted the permission using following.

sudo chmod 777 -R mysite/
sudo chmod 777 -R mysite/*

now i can access the site from my local machine with http://192.168.0.6/mysite/public/ url, but the css,img,js does not load correctly. it's looking for the css,js and img in http://192.168.0.6/ location instead of http://192.168.0.6/mysite/public/

appreciate any help

Thanks

0 likes
32 replies
tgif's avatar

@WPS2 Is this setup just for development at the moment? If it is in dev, what does the /etc/hosts look like and what is in your /etc/apache2/sites-enabled directory?

My hosts file contains:

127.0.0.1       localhost
127.0.0.1       controlll.dev

my sites-enabled dir contains a conf file named exactly as my website directory: controll -> controll.conf. It contains this:

<VirtualHost *:80>
        ServerAdmin webmaster@controlll.dev
        DocumentRoot /var/www/controlll.dev/public
        ServerName controlll.dev
        ServerAlias www.controlll.dev


        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/controlll/public>
                Options Indexes FollowSymLinks Includes ExecCGI
                AllowOverride All
                Order Allow,Deny
                Allow from All
        </Directory>
tgif's avatar

And I would rethink the 777. I'm pretty sure you should go with 755. 777 gives unfettered access

WPS2's avatar
Level 1

@csuarez thanks for the reply. I am doing a pre-deployment on ubuntu server on my virtual box before do the actual development on the ec2 could server. my ubuntu server version is same as the ec2 could server version. but yes both running on local environment and there is no permanent ip address on local hosting server.

i ran the following command to change the server name to localhost

 echo "ServerName localhost" | sudo tee /etc/apache2/conf-available/fqdn.conf

but my etc/host.conf file is as follows

127.0.0.1       localhost
127.0.1.1       ubuntuserver

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

i have 000-default.conf in /etc/apache2/sites-available and its content as follows

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

conf file name in my sites-enabled dir not same as the laravel project folder. should it be the same?

Snapey's avatar

Use apache virtual hosts on your EC2 instance?

1 like
tgif's avatar

@WPS2 that is the way it was taught to me. That may not be the source of your problem but you could give it a try. I've only setup dev server's. Going into production is a different beast that I've yet to tackle.

I remember early on being instructed to change some of the Apache2 httpd.conf file settings like the DirectoryIndex.

I'd hate to send you on a wild goose chase but when I run into these problems I try everything. Good luck:)

michaeldyrynda's avatar

So you have domain.com and want to have domain.com/project1 and domain.com/project2?

/var/www/html/mysite/project1
/var/www/html/mysite/project1/app
...
/var/www/html/mysite/project1/public
/var/www/html/mysite/project2
/var/www/html/mysite/project2/app
...
/var/www/html/mysite/project2/public

If so, you can use a location directive in your apache config to point /project1 to /var/www/html/mysite/project1/public and /project2 to /var/www/html/mysite/project2/public, but this is messy.

Consider either different domains or subdomains i.e. project1.domain.com with a DocumentRoot of /var/www/project1/public and project2.domain.com with a DocumentRoot of /var/www/project2/public - note each project is now out of the main public (html) directory.

1 like
WPS2's avatar
Level 1

hi guys,

thanks you all for the replies. I couldn't get it worked on my local server. So I tried on deploy 1 web site on my live amazon ec2 cloud server and now I am getting a different error message.

It's loaded the home page, but look like the route urls are not working. I get the "Not Found, The requested URL /register was not found on this server" error message when I try to navigate to www.mynewhost.com/register or http://************.ap-southeast-2.compute.amazonaws.com/register

I changed the apache root directory to laravel public folder and this is what i have in my /etc/apache2/sites-available/000-default.conf

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

I am using laravel 5.1 and I have ran the following command to configure apache and mysql.

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

And also I ran the following command to grant the permission to storage folder

 chmod -R 777 storage

Do i need to assign any permission to my laravel project folder? May be I am getting this error because of my lack of php/ubuntu knowledge as this is my 1st php/laravel project. I was mainly doing the .net development.

appreciate any help.

Snapey's avatar

If you use virtual host then you have to name your site in the VH directives so that when the request arrives, apache can direct it to the correct virtual host.

I put both directives but not sure they are both needed

    ServerName mynewhost.com
    ServerAlias mynewhost.com

Then if you don't yet have the domain name setup, put an entry in your hosts file so that your browser is requesting pages from mynewhost.com

WPS2's avatar
Level 1

@Snapey thanks for the quick response. mynewhost.com home page is loading but the the route URLs does not work. i.e. mynewhost.com/register etc

Before changed the apache root directory to laravel public folder, I did enable the following virtual host file but got the same error. that's why i changed the apache root directory.

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

Which way u used to link your external css/js file ? Like :

<link rel="stylesheet" type="text/css" href="theme.css">
or 
HTML::style('theme.css')
WPS2's avatar
Level 1

@Shahin I am using the following syntax to link the css/js files within blade templates. But actually my main issue is the route URLs. I get the "Not Found, The requested URL /register was not found on this server" error even when I enter the www.mynewhost.com/register from the address bar though my home page is working.

<link href="/css/imageupload.css" rel="stylesheet">
<script src="/js/jquery.cookie.js"></script>
Shahin's avatar

Ok, Firstly it's better to u use blade syntex for link your external file otherwise some remote server occur problems for this. Like

HTML::style('theme.css')

anyway, Which syntax you used to link your route?

Like:

<a href="some-route">A link</a>
or 
{{URL::to('some-route')}}
Shahin's avatar

Yap, It's better you write blade syntax. Specially for External files && link/menu.

WPS2's avatar
Level 1

@Shahin sorry I ddidn't understand what do you mean by link systax and thought you are asking how i am linking css/js files. my bad. to answer your question, there is no link. its a form post as follows.

            <div class="col-md-4">
              <div class="block">
                <h3><i class="fa fa-user-plus"></i> Registration</h3>
                <form id="registration" name="registration" action="/register" method="post">
                    {!! csrf_field() !!}
                  <label for="username">User Name</label>
                  <input id="username" name="username" type="text" class="form-control" placeholder="User name" value="test">
                  <label for="password">Password</label>
                  <input id="password" name="password" type="password" class="form-control" placeholder="Password" value="test12">
                  <label for="password_confirmation">Confirm Password</label>
                  <input id="password_confirmation"  name="password_confirmation" type="password" class="form-control" placeholder="Confirm Password" value="test12">
                  <label for="email">Email</label>
                  <input id="email" name="email" type="email" class="form-control" placeholder="Email Address" value="test@gmail.com">
                  <label for="sex">I am a </label>
                    {!! Form::select('sex', Config::get('constants.sex'), old('sex_id') ? '' : '', array('class' => 'form-control')) !!}
                  <label for="dob">Date of Birth</label>
                  <input id="dob" name="dob" type="text" class="form-control datepicker" placeholder="Date of Birth" readonly value="1981-Feb-04">
                  <label for="country">Country</label>
                    {!! Form::select('country', Config::get('constants.country'), old('country_id') ? '' : '14',array('class' => 'form-control')) !!}
                  <button type="submit" class="btn">Sign Up</button><br>
                  By continuing, you're confirming that you've read and agree to our <a>Terms and Conditions</>, <a>Privacy Policy</a> and <a>Cookie Policy</a>
              </form>
              </div>
            </div>

Shahin's avatar

Ok, At first change the form

<form id="registration" name="registration" action="/register" method="post">

To 

{!! Form::open(['url' => '/register', 'id' => 'registration', 'role' => 'form']) !!}
{!! Form::close() !!}

and remove {!! csrf_field() !!} and for my better understand please tell me details which controller system r u used? Implicit Controllers ?

Like?

Route::controller('register', 'RegisterController');
WPS2's avatar
Level 1

@Shahin I use the basic controllers not the implicit contollers

    return view('index');
});

// Authentication routes...
Route::get('/', 'Auth\AuthController@getLogin');
Route::post('/', 'Auth\AuthController@postLogin');
Route::get('logout', 'Auth\AuthController@getLogout');

// Registration routes...
Route::get('register', 'Auth\AuthController@getRegister');
Route::post('register', 'Auth\AuthController@postRegister');
Shahin's avatar

ok, never mind please check it..like

Route::post('/register', function () {
return 1;
});
WPS2's avatar
Level 1

@Shahin I tried it with the GET, but its still not working

new routes.php


Route::get('/login', function () {
    return view('index');
});

Route::get('/register', function () {
return 1;
});

// Authentication routes...
Route::get('/', 'Auth\AuthController@getLogin');
Route::post('/', 'Auth\AuthController@postLogin');
Route::get('logout', 'Auth\AuthController@getLogout');

// Registration routes...
Route::get('register1', 'Auth\AuthController@getRegister');
Route::post('register1', 'Auth\AuthController@postRegister');

this is the error page

<!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 xxxxxxxxx.ap-southeast-2.compute.amazonaws.com Port 80
</address>
</body></html>
1 like
Shahin's avatar

Well this depends on how you installed it, I think it's your server problem. configure it correctly. check your server version cause of many dependency in server :(

1 like
WPS2's avatar
Level 1

@Shahin thanks mate.

Hi Guys

I am still having the issue is the route URLs. I get the following error when I try access any route URL but my home page is working correctly.

<!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 xxxxxxxxx.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 but still got the same error.

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

And also I ran the following command to grant the permission to storage folder

 chmod -R 777 storage

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

WPS2's avatar
Level 1

hi all

I just noticed that my .env file has got the app_env variable set to local. please see the below for the same.

APP_ENV=local
APP_DEBUG=true

do i need to change this?

Shahin's avatar

APP_ENV=local is right. anyway post your question on stackoverflow :)

Snapey's avatar

There is a lot of pointless information in this thread. So, to start with, do ANY routes work? IE, your homepage for instance?

Any indication that you are hitting the Laravel index.php file?

What .htaccess file do you have?

WPS2's avatar
Level 1

@Snapety yes it loads the /var/www/html/mynewhost/resources/views/auth/login.blade.php template as the home page. That means Route::get('/', 'Auth\AuthController@getLogin') route is working isnt it? (that is the only working route)

this is my .htaccess file in public folder

<VirtualHost *:80>
<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

</VirtualHost>

Snapey's avatar

Can you please php artisan route:list and post the result?

Next

Please or to participate in this conversation.