Last active
December 11, 2015 10:00
-
-
Save KaidenP/0627ca95b61ccf317024 to your computer and use it in GitHub Desktop.
This is a auto installer that installs the packages needed for a LEMH (Linux (E)nginx MariaDB (PHP) HHVM) install
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
######################################################################## | |
# # | |
# Kaiden's LEMH Installer # | |
# # | |
# This is a auto installer that installs the packages needed for # | |
# a LEMH (Linux (E)nginx MariaDB (PHP) HHVM) install. # | |
# # | |
# Credit to: http://www.maketecheasier.com/setup-lemh-stack-in-ubuntu/ # | |
# # | |
######################################################################## | |
# Add Ubuntu Archive Keys (My Server Doesn't have them by default) | |
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32 | |
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 40976EAF437D05B5 | |
# Remove pre-existing packages and reseduil files | |
apt-get purge apache2* bind9* nginx* php* mysql* -y | |
apt-get purge -y mariadb* | |
apt-get autoremove -y --purge | |
apt-get autoclean -y | |
apt-get clean -y | |
rm -rf /var/lib/mysql | |
# Update | |
apt-get update | |
apt-get -y upgrade | |
apt-get -y dist-upgrade | |
# Install common packages (OK to skip this) | |
apt-get install mosh screen p7zip p7zip-full p7zip-rar unrar-nonfree \ | |
aptitude elinks axel -y | |
# Install Needed Package(s) | |
apt-get install software-properties-common -y | |
# Add Repo's | |
add-apt-repository ppa:nginx/stable | |
apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db | |
add-apt-repository 'deb http://sfo1.mirrors.digitalocean.com/mariadb/repo/10.0/ubuntu trusty main' | |
wget -O - http://dl.hhvm.com/conf/hhvm.gpg.key | apt-key add - | |
echo deb http://dl.hhvm.com/ubuntu trusty main | tee /etc/apt/sources.list.d/hhvm.list | |
# Start installing packages | |
# Update Lists | |
apt-get update | |
# Install nginx | |
apt-get install nginx -y | |
service nginx start | |
# Install MariaDB | |
apt-get install mariadb-server -y | |
# Install PHP | |
apt-get install php5-fpm php5-mysql php5-curl -y | |
# Install HHVM | |
apt-get install hhvm -y | |
/usr/share/hhvm/install_fastcgi.sh | |
service hhvm restart | |
# Set PHPinfo | |
cat /var/www/html/phpinfo.php <<EOF | |
<?php phpinfo(); ?> | |
EOF | |
# What's Left? | |
cat << EOF | |
Now that you have everything set up, it is time to create a virtual host to run your website. | |
Create a new config file that holds your website detail: | |
sudo nano /etc/nginx/sites-available/my-site | |
and paste in the following snippet: | |
server { | |
listen 80; | |
listen [::]:80; | |
root /var/www/html; | |
# Add index.php to the list if you are using PHP | |
index index.html index.htm; | |
server_name mywebsite.com; | |
include hhvm-with-fallback.conf; | |
location / { | |
# First attempt to serve request as file, then | |
# as directory, then fall back to displaying a 404. | |
try_files $uri $uri/ =404; | |
} | |
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 | |
# | |
location @fallback { | |
# include snippets/fastcgi-php.conf; | |
# | |
# # With php5-fpm: | |
fastcgi_pass unix:/var/run/php5-fpm.sock; | |
fastcgi_index index.php; | |
include fastcgi_params; | |
} | |
# deny access to .htaccess files, if Apache's document root | |
# concurs with nginx's one | |
# | |
location ~ /\.ht { | |
deny all; | |
} | |
} | |
You can change the server_name to point to your own domain and the root folder location where you want the files to be served. | |
HHVM has this bug of crashing occasionally without restarting itself; this will cause the website to fail with a 500 error. In this case, we will create a fallback system whereby PHP5-FPM will take over when HHVM fails. Notice the location @fallback block in the config snippet above? That is the callback when HHVM fails. To complete the equation, we still need to create the “hhvm-with-fallback.conf” file which is a modified version of the “hhvm.conf” file. | |
sudo nano /etc/nginx/hhvm-with-fallback.conf | |
Paste the following snippet: | |
location ~ \.(hh|php)$ { | |
proxy_intercept_errors on; | |
error_page 500 501 502 503 = @fallback; | |
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; | |
} | |
Save and exit the file. | |
Lastly, test Nginx settings with | |
sudo nginx -t | |
and if everything is fine, restart Nginx. | |
sudo service nginx restart | |
After that, you have completed the LEMH stack setup on your Linux server. | |
EOF | |
# DONE! | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment