Skip to content

Instantly share code, notes, and snippets.

@mariolopjr
Forked from isc30/install.bash
Last active January 15, 2018 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mariolopjr/78e04e086ce7e224ef655b466962aeb5 to your computer and use it in GitHub Desktop.
Save mariolopjr/78e04e086ce7e224ef655b466962aeb5 to your computer and use it in GitHub Desktop.
Raspberry Pi Install PHP7.0 + Nginx + MySQL + PhpMyAdmin
#!/bin/bash
# Thanks to https://gist.github.com/Lewiscowles1986/ce14296e3f5222082dbaa088ca1954f7
if [ "$(whoami)" != "root" ]; then
echo "Run script as ROOT please. (sudo !!)"
exit
fi
echo -e 'LANGUAGE=en_US.UTF-8\nLANG=en_US.UTF-8\nLC_ALL=en_US.UTF-8' > /etc/default/locale
sed -i -e "s/# en_US.*/en_US.UTF-8 UTF-8/" /etc/locale.gen
dpkg-reconfigure --frontend=noninteractive locales
apt-get purge -y fonts-opensymbol libreoffice libreoffice-\* openoffice.org-dtd-officedocument1.0 python\*-uno uno-libs3-\* ure ure-dbg
apt-get purge -y wolfram-engine sonic-pi scratch minecraft-pi
apt-get autoremove -y
apt-get update -y
apt-get upgrade -y
apt-get dist-upgrade -y
apt-get install -y apt-transport-https lsb-release ca-certificates rpi-update
wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
apt-get update -y
apt-get install -y php7.0 php7.0-fpm php7.0-cli php7.0-opcache php7.0-mbstring php7.0-curl php7.0-xml php7.0-gd php7.0-mysql nginx
update-rc.d nginx defaults
update-rc.d php7.0-fpm defaults
sed -i 's/^;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/' /etc/php/7.0/fpm/php.ini
sed -i 's/# server_names_hash_bucket_size/server_names_hash_bucket_size/' /etc/nginx/nginx.conf
cat > /etc/nginx/sites-enabled/default << "EOF"
# Default server
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /var/www/default/public;
index index.php index.html index.htm default.html;
location / {
try_files $uri $uri/ =404;
}
# pass the PHP scripts to FastCGI server
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
# optimize static file serving
location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
access_log off;
log_not_found off;
expires 30d;
}
# deny access to .htaccess files, should an Apache document root conflict with nginx
location ~ /\.ht {
deny all;
}
}
EOF
mkdir -p /var/www/default/public
cat > /var/www/default/public/index.php << "EOF"
<?php
class Application
{
public function __construct()
{
phpinfo();
}
}
$application = new Application();
EOF
mkdir -p /var/www/zonaisc.com/public
cat > /var/www/zonaisc.com/public/index.php << "EOF"
<?php
class Application
{
public function __construct()
{
echo 'Hi ZonaIsc.com';
}
}
$application = new Application();
EOF
rm -rf /var/www/html
usermod -a -G www-data pi
chown -R pi:www-data /var/www
chgrp -R www-data /var/www
chmod -R g+rw /var/www
setfacl -d -R -m g::rw /var/www
apt-get -y autoremove
service nginx restart
service php7.0-fpm restart
# MySQL
apt-get -t stretch -y install mysql-server
read -s -p "Type the password you just entered (MySQL): " mysqlPass
mysql --user="root" --password="$mysqlPass" --database="mysql" --execute="GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '$mysqlPass'; FLUSH PRIVILEGES;"
sed -i 's/^bind-address/#bind-address/' /etc/mysql/mysql.conf.d/mysqld.cnf
sed -i 's/^skip-networking/#skip-networking/' /etc/mysql/mysql.conf.d/mysqld.cnf
service mysql restart
# PhpMyAdmin
read -p "Do you want to install PhpMyAdmin? <y/N> " prompt
if [ "$prompt" = "y" ]; then
apt-get install -t stretch -y phpmyadmin
ln -s /usr/share/phpmyadmin /var/www/default/public
echo "http://192.168.XXX.XXX/phpmyadmin to enter PhpMyAdmin"
fi
apt-get -y autoremove
apt-get -y clean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment