Skip to content

Instantly share code, notes, and snippets.

@moradi-morteza
Last active February 7, 2021 15:46
Show Gist options
  • Save moradi-morteza/6516c89cb155df7a54ced6a5eeb6e6d4 to your computer and use it in GitHub Desktop.
Save moradi-morteza/6516c89cb155df7a54ced6a5eeb6e6d4 to your computer and use it in GitHub Desktop.
[Install LEMP on Ubunto]

Install LEMP

ubunto version 19 - php v 7.2

0. prepare Server

if your server repository is not in us set in in us

copy content of https://gist.github.com/mrmordi/2e2ef9507bbb75d09c419a61fa8ed981 to sources.list file.

sudo nano /etc/apt/sources.list

1. Install Nginx

  • sudo apt install nginx

  • sudo service nginx status

  • sudo systemctl enable nginx [ start nginx in startup system]

  • sudo ufw allow 'Nginx HTTP'

    after install check your ip address to see nginx home page

2. Config ufw

  • sudo ufw enable
  • sudo ufw allow OpenSSH
  • sudo ufw allow ssh
  • sudo ufw allow http
  • sudo ufw allow https
  • sudo ufw status

3. Install Mysql

  • sudo apt install mysql-server

  • sudo mysql_secure_installation

    first mysql do not have any pass and user we should ceate one :

    • sudo mysql

    • SELECT user,authentication_string,plugin,host FROM mysql.user;

    • ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'sale2012'; ``

    • FLUSH PRIVILEGES;

    • SELECT user,authentication_string,plugin,host FROM mysql.user;

    • exit

    • now for access to mysql we should run : mysql -u root -p

4.Installing PHP and Configuring Nginx to Use the PHP Processor

  • sudo apt install php-fpm php-mysql

  • sudo apt-get install php7.2-curl php7.2-gd php7.2-json php7.2-mbstring php7.2-intl php7.2-mysql php7.2-xml php7.2-zip
  • sudo systemctl restart php7.2-fpm

  • php -v

  • sudo nginx -t

  • sudo systemctl reload nginx

5. Install PhpMyAdmin

  • sudo apt install phpmyadmin php-mbstring php-gettext

  • sudo ln -s /usr/share/phpmyadmin /var/www/html

  • for more secure phpMyadmin you can change name :

    sudo mv phpmyadmin securephpmyadmin

Create Another Folder Root with Port

open your port with command : sudo ufw allow 8010 - sudo ufw allow 8010

  • create a file on /etc/nginx/sites-available with your selected name and copy content of default file to it.

    then just change some part :

    listen 8010; listen [::]:8010; root /var/www/html/nfc;

  • ​ sudo ln -s /etc/nginx/sites-available/nfc /etc/nginx/sites-enabled/

Install Composer

  • sudo apt install curl php-cli php-mbstring git unzip

  • go to home directory with command **cd ~**

    curl -sS https://getcomposer.org/installer -o composer-setup.php
  • Next, verify that the installer matches the SHA-384 hash for the latest installer found on the Composer Public Keys / Signatures page. Copy the hash from that page and store it as a shell variable:

  • HASH=756890a4488ce9024fc62c56153228907f1545c228516cbf63f885e036d37e9a59d27d63f46af1d4d07ee0f76181c7d
  • php -r "if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
  • You’ll see the following output: Installer verified

  • sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer

  • composer

Install Node

  • sudo apt install nodejs
  • sudo apt install npm
  • nodejs -v

Nginx Configuration

  • to avoid 413 Request Entity Too Large file upload as base64

    The client_max_body_size directive assigns the maximum accepted body size of client request, indicated by the line Content-Length in the header of request. If size is greater the given one, then the client gets the error “Request Entity Too Large” (413).

    • nano /etc/nginx/nginx.conf

    • # set client body size to 20M #
      client_max_body_size 20M;
  • sudo systemctl reload nginx.service

Change php.ini

  • nano /etc/php/7.2/fpm/php.ini

  • change below variables

    • max_execution_time
    • memory_limit
    • upload_max_filesize
    • post_max_size
  • sudo service apache2 restart

  • sudo systemctl restart php7.2-fpm
    

Laravel On Ubuntu

  • change location part in /etc/nginx/sites-available/nfc

    location / {try_files $uri $uri/ /index.php?$query_string; }

  • sudo chmod -R 777 public [public folder - where you upload your files]
    sudo chown -R www-data.www-data storage
    sudo chown -R $USER:www-data storage bootstrap/cache
    sudo chmod -R 775 storage bootstrap/cache

Fix PhpMyAdmin Error

Import/Export issues If you are also getting an error Warning in ./libraries/plugin_interface.lib.php#551 under import and export tabs:

Backup plugin_interface.lib.php

sudo cp /usr/share/phpmyadmin/libraries/plugin_interface.lib.php /usr/share/phpmyadmin/libraries/plugin_interface.lib.php.bak

Edit plugin_interface.lib.php

sudo nano /usr/share/phpmyadmin/libraries/plugin_interface.lib.php

Press CTRL + W and search for

if (! is_null($options) && count($options) > 0) {

If not found, try search for

if ($options != null && count($options) > 0)

Replace with

if (! is_null($options) && count((array)$options) > 0) {

Save file and exit. (Press CTRL + X, press Y and then press ENTER)

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