We will install Larave 4.1 with PHP5.5 & Latest nginx on Ubuntu 12.04.3 x64.
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]
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
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.
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 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
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
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;
}
}
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
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.