Call + (44) 0843 289 4539

Upgrade from LAMP to LEMP ubuntu 14.04

I needed to upgrade my Ubuntu 14.04 LAMP (Linux, Apache, MySql, PHP5) stack development machine to a LEMP (Linux, Nginx, MySQL, PHP7).  My first instinct was to turn to the internet and consult the millions of blog posts and forum posts, but they all seem to be lacking vital bit of information I was after in my particular situation.

I have detailed the complete steps I undertook to complete the upgrade.

Remove PHP 5

I wanted to completely remove PHP5 from my workstation.  I found by using the bash command was the best approach

sudo bash -c "sudo apt-get remove php*"
sudo apt-get update
sudo apt-get purge php5-fpm
sudo apt-get --purge autoremove

Remove phpMyAdmin

Although this command is not necessarily for removing phpMyAdmin, it appears when you remove php5-mcrypt it removes phpmyadmin.

sudo apt-get purge php5-mcrypt

Remove Apache

sudo apt-get remove apache2*

Once complete ensure all is clean by executing an autoremove

sudo apt-get autoremove

Our workstation should now be ready for re-configuring it for LEMP.

Install PHP7

It seems that PHP7 is not currently in the default ubuntu repository, so we will need to add a private repository .

sudo add-apt-repository ppa:ondrej/php

Now install all the PHP modules required

sudo apt-get install php7.0-fpm php7.0-mysql php7.0-curl php7.0-gd php7.0-json php7.0-mcrypt php7.0-opcache php7.0-xml php7-mbstring

Install NGINX

 sudo apt-get install nginx

Update NGINX Default site configuration

I just used Gedit to open the file and copied and pasted the configuration over.

sudo gedit /etc/nginx/sites-enabled/default
server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /var/www/html;
    index index.php index.html index.htm;

    server_name localhost;

    location / {
        try_files $uri $uri/ =404;
    }

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

Save and close Gedit and now we can test our configuration

sudo nginx -t

We also edit the PHP.ini file

sudo gedit /etc/php/7.0/fpm/php.ini

Findcgi.fix_pathinfo without quotation mark. change its value to 0 like this: cgi.fix_pathinfo=0 and save it

Install the new PHP-FPM package

sudo apt-get install php7.0-fpm

Install phpMyadmin

sudo apt-get install phpmyadmin
sudo ln -s /usr/share/phpmyadmin/ /var/www/html/
sudo service nginx restart

 

Follow Me

Gary Woodfine

Helps businesses by improving their technical proficiencies and eliminating waste from the software development pipelines.

A unique background as business owner, marketing, software development and business development ensures that he can offer the optimum business consultancy services across a wide spectrum of business challenges.
Follow Me
%d bloggers like this: