{"id":52,"date":"2020-12-15T09:12:30","date_gmt":"2020-12-15T01:12:30","guid":{"rendered":"http:\/\/www.anger.ltd\/?p=52"},"modified":"2021-03-29T14:20:40","modified_gmt":"2021-03-29T06:20:40","slug":"one-key-install-php-7-x-and-nginx","status":"publish","type":"post","link":"https:\/\/www.anger.ltd\/index.php\/2020\/12\/15\/one-key-install-php-7-x-and-nginx\/","title":{"rendered":"One Key Install PHP 7.x And Nginx"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n\n\n\n# message\nfunction message()\n{\n    if &#91;&#91; $1 == \"error\" ]]\n    then\n        echo -e \"\\e&#91;1;37;1;41m $2 \\e&#91;0m\" \n    elif &#91;&#91; $1 == \"normal\" ]]\n    then\n        echo -e \"\\e&#91;30;1;1;42m $2 \\e&#91;0m\" \n    fi\n}\n\n# help \nfunction showhelp()\n{\n    echo '''\n##################################################\n#  auth:anger                                    #\n#  mail:yxmingh@hotmaiil.com                     #\n##################################################\n#  description:                                  #\n#                                                #\n#       php auto install script                  #\n#       for centos 7.x                           #\n#                                                #\n##################################################\n#  example:                                      #\n#                                                #\n#       $0 &lt;php version&gt;                         #\n#                                                #\n#                                                #\n##################################################\n#  options:                                      #\n#                                                #\n#       70 | 71 | 72 | 73 | 74                   #\n#                                                #\n##################################################\n#  version:0.1                                   #\n##################################################\n#  take care! script must be tested before used  #\n#  TAKE CARE! SCRIPT MUST BE TESTED BEFROE USED  #\n##################################################\n    '''\n    exit 0\n}\n\n# check user\nmessage \"normal\" \"check user.\"\nif &#91;&#91; $UID != 0 ]]\nthen\n    message \"error\" \"must as user root.\"\n    exit 0\nfi\n\n# check arg len\nmessage \"normal\" \"check arg.\"\nif &#91;&#91;  $# != 1 ]]\nthen\n    showhelp\n    exit 0\nfi\n\n################################################################################## basic depand packages\nmessage \"normal\" \"install depaned soft packages\"\nyum makecache\nyum install -y epel-release\nyum install -y install yum-utils\nyum install -y gcc make autoconf glibc glibc-devel pkgconfig zlib-devel\n\n################################################################################## nginx install \nmessage \"normal\" \"install nginx\"\ncat &gt; \/etc\/yum.repos.d\/nginx.repo &lt;&lt;EOF\n&#91;nginx-stable]\nname=nginx stable repo\nbaseurl=http:\/\/nginx.org\/packages\/centos\/\\$releasever\/\\$basearch\/\ngpgcheck=1\nenabled=1\ngpgkey=https:\/\/nginx.org\/keys\/nginx_signing.key\n\n&#91;nginx-mainline]\nname=nginx mainline repo\nbaseurl=http:\/\/nginx.org\/packages\/mainline\/centos\/\\$releasever\/\\$basearch\/\ngpgcheck=1\nenabled=0\ngpgkey=https:\/\/nginx.org\/keys\/nginx_signing.key\nEOF\n\nyum-config-manager --enable nginx-mainline\nyum -y install nginx\nsystemctl start nginx\nsystemctl enable nginx\n\n################################################################################## php install \n# get php version\nPHP_VERSION_USER_INPUT=$1\nPHP_VERSION_available=(\"70\" \"71\" \"72\" \"73\" \"74\")\nif &#91;&#91; $PHP_VERSION_USER_INPUT == ${PHP_VERSION_available&#91;0]} ]] \nthen \n    PHP_VERSION=\"php70-php\"\nelif &#91;&#91; \"$PHP_VERSION_USER_INPUT\" == ${PHP_VERSION_available&#91;1]} ]] \nthen \n    PHP_VERSION=\"php71-php\"\nelif &#91;&#91; \"$PHP_VERSION_USER_INPUT\" == ${PHP_VERSION_available&#91;2]} ]] \nthen \n    PHP_VERSION=\"php72-php\"\nelif &#91;&#91; \"$PHP_VERSION_USER_INPUT\" == ${PHP_VERSION_available&#91;3]} ]] \nthen \n    PHP_VERSION=\"php73-php\"\nelif &#91;&#91; \"$PHP_VERSION_USER_INPUT\" == ${PHP_VERSION_available&#91;4]} ]] \nthen \n    PHP_VERSION=\"php74-php\"\nelse\n    showhelp\nfi\n\n# install remi\nmessage \"normal\" \"install remi\"\nyum install -y https:\/\/mirrors.tuna.tsinghua.edu.cn\/remi\/enterprise\/remi-release-7.rpm\n\n# install php packages\nmessage \"normal\" \"install php\"\nyum install -y $PHP_VERSION $PHP_VERSION-common $PHP_VERSION-json $PHP_VERSION-devel \\\n               $PHP_VERSION-fpm $PHP_VERSION-cli $PHP_VERSION-bcmath $PHP_VERSION-bz2 \\\n               $PHP_VERSION-curl $PHP_VERSION-pear $PHP_VERSION-gd \\\n               $PHP_VERSION-mbstring $PHP_VERSION-mysql $PHP_VERSION-opcache $PHP_VERSION-sqlite3 \\\n               $PHP_VERSION-xml $PHP_VERSION-zip $PHP_VERSION-pecl-memcache $PHP_VERSION-pecl-redis5 \n\n################################################################################## configure files\n\n# create web folder\nmessage \"normal\" \"create project folder\"\n\nwwwroot=\"\/opt\/www\/wwwroot\"\nnginxconfig=\"\/opt\/www\/config\"\nnginxlog=\"\/opt\/www\/nginx_log\"\n\nmkdir -p $wwwroot\nmkdir -p $nginxconfig\nmkdir -p $nginxlog\n\nchown -R nginx.root $wwwroot\nchown -R nginx.root $nginxlog\n\n# copy nginx config file\nmessage \"normal\" \"copy config file\"\ncp -f fastcgi.conf $nginxconfig\ncp -f pathinfo.conf $nginxconfig\ncp -f rewrite.conf $nginxconfig\ncp -f nginx.conf \/etc\/nginx\/\ncp -f default.conf \/etc\/nginx\/conf.d\/\n\n## reconfig nginx\nmessage \"normal\" \"reconfig nginx\"\nCPU_COUNT=`nproc`\nNGINX_WORK_PROCESS=`expr $CPU_COUNT \\* 2`\nsed -i \"s\/^worker_processes.*\/worker_processes $NGINX_WORK_PROCESS;\/g\" \/etc\/nginx\/nginx.conf\n\n## logrotate\nmessage \"normal\" \"create custom logrotate file\"\ncat &gt; \/etc\/logrotate.d\/nginx_vhost &lt;&lt; EOF\n$nginxlog\/*.log {\n        daily\n        missingok\n        rotate 52\n        compress\n        delaycompress\n        notifempty\n        create 640 nginx adm\n        sharedscripts\n        postrotate\n                if &#91; -f \/var\/run\/nginx.pid ]; then\n                        kill -USR1 \\`cat \/var\/run\/nginx.pid\\`\n                fi\n        endscript\n}\n\nEOF\n\n## reconfig php-fpm\nmessage \"normal\" \"reconfig php php-fpm config file\"\nREMI_ROOT=\/etc\/opt\/remi\/php$PHP_VERSION_USER_INPUT\nPHP_FPM_CONFIG_FILE=$REMI_ROOT\/php-fpm.d\/www.conf\n\nsed -i \"s#^listen = 127.*#listen = \/run\/php-fpm.sock#g\" $PHP_FPM_CONFIG_FILE\nsed -i \"s\/^user = apache\/user = nginx\/g\" $PHP_FPM_CONFIG_FILE\nsed -i \"s\/^group = apache\/group = nginx\/g\" $PHP_FPM_CONFIG_FILE\nsed -i \"s\/^;listen.backlog.*\/listen.backlog = -1\/g\" $PHP_FPM_CONFIG_FILE\nsed -i \"s\/^;listen.owner =.*\/listen.owner = nginx\/g\" $PHP_FPM_CONFIG_FILE\nsed -i \"s\/^;listen.group =.*\/listen.group = nginx\/g\" $PHP_FPM_CONFIG_FILE\nsed -i \"s\/^;listen.mode =.*\/listen.mode = 0660\/g\" $PHP_FPM_CONFIG_FILE\nsed -i \"s\/^php_value\/;php_value\/g\" $PHP_FPM_CONFIG_FILE\n\n## reconfig php.ini\nPHP_INI_CONFIG_FILE=$REMI_ROOT\/php.ini\nsed -i \"s\/upload_max_filesize.*\/upload_max_filesize = 12M\/g\" $PHP_INI_CONFIG_FILE\nsed -i \"s#^;date.timezone.*#date.timezone = 'Asia\/Shanghai'#g\" $PHP_INI_CONFIG_FILE\nsed -i \"s\/expose_php =.*\/expose_php = Off\/\" $PHP_INI_CONFIG_FILE\n\n## create phpinfo page\nmessage \"normal\" \"create phpinfo page\"\necho \"&lt;?php echo phpinfo();?&gt;\" &gt; $wwwroot\/index.php\n\n## create .user.ini file\necho \"open_basedir=$wwwroot\/:\/tmp\/:\/proc\/\" &gt; $wwwroot\/.user.ini\n\n# start php fpm\nmessage \"normal\" \"restart php-fpm\"\nsystemctl enable php$PHP_VERSION_USER_INPUT-php-fpm.service\nsystemctl start php$PHP_VERSION_USER_INPUT-php-fpm.service\n\n# restart nginx\nmessage \"normal\" \"restart nginx\"\nsystemctl restart nginx\n\n# print infomation\necho '''\nPHP\n\nPHP VERSION : $PHP_VERSION_USER_INPUT\nPHP FPM CONFIG FILE : $PHP_FPM_CONFIG_FILE\nPHP CONFIG FILE : $PHP_INI_CONFIG_FILE\nRESTART PHP FPM : systemctl restart php-fpm.service\n\nNGINX\n\nWWWROOT : $wwwroot\nNGINX CONFIG : \/etc\/nginx\/nginx.conf\nNGINX VHOST COFNIG : \/etc\/nginx\/conf.d\/default.conf\nNGINX VHOST LOG : $nginxlog\nNGINX RESTART : systemctl restart nginx\n''' &gt; \/root\/.php_install.txt\n\n\n\n\n<\/code><\/pre>\n\n\n\n<p>The tools is on my Cloud<\/p>\n\n\n\n<p><a href=\"https:\/\/cloud.anger.ltd\/index.php\/s\/N1NbfogXitO34o9\">https:\/\/cloud.anger.ltd\/index.php\/s\/N1NbfogXitO34o9<\/a><\/p>\n\n\n\n<p>The share password is : anger<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The tools is on my Cloud https:\/\/cloud.anger.ltd\/index.php\/s\/N1NbfogXitO34o9 The share password is : ange &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-52","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.anger.ltd\/index.php\/wp-json\/wp\/v2\/posts\/52","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.anger.ltd\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.anger.ltd\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.anger.ltd\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.anger.ltd\/index.php\/wp-json\/wp\/v2\/comments?post=52"}],"version-history":[{"count":5,"href":"https:\/\/www.anger.ltd\/index.php\/wp-json\/wp\/v2\/posts\/52\/revisions"}],"predecessor-version":[{"id":68,"href":"https:\/\/www.anger.ltd\/index.php\/wp-json\/wp\/v2\/posts\/52\/revisions\/68"}],"wp:attachment":[{"href":"https:\/\/www.anger.ltd\/index.php\/wp-json\/wp\/v2\/media?parent=52"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.anger.ltd\/index.php\/wp-json\/wp\/v2\/categories?post=52"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.anger.ltd\/index.php\/wp-json\/wp\/v2\/tags?post=52"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}