Skip to content

Instantly share code, notes, and snippets.

@zaherg
Last active October 18, 2020 17:45
Show Gist options
  • Save zaherg/7812986 to your computer and use it in GitHub Desktop.
Save zaherg/7812986 to your computer and use it in GitHub Desktop.
a small tips to install latest nginx , php 5.5 & laravel 4.1 since that Laravel 4.1 has been released, i have removed the line which explain how to install laravel from dev branch using composer.

Creating Your Laravel & nginx Server

We will install Larave 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 we need to logout and login using the user which we have created

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

installing latest nginx version

Ubuntu 12.04 does not include the latest stable version of nginx, thats why we need to add the repository from the nginx website

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

When installing Ubuntu 12.04 you will get the version 5.3.x of php, and since the latest version is 5.5.x, we need to add an external repository to make sure we get the latest version of php.

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 php5-json

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

note :

Someone noted out there that you should edit your php.ini file and change the value of cgi.fix_path

sudo -s
nano /etc/php5/fpm/php.ini

change the value of cgi.fix_path from :

;cgi.fix_path = 1

to

cgi.fix_path = 0

installing composer

Installing Composer is simple and easy, we download the composer.phar file then we copy it to the bin directory to make sure that we can use it globaly.

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

From time to time we need to make sure that we have the latest version of composer so we issue the command:

sudo composer self-update

installing laravel

Now that we have installed composer we can use it to install laravel in a dirctory of our choice, commenly used /var/www , most severs by default does not have it if they dont have apache installed by default .

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

We will just change the owner of the storage directory to be the web server, or we 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

Now that we have everything we need, we still have one last step, which is to configure nginx so that it will serve our site.

sudo -s
cd /etc/nginx/sites-avaliable
# if you didnt find this directory, try to check `/etc/nginx/conf.d/`
rm default
nano default

then we have to paste this and edit it as we 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 steps:

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

	$ ln -s /var/www/laravel www

Finally we restart nginx or we can just reboot your VPS.

	sudo service nginx restart
@zaherg
Copy link
Author

zaherg commented Jan 1, 2014

for digitalocean you can do this

Heads Up: If you're installing Laravel on DigitalOcean's 512MB VPS, make sure you add a swapfile to Ubuntu to prevent it from running out of memory. You can quickly do this by issuing the following commands. This will only work during 1 session, so if you reboot during this tutorial, add the swapfile again.

dd if=/dev/zero of=/swapfile bs=1024 count=512k
mkswap /swapfile
swapon /swapfile

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