Install Nginx, Php-Fpm and MySql on Debian

In Linux, Tutorial 1650 views

This tutorial explains how to install nginx/MySQL/PHP-fpm, as well as all of the required repos to download nginx and php-fpm. It will also review how to configure php and nginx, as well as how to create a php info page.

1) Update Apt-Get

The apt-get update command is used to re-synchronize the package index files from their sources. If used in combination with the apt-get upgrade command, they install the newest versions of all packages currently available.

At the moment, we only need to do a thorough update:

sudo apt-get update

2) Install MySQL on your VPS

MySQL is a powerful database management system used for organizing and retrieving data

To install MySQL, open terminal and type in these commands:

sudo apt-get install mysql-server

During the installation, MySQL will ask you to set a root password. If you miss the chance to set the password while the program is installing, it is very easy to set the password later from within the MySQL shell.



Once you have installed MySQL, we should activate it with this command:

sudo mysql_install_db

Finish up by running the MySQL set up script:

sudo /usr/bin/mysql_secure_installation

The prompt will ask you for your current root password. Type it in.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

The prompt will ask if you want to change the root password. Go ahead and choose N for this option, as the root password should aready be set; however, for the rest of the questions you can simply reply Y to all– unless there is a reason for you to do otherwise.

Now let’s install nginx!

3) Install and Configure Nginx on your VPS


Initial installation is simple with the apt-get command.

sudo apt-get install nginx

nginx needs a command to begin running:

sudo service nginx start

Now if you point your browser to your IP address, it should confirm that nginx was successfully installed on your cloud server.

*Run the following command to reveal your VPS’s IP address.

ifconfig eth0 | grep inet | awk '{ print $2 }'


Open up the default virtual host file with this command:

sudo nano /etc/nginx/sites-available/default

The configuration should include the changes below (the details of the changes are under the config information):

UPDATE: Newer Ubuntu versions create a directory called ‘html’ instead of ‘www’ by default. If /usr/share/nginx/www does not exist, it’s probably called html. Make sure you update your configuration appropriately.

server {
        listen   80;

        root /usr/share/nginx/www;
        index index.php index.html index.htm;


        location / {
                try_files $uri $uri/ /index.html;

        error_page 404 /404.html;

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

        # pass the PHP scripts to FastCGI server listening on /var/run/php5-fpm.sock
        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;


Here are the details of the changes:

  • Add index.php to the index line.
  • Change the server_name from local host to your domain name or IP address (replace the in the configuration)
  • Change the correct lines in “location ~ \.php$ {“ section

Save and Exit

4) Install and Configure PHP


You probably guessed it! We will use the apt-get command to install PHP-FPM:

sudo apt-get install php5-fpm php5-mysql


We need to make one small change in the php configuration. Open up php.ini:

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

Find the line cgi.fix_pathinfo=1 and change the 1 to 0.


If this number is kept as 1, the php interpreter will do its best to process the file that is as near to the requested file as possible. This is a possible security risk. If this number is set to 0, conversely, the interpreter will only process the exact file path— a much safer alternative.

Save and Exit.

We need to make another small change in the php5-fpm configuration. Open up www.conf:

 sudo nano /etc/php5/fpm/pool.d/www.conf

Find the line, listen =, and change the to /var/run/php5-fpm.sock.

listen = /var/run/php5-fpm.sock

Save and Exit.

Restart php-fpm:

sudo service php5-fpm restart

5) Create a Php Info Page

We can quickly see all of the details of the new php configuration.

To set this up, first create a new file:

sudo nano /usr/share/nginx/www/info.php

Add in the following line:


Then Save and Exit.

Finishing Up

Restart nginx:

sudo service nginx restart

You can see the nginx and php-fpm configuration details by visiting http://youripaddress/info.php


Nginx error 413: Request entity too large Quick Fix

Open Nginx conf

sudo nano /etc/nginx/nginx.conf

Insert this code

http {
 client_max_body_size 500M; # allows file uploads up to 500 megabytes

And also change the value in the file php.ini

sudo nano /etc/php5/fpm/php.ini
post_max_size 128M
upload_max_filesize 100M
memory_limit 256M



Configure phpMyAdmin


Step One—Install phpMyAdmin

Start off by downloading the program from apt-get.

sudo apt-get install phpmyadmin

During the installation, phpmyadmin will ask you if you want to configure the database with dbconfig. Go ahead and choose yes.

Input MySQL’s database password when prompted and click ok.

When phpmyadmin prompts you to choose a server (either apache or lighttpd) hit tab, and select neither one.

Step Two—Configure phpMyAdmin

You now have phpMyAdmin installed on your server. In order to access it, you need to take one more step.

Create a symbolic link between phpMyAdmin and your site’s directory. If you were using the previous tutorial, it may be still located in the nginx default directory, otherwise link it with the appropriate place:

sudo ln -s /usr/share/phpmyadmin/ /usr/share/nginx/www

Create virtual host file for phpmyadmin

sudo nano /etc/nginx/sites-available/phpmyadmin

The content is

 listen 80;
 server_name phpmyadmin;
 access_log /var/log/phpmyadmin.access_log;
 error_log /var/log/phpmyadmin.error_log;
 location / {
 root /usr/share/phpmyadmin;
 index index.php;
 location ~ \.php$ {
 fastcgi_index index.php;
 fastcgi_param SCRIPT_FILENAME /usr/share/phpmyadmin$fastcgi_script_name;
 include fastcgi_params;
sudo ln -s /etc/nginx/sites-available/phpmyadmin /etc/nginx/sites-enabled/phpmyadmin
sudo nano /etc/hosts

Append the ‘phpmyadmin’ into line   localhost phpmyadmin

Now restart the nginx server

sudo service nginx restart


source: digitalocean.comjoneslee85

Related Search

Tags: #debian #linux #mysql #Newer Ubuntu #nginx #Open Nginx #php-fpm #server #UPDATE #webserver #website

Install Pi-Hole DNS Blokir Iklan dan Tracker
Install Pi-Hole DNS Blokir Iklan dan Tracker
Pi-Hole merupakan salah satu pelindung user internet
Migrasi VPS Panel dari Tuxlite ke VestaCP
Migrasi VPS Panel dari Tuxlite ke VestaCP
Setelah sekian lama menggunakan Tuxlite akhirnya diputuskan
Cara Cepat Root Unlock STB ZTE B760H Tanpa Bongkar
Cara Cepat Root Unlock STB ZTE B760H Tanpa Bongkar
Mungkin beberapa ada yang pernah berlangganan Indihome
Upgrade PHP 5.6 ke PHP 7.0 Nginx Debian Jessie
Upgrade PHP 5.6 ke PHP 7.0 Nginx Debian Jessie
Sebetulnya sudah agak lama warning untuk upgrade