Skip to content

Instantly share code, notes, and snippets.

@paneru-rajan
Last active November 17, 2021 15:44
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paneru-rajan/66994f5d3bd6cad7401de949d9dd4acf to your computer and use it in GitHub Desktop.
Save paneru-rajan/66994f5d3bd6cad7401de949d9dd4acf to your computer and use it in GitHub Desktop.
[Nginx, Php, PhpMyAdmin, MariaDB, Postgres, PhpPgAdmin Installation] Installation of nginx, php, phpmyadmin, phppdadmin, mysql and postgres in ubuntu 16.04 #public #loclhost #ubuntu #php #mariadb #installation #phppgadmin #phpmyadmin #postgres #nginx

Installation and Configuration

  1. Update System

    sudo apt install update && sudo apt upgrade -y
  2. Install Nginx

    sudo apt install nginx -y
  3. Test on the browser Click Me

  4. Install Php7.0

    sudo apt install php7.0 php7.0-fpm -y
  5. Install Mariadb

    sudo apt install mariadb-server mariadb-client php7.0-mysql -y
  6. Configure php.ini which is located on /etc/php/7.0/fpm/php.ini

    sudo sed -i "s/display_errors = .*/display_errors = On/" /etc/php/7.0/fpm/php.ini
    #sudo sed -i "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/" /etc/php/7.0/fpm/php.ini
  7. Setup Nginx Configuration

    • Open File
      sudo vim /etc/nginx/sites-available/default
      
    • Replace with the folowing Code
      server {
          listen 80;
          server_name localhost;
          root /extra/localhost/php;
          index index.html index.htm index.php;
          location / {
                  try_files $uri $uri/ =404;
          }
      
          location ~ \.php$ {
                  include snippets/fastcgi-php.conf;
                  fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
          }
          location /pma {
                  root /var/www/html;
      
                  index index.php;
                  try_files $uri $uri/ =404;
      
                  location ~ ^/pma/(doc|sql|setup)/ {
                          deny all;
                  }
      
                  location ~ ^/pma/(.+\.php)$ {
                          include snippets/fastcgi-php.conf;
                          fastcgi_pass unix:/run/php/php7.0-fpm.sock;
                          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                          include fastcgi_params;
                  }
          }
          location /ppa {
                  root /var/www/html;
                  index index.php;
                  try_files $uri $uri/ =404;
      
                  location ~ ^/ppa/(doc|sql|setup)/ {
                          deny all;
                  }
      
                  location ~ ^/ppa/(.+\.php)$ {
                          include snippets/fastcgi-php.conf;
                          fastcgi_pass unix:/run/php/php7.0-fpm.sock;
                          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                          include fastcgi_params;
                  }
           }
          location ~ /\.ht {
              deny all;
          }
      
      }
      
    • Remove previous smlink and add new one
      sudo rm -f /etc/nginx/sites-enabled/default
      sudo ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/
      
  8. Add www-data to username group:

    sudo gpasswd -a www-data rajan
    
  9. Make sure that username group can enter all directories along the path:

    sudo chmod g+x /home && chmod g+x /home/rajan && chmod g+x /home/rajan/Dropbox && chmod g+x /home/rajan/Dropbox/yipl && chmod g+x /home/rajan/Dropbox/yipl/php
    
  10. Install Phpmyadmin (During Installation You are asked to enter password, and choose yes in other case)

    sudo apt-get install phpmyadmin php-mbstring php-gettext -y
    
  11. Install Postgres and dependencies

    sudo apt install postgresql postgresql-contrib -y
    
  12. Using Cli to login

    sudo -i -u postgres
    psql
    
  13. Install Prerequisites and phpPgAdmin

    sudo apt install php-pgsql phppgadmin -y
    
  14. Resolve these kind of errors:

    ERROR 1045: Access denied for user: 'root@localhost' (Using password: NO)

    or

    ERROR 1045: Access denied for user: 'root@localhost' (Using password: YES)

    sudo mysql
    use mysql
    UPDATE user SET Password=PASSWORD('root') WHERE User='root';
    UPDATE user SET plugin='' WHERE User='root';
    flush privileges;
    exit
    
  15. Setup password for user postgres

    sudo -u postgres psql postgres
    \password postgres
    \q
    
  16. Set extra_login_security = false in /etc/phppgadmin/config.inc.php

    sudo sed -i "s/$conf\['extra_login_security'\] = true;/$conf\['extra_login_security'\] = false;/" /etc/phppgadmin/config.inc.php
    
  17. Set peer to MD5 in /etc/postgresql/9.5/main/pg_hba.conf

    sudo sed -i "s/postgres                                peer/postgres                                md5/" /etc/postgresql/9.5/main/pg_hba.conf
    
  18. Simlink of PhpMyAdmin and PhpPgAdmin

sudo ln -s /usr/share/phpmyadmin /var/www/html/pma
sudo ln -s /usr/share/phppgadmin /var/www/html/ppa
  1. Restart Every thing

    sudo service nginx restart
    sudo service mysql restart
    sudo service php7.0-fpm restart
    sudo service postgresql restart
    
  2. Making Postgres accessable in network

    Change listen_addresses from localhost to * in

     sudo vim /etc/postgresql/10/main/postgresql.conf
     listen_addresses = '*'
    
    sudo vim /etc/postgresql/10/main/pg_hba.conf 
    host   all              postgres      0.0.0.0/0               md5
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment