Skip to content

Instantly share code, notes, and snippets.

@felipepodesta
Forked from zaherg/install.md
Last active December 30, 2015 20:18
Show Gist options
  • Save felipepodesta/7879376 to your computer and use it in GitHub Desktop.
Save felipepodesta/7879376 to your computer and use it in GitHub Desktop.

Creating Your Laravel & nginx Server

I will install Larave 4.0/4.1 with PHP5.5 & Latest nginx on Ubuntu 12.04.3 x64.

updating your system

	apt-get update && apt-get upgrade
	adduser [username]
	usermod -aG sudo [username]
	apt-get -y install git

Now you will have to logout then you need to login using the user you create

	git config --global user.name "your name"
	git config --global user.email [email protected]

installing latest nginx version

	sudo -s
	nginx=stable
	apt-get -y install python-software-properties
	add-apt-repository ppa:nginx/$nginx
	apt-get update && apt-get upgrade
	apt-get -y install nginx
	service nginx start
	exit

installing php5.5

	sudo -s
	add-apt-repository ppa:ondrej/php5
	apt-get update && apt-get upgrade
	apt-get -y install php5-fpm php5-mcrypt php5-sqlite sqlite php5-cli php5-xcache php5-curl

Just remember that if you want to install mysql you should also install php5-mysql and any other required module.

installing composer

	curl -sS https://getcomposer.org/installer | php
	sudo mv composer.phar /usr/local/bin/composer

installing laravel

	sudo -s
	cd /var
	mkdir www
	chown -R [username]:[username] www
	exit
	cd www && composer create-project laravel/laravel

But if you like to install Laravel 4.1, you can do like :

	cd www & composer create-project laravel/laravel:dev-develop

I will just change the owner of the storage directory to be the web server, or you can just make it writable for all users, I like changing the ownership ..

	chown -R www-data:www-data laravel/app/storage

configure nginx for laravel

	sudo -s
	cd /etc/nginx/sites-avaliable
	rm default
	nano default

then you have to paste this and edit it as you need

server {

    # Port that the web server will listen on.
    listen          80;

    # Host that will serve this project.
    server_name     .jasmine.dev;

    # Useful logs for debug.
    access_log      /var/www/laravel/access.log;
    error_log       /var/www/laravel/error.log;
    rewrite_log     on;

    # The location of our projects public directory.
    root            /var/www/laravel/public;

    # Point index to the Laravel front controller.
    index           index.php;

    location / {

        # URLs to attempt, including pretty ones.
        try_files   $uri $uri/ /index.php?$query_string;

    }

    # Remove trailing slash to please routing system.
    if (!-d $request_filename) {
        rewrite     ^/(.+)/$ /$1 permanent;
    }

    # PHP FPM configuration.
    location ~* \.php$ {
            fastcgi_pass                    unix:/var/run/php5-fpm.sock;
            fastcgi_index                   index.php;
            fastcgi_split_path_info         ^(.+\.php)(.*)$;
            include                         /etc/nginx/fastcgi_params;
            fastcgi_param                   SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    # We don't need .ht files with nginx.
    location ~ /\.ht {
            deny all;
    }
    
    # Set header expirations on per-project basis
    location ~* \.(?:ico|css|js|jpe?g|JPG|png|svg|woff)$ {
            expires 365d;

    }
}

final small steps:

I like to have a link to my Laravel installation under my home directory so :

	$ ln -s /var/www/laravel www

Finally i restart nginx or you can just reboot your VPS.

	sudo service nginx restart

http://blog.sensible.io/2013/08/20/setting-up-redis-for-production-environment.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment