找回密码
 立即加入
搜索
查看: 6818|回复: 0

树莓派搭建web服务器环境

[复制链接]

43

主题

47

回帖

849

积分

管理员

积分
849
发表于 2017-9-9 19:22 | 显示全部楼层 |阅读模式 |回复 |
可以在debian上安装nginx,php,mysql进行web环境搭建

可以参看:https://gist.github.com/isc30/aa80d81df44de8a91dc0a82d55806381

系统为debian 9(debian stretch),代码如下:

  1. #!/bin/bash
  2. # Thanks to https://gist.github.com/Lewiscowles1986/ce14296e3f5222082dbaa088ca1954f7

  3. if [ "$(whoami)" != "root" ]; then
  4.         echo "Run script as ROOT please. (sudo !!)"
  5.         exit
  6. fi

  7. echo "deb http://mirrordirector.raspbian.org/raspbian/ stretch main contrib non-free rpi" > /etc/apt/sources.list.d/stretch.list
  8. echo "APT::Default-Release "jessie";" > /etc/apt/apt.conf.d/99-default-release

  9. apt-get update -y
  10. apt-get upgrade -y
  11. apt-get dist-upgrade -y

  12. apt-get install -y rpi-update

  13. apt-get install -t stretch -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
  14. apt-get install -t stretch -y nginx

  15. update-rc.d nginx defaults
  16. update-rc.d php7.0-fpm defaults

  17. sed -i 's/^;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/' /etc/php/7.0/fpm/php.ini
  18. sed -i 's/# server_names_hash_bucket_size/server_names_hash_bucket_size/' /etc/nginx/nginx.conf

  19. cat > /etc/nginx/sites-enabled/default << "EOF"
  20. # Default server
  21. server {
  22.         listen 80 default_server;
  23.         listen [::]:80 default_server;
  24.        
  25.         server_name _;
  26.         root /var/www/default/public;
  27.         index index.php index.html index.htm default.html;

  28.         location / {
  29.                 try_files $uri $uri/ =404;
  30.         }

  31.         # pass the PHP scripts to FastCGI server
  32.         location ~ \.php$ {
  33.                 include snippets/fastcgi-php.conf;
  34.                 fastcgi_pass unix:/run/php/php7.0-fpm.sock;
  35.         }

  36.         # optimize static file serving
  37.         location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
  38.                 access_log off;
  39.                 log_not_found off;
  40.                 expires 30d;
  41.         }

  42.         # deny access to .htaccess files, should an Apache document root conflict with nginx
  43.         location ~ /\.ht {
  44.                 deny all;
  45.         }
  46. }

  47. # Zonaisc.com server configuration
  48. server {
  49.         listen 80;
  50.         listen [::]:80;
  51.        
  52.         server_name zonaisc.com www.zonaisc.com;
  53.         root /var/www/zonaisc.com/public;
  54.         index index.php index.html index.htm default.html;

  55.         location / {
  56.                 try_files $uri $uri/ =404;
  57.         }

  58.         # pass the PHP scripts to FastCGI server
  59.         location ~ \.php$ {
  60.                 include snippets/fastcgi-php.conf;
  61.                 fastcgi_pass unix:/run/php/php7.0-fpm.sock;
  62.         }
  63.        
  64.         # optimize static file serving
  65.         location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
  66.                 access_log off;
  67.                 log_not_found off;
  68.                 expires 30d;
  69.         }

  70.         # deny access to .htaccess files, should an Apache document root conflict with nginx
  71.         location ~ /\.ht {
  72.                 deny all;
  73.         }
  74. }
  75. EOF

  76. mkdir -p /var/www/default/public
  77. cat > /var/www/default/public/index.php << "EOF"
  78. <?php

  79. class Application
  80. {
  81.         public function __construct()
  82.         {
  83.                 phpinfo();
  84.         }
  85. }

  86. $application = new Application();
  87. EOF

  88. rm -rf /var/www/html

  89. usermod -a -G www-data pi
  90. chown -R pi:www-data /var/www
  91. chgrp -R www-data /var/www
  92. chmod -R g+rw /var/www

  93. setfacl -d -R -m g::rw /var/www

  94. apt-get -y autoremove

  95. service nginx restart
  96. service php7.0-fpm restart

  97. # MySQL
  98. apt-get -t stretch -y install mysql-server

  99. read -s -p "Type the password you just entered (MySQL): " mysqlPass

  100. mysql --user="root" --password="$mysqlPass" --database="mysql" --execute="GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '$mysqlPass'; FLUSH PRIVILEGES;"

  101. sed -i 's/^bind-address/#bind-address/' /etc/mysql/mysql.conf.d/mysqld.cnf
  102. sed -i 's/^skip-networking/#skip-networking/' /etc/mysql/mysql.conf.d/mysqld.cnf

  103. service mysql restart

  104. # PhpMyAdmin
  105. read -p "Do you want to install PhpMyAdmin? <y/N> " prompt
  106. if [ "$prompt" = "y" ]; then
  107.         apt-get install -t stretch -y phpmyadmin
  108.         ln -s /usr/share/phpmyadmin /var/www/default/public
  109.         echo "http://192.168.XXX.XXX/phpmyadmin to enter PhpMyAdmin"
  110. fi

  111. apt-get -y autoremove
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即加入

本版积分规则

Archiver|手机版|小黑屋|玉玲珑

GMT+8, 2024-11-21 17:11 , Processed in 0.017007 second(s), 21 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表