July 19, 2018 · Server Ubuntu

Native Ubuntu 18 LEMP + mongoDB Setup

install php lib

apt-get update
apt-get purge apache2
apt-get install -y nginx
apt-get install -y mysql-server mysql-client
sudo mysql_secure_installation
apt-get install -y vim curl unzip zip git tree tar tmux tig wget
apt-get install -y php php-fpm php-mysql php-pear php-cli php-curl php-gd php-mbstring php7.2-dev
sudo apt-get -y install gcc make autoconf libc-dev pkg-config
sudo apt-get -y install libmcrypt-dev
sudo pecl install mcrypt-1.0.1
sudo bash -c "echo extension=/usr/lib/php/20170718/mcrypt.so > /etc/php/7.2/cli/conf.d/mcrypt.ini"
sudo bash -c "echo extension=/usr/lib/php/20170718/mcrypt.so > /etc/php/7.2/apache2/conf.d/mcrypt.ini"
php -i | grep "mcrypt"
#Add the extention extension=mcrypt.so to your php.ini configuration file; if you don't know where it is, search with:
#$ sudo php -i | grep 'Configuration File'
apt-get install -y libmagickwand-dev imagemagick php-dev
apt-get install -y php-imagick
.bashrc languages settings

setup .bashrc

export LANG="en_US.utf8"
export LANGUAGE="en_US.utf8"
export LC_ALL="en_US.utf8"
source ~/.bashrc
Setup php server

/etc/php/7.2/fpm/php.ini

#modify the following
cgi.fix_pathinfo=0
upload 2M => 128M
post 8M => 128M
input 30s => 300s
60s => 600s

/etc/php/7.2/fpm/pool.d/www.conf

#modify the following
pm.max_children = 20
pm.start_servers = 8
pm.min_spare_servers = 4
pm.max_spare_servers = 20
service php7.2-fpm restart
configuring logs directory
mkdir /var/www/logs
chmod 775 /var/www/logs
chown www-data:www-data /var/www/logs
configuring phpmyadmin
apt-get update
apt-get install phpmyadmin
ln -s /usr/share/phpmyadmin /var/www/phpmyadmin

adduser www-pub
usermod -aG www-data www-pub
cd /var/www/

chown -R www-pub:www-pub .
find -type d -exec chmod 755 {} \;
find -type d -exec chmod ug+s {} \;
find -type f -exec chmod 644 {} \;
configuring nginx server for phpmyadmin

phpmymadin.example.com example config

/etc/nginx/sites-available/phpmyadmin

server {
listen 80;
server_name phpmyadmin.example.com;
 
root /var/www/phpmyadmin.example.com;
if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})") {
    set $year $1;
    set $month $2;
    set $day $3;
}
access_log /var/www/logs/phpmyadmin.example.com.$year-$month-$day.access.log;
error_log /var/www/logs/phpmyadmin.example.com.error.log;
allow all;
 
index index.php index.html index.htm;
client_max_body_size 512M;
 
location ~ \.php$ {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
include snippets/fastcgi-php.conf;
fastcgi_read_timeout 300;
}
 
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
 
location ~ /\.ht {
deny all;
}
}
# phpmymadin.example.com example config
ln -s /etc/nginx/sites-available/phpmyadmin.example.com /etc/nginx/sites-enabled/phpmyadmin.example.com
 
#end of nginx server script
 
Remove direct ip access and default nginx config
unlink /etc/nginx/sites-enabled/default

/etc/nginx/sites-available/direct-ip-access

#paste the following
server {
listen 80;
listen 8080;
server_name _;
return 404;
}

# or redirect
server {
listen 80;
listen 8080;
server_name IP_ADRESS;
return 301 http://YOUR.DOMAIN;
}
ln -s /etc/nginx/sites-available/direct-ip-access /etc/nginx/sites-enabled/direct-ip-access
mysql root setup
#mysql new root user setup
mysql --user=root mysql
set global validate_password_policy=0;
set global validate_password_length=0;
CREATE USER 'dev'@'localhost' IDENTIFIED BY 'devA123';
GRANT ALL PRIVILEGES ON *.* TO 'dev'@'localhost' WITH GRANT OPTION;
install the composer
# follow https://getcomposer.org/download/
sudo  mv composer.phar /usr/local/bin/composer

MEAN Server Setup
sudo apt-get install mongodb
mongo

use admin;
db.createUser( { user: "root", pwd: "root_password", roles: [ { role: "dbAdminAnyDatabase", db: "admin" } ] } );
mongo -u root -p --authenticationDatabase admin

use new_db;
db.createUser( { user: "wiki", pwd: "wiki_password", roles: [ { role: "dbOwner", db: "new_db" } ] } );

sudo vim /etc/mongodb.conf
comment #bind_ip
#add following#######
security:
  authorization: 'enabled'
#######################
Install npm and set the node js to 8
#curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
nvm install 8