Search This Blog

Showing posts with label MariaDB. Show all posts
Showing posts with label MariaDB. Show all posts

Saturday, March 23, 2019

CREATE A LEMP STACK IN AWS EC2 by Amazon Linux 2 (LINUX, NGINX, MARIADB AND PHP 7.2)

Launch Instance: latest Amazon Linux 2 AMI



# Update Linux and install essential packages
sudo yum -y update

# Install php72 using amazon-linux-extras
sudo amazon-linux-extras install php7.2

# Install Nginx 1.12 using amazon-linux-extras
sudo amazon-linux-extras install nginx1.12

# Install mariadb using amazon-linux-extras
sudo amazon-linux-extras install lamp-mariadb10.2-php7.2
## this will install apache/httpd as well, which we don't need.
### uninstall httpd
sudo yum earse httpd httpd-tools
# install mariadb-server should be version 10.2 or higher
sudo yum install mariadb-server
To enable nginx, php-fpm and mardb services on boot:
sudo systemctl enable nginx
sudo systemctl enable php-fpm
sudo systemctl enable mariadb
To start all 3 service:
sudo systemctl start php-fpm
sudo systemctl start nginx
sudo systemctl start mariadb
sudo mysql_secure_installation

Friday, November 14, 2014

Magento on HHVM 3.3 Nginx 1.6 on Ubuntu 14.04 trusty

No more Varnish! Love HHVM!

1.First this VPS box running Ubuntu 14.04 trusty 64 bit with 2 GB Memory and 2 Core CPU.
Please follow HHVM, Nginx and MariaDB 's offical installation guide to install:





After installation I have these files under /etc/apt/sources.list.d/:
nginx.list
deb http://nginx.org/packages/ubuntu/ trusty nginx


mariadb.list
deb http://mariadb.mirror.iweb.com//repo/10.0/ubuntu trusty main


hhvm.list
deb http://dl.hhvm.com/ubuntu trusty main


At this moment I have the version:

root@mds-magento:/var/www/magento/includes# dpkg -l|grep hhvm
ii hhvm 3.3.0~trusty amd64 HHVM virtual machine, runtime, and JIT for the PHP language
root@mds-magento:/var/www/magento/includes# dpkg -l|grep nginx
ii nginx 1.6.2-1~trusty amd64 high performance web server
root@mds-magento:/etc/apt/sources.list.d# dpkg -l|grep mariadb
ii libmariadbclient18 10.0.14+maria-1~trusty amd64 MariaDB database client library
ii mariadb-client-10.0 10.0.14+maria-1~trusty amd64 MariaDB database client binaries
ii mariadb-client-core-10.0 10.0.14+maria-1~trusty amd64 MariaDB database core client binaries
ii mariadb-common 10.0.14+maria-1~trusty all MariaDB database common files (e.g. /etc/mysql/conf.d/mariadb.cnf)
ii mariadb-server 10.0.14+maria-1~trusty all MariaDB database server (metapackage depending on the latest version)
ii mariadb-server-10.0 10.0.14+maria-1~trusty amd64 MariaDB database server binaries
ii mariadb-server-core-10.0 10.0.14+maria-1~trusty amd64 MariaDB database core server files


2.Share my Nginx config file:
/etc/nginx/nginx.conf


user www-data;
worker_processes 2;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;


events {
worker_connections 1024;
}


http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
autoindex off;
#tcp_nopush on;

map $scheme $fastcgi_https { ## Detect when HTTPS is used
default off;
https on;
}

keepalive_timeout 10;

gzip on;
gzip_comp_level 2;
gzip_proxied any;
gzip_types text/plain text/css application/x-javascript application/xml application/xml+rss text/javascript;

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}


/etc/nginx/hhvm.conf

location ~ .(hh|php)$ {
fastcgi_keep_conn on;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}


/etc/nginx/fastcgi_params


fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;

fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param HTTPS $https if_not_empty;

fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;

fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;


/etc/nginx/sites-enabled/magento

server {
listen 80;
server_name localhost;
rewrite / $scheme://www.$host$request_uri permanent; ## Forcibly prepend a www
}

server {
listen 80 default;

#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;

root /var/www/magento;

location / {
index index index.html index.htm index.php;
try_files $uri $uri/ @handler;
}

## These locations would be hidden by .htaccess normally
location ^~ /app/ { deny all; }
location ^~ /includes/ { deny all; }
location ^~ /lib/ { deny all; }
location ^~ /media/downloadable/ { deny all; }
location ^~ /pkginfo/ { deny all; }
location ^~ /report/config.xml { deny all; }
location ^~ /var/ { deny all; }

location /. { ## Disable .htaccess and other hidden files
return 404;
}

location @handler { ## Magento uses a common front handler
rewrite / /index.php;
}

location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler
rewrite ^(.*.php)/ $1 last;
}

location ~ .php$ { ## Execute PHP scripts
if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss

expires off; ## Do not cache dynamic content
fastcgi_keep_conn on;
fastcgi_pass unix:/var/run/hhvm/hhvm.sock;
fastcgi_index index.php;
fastcgi_param HTTPS $fastcgi_https;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param MAGE_RUN_CODE default; ## Store code is defined in administration > Configuration > Manage Stores
fastcgi_param MAGE_RUN_TYPE store;
include fastcgi_params; ## See /etc/nginx/fastcgi_params
}
}


3.My HHVM config file:

/etc/hhvm/server.ini

; php options

pid = /var/run/hhvm/pid

; hhvm specific

;hhvm.server.port = 9000
hhvm.server.file_socket = /var/run/hhvm/hhvm.sock
hhvm.server.type = fastcgi
hhvm.server.default_document = index.php
hhvm.log.use_log_file = true
hhvm.log.file = /var/log/hhvm/error.log
hhvm.repo.central.path = /var/run/hhvm/hhvm.hhbc


/etc/hhvm/php.ini

; php options

; hhvm specific
hhvm.log.level = Warning
hhvm.log.always_log_unhandled_exceptions = true
hhvm.log.runtime_error_reporting_level = 8191
hhvm.mysql.typed_results = false


Thank you for the kind sharing from:

http://bryanapperson.com/blog/intro-hhvm-mariadb-nginx-wordpress/
http://bryanapperson.com/blog/install-hhvm-nginx-ubuntu-14-04-make-wordpress-fly/
http://wiki.nginx.org/Install#Official_Debian.2FUbuntu_packages
https://udinra.com/blog/hhvm-fastcgi-nginx-speedup-php
http://stackoverflow.com/questions/23872439/nginx-rewrite-with-laravel-and-hhvm

Monday, June 23, 2014

Nginx 1.6 stable fail php-fpm on Debian Wheezy

I am big fan of Debian.
It just easy to setup a nice clean server get the job done.

For more effective web server, I try to use Nginx + PHP5-FPM to serve Wordpress and Mediawiki.

I bring up a new Debian Wheezy 7.5 64-bit server today.

1.First upgrade all new patch:
aptitude update && aptitude upgrade

2.Install Nginx Stable follow Nginx's offical Pre-Built Packages:
http://nginx.org/en/linux_packages.html#stable
wget http://nginx.org/keys/nginx_signing.key
apt-key add nginx_signing.key
aptitude update
aptitude install nginx

3.Install Latest MariaDB Pre-Built Packages:
aptitude install python-software-properties
apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db
add-apt-repository 'deb http://ftp.osuosl.org/pub/mariadb/repo/10.0/debian wheezy main'
aptitude install mariadb-server

4.Install PHP5-FPM:
aptitude install php5-fpm

5.Modify Nginx vhost location in /etc/nginx/nginx.conf:
include /etc/nginx/sites-enabled/*.conf;

6.Put my vhost file at /etc/nginx/sites-available/mds.conf:
server {
listen 80;
server_name localhost;

access_log /var/log/nginx/log/mds.access.log main;
error_log /var/log/nginx/log/mds.error.log error;

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

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

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/mds;
}

# With php5-fpm / php5-cgi will be different:
location ~ .php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}

Make a link:
ln -s /etc/nginx/sites-available/mds.conf /etc/nginx/sites-enable/

Restart Nginx:
service nginx restart

Then I put a index.php with phpinfo() into the /var/www/mds folder.
But the browser shows blank page.
I try follow different post, able to bring errors logs: php5-fpm.sock failed (13: Permission denied) error

But still not able to quickly fix it.

Spend almost half hour on it, finally found:

Missing this line in /etc/nginx/fastcgi_params:
fastcgi_param   SCRIPT_FILENAME         $request_filename;

I should just stay with Debian Nginx 1.2, what a wast!
Nginx's RPM package works just fine.

Hope this helps.

Update 1 on June 24, 2014:

It seems more problem are coming, I really miss stock debian package.

Php page show error, but nothing in error log file.

I have to run this to bring the php page up:
chmod 666 /var/run/php5-fpm.sock

Thanks the post: http://www.nginxtips.com/php5-fpm-sock-failed-13-permission-denied-error/

I modified file: /etc/php5/fpm/pool.d/www.conf
;listen.owner = www-data
;listen.group = www-data
;listen.mode = 0660
listen.owner = nginx
listen.group = nginx

service php5-fpm restart

Update 2: Additional installation to make it works better
aptitude install php-apc
aptitude install php5-mysqlnd
mysql_secure_installation


Update 2 on November 14, 2014:

Another solution for .sock permission issue will be:

/etc/nginx/nginx.conf
#user nginx;
user www-data;


This because php5-fpm package set /var/www owner to www-data.
It will be much cleaner just set nginx run as www-data, therefor we borrow the Debian setting over.

[poll id="2"]