Skip to content

Instantly share code, notes, and snippets.

@khlbrg
Forked from zaherg/install.md
Last active April 2, 2016 19:53
Show Gist options
  • Save khlbrg/7819495 to your computer and use it in GitHub Desktop.
Save khlbrg/7819495 to your computer and use it in GitHub Desktop.
Creating Your Laravel & nginx Server

Creating Your Laravel & nginx Server

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 youremail@serviceprovider.com

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

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment