皮皮虾的博客

一个备受大佬们欺负的萌新

[折腾]小型HTTP服务Caddy及配置PHP

前言(废话)

Caddy是一个轻量级的http服务器,虽然很轻但是却很实用,功能也很强大。适合各种小内存鸡鸡

反代超级方便,证书申请很方便

本文主要内容是caddy的安装和配置php

安装

开始搞事

准备工作

apt-get update -y
apt-get install -y gcc g++ make zip lrzsz autoconf curl libxml2 libxml2-dev libssl-dev bzip2 libbz2-dev libjpeg-dev libpng12-dev libfreetype6-dev libgmp-dev libmcrypt-dev libreadline6-dev libsnmp-dev libxslt1-dev libcurl4-openssl-dev
groupadd -r php
groupadd -r www
useradd -r -g php -s /bin/false -d /usr/local/php -M php
useradd -r -g www -s /bin/false -d /usr/local/www -M www

#安装必要的依赖文件和创建PHP运行用户.组

安装PHP

#简便方法 apt install php

#编译安装

mkdir php
cd php
wget http://am1.php.net/distributions/php-7.2.8.tar.gz
tar -zxf php-7.2.8.tar.gz
cd php-7.2.8
ossl=`find / -name libssl.so`
ln -s $ossl /usr/lib
./configure –prefix=/usr/local/php –exec-prefix=/usr/local/php –bindir=/usr/local/php/bin –sbindir=/usr/local/php/sbin –includedir=/usr/local/php/include –libdir=/usr/local/php/lib/php –mandir=/usr/local/php/php/man –with-config-file-path=/usr/local/php/etc –with-mysql-sock=/var/run/mysql/mysql.sock –with-mhash –with-openssl –with-mysqli=shared,mysqlnd –with-pdo-mysql=shared,mysqlnd –with-gd –with-iconv –with-zlib –enable-zip –enable-inline-optimization –disable-debug –disable-rpath –enable-shared –enable-xml –enable-bcmath –enable-shmop –enable-sysvsem –enable-mbregex –enable-mbstring –enable-ftp –enable-pcntl –enable-sockets –with-xmlrpc –enable-soap –without-pear –with-gettext –enable-session –with-curl –with-jpeg-dir –with-freetype-dir –enable-opcache –enable-fpm –with-fpm-user=php –with-fpm-group=php –without-gdbm –disable-fileinfo
make && make install

/etc/profile 中增加以下行

export PHP_HOME=/usr/local/php
export PATH=$PHP_HOME/bin:$PATH

source /etc/profile
cp sapi/fpm/init.d.php-fpm /usr/local/bin/php-fpm
chmod +x /usr/local/bin/php-fpm
cp php.ini-production /usr/local/php/etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

创建进程池 /usr/local/php/etc/php-fpm.d/www.conf


; Start a new pool named ‘www’
[www]
listen = /usr/local/php/var/run/$pool-php-fpm.sock
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
listen.owner = www
listen.group = www
listen.mode = 0660
user = www
group = www
pm = dynamic
pm.max_children = 10
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 6
pm.status_path = /status
ping.path = /ping
ping.response = pong
request_terminate_timeout = 100
request_slowlog_timeout = 10s
slowlog = /usr/local/php/var/log/$pool.log.slow

启动php

/usr/local/bin/php-fpm start

 

 

caddy安装

curl https://getcaddy.com | bash -s personal http.cgi,http.filemanager

创建网站文件夹

mkdir -p /data/www/default
chown -R www:www /data/www/

创建配置文件-实例

http://localhost {
root /data/www/default
gzip
fastcgi / /usr/local/php/var/run/www-php-fpm.sock {
ext .php
split .php
index index.php
}

 

后台运行 Caddy

nohup caddy -conf=/etc/caddy.conf >> /usr/local/caddy.log 2>&1 &

 

点赞

发表评论

电子邮件地址不会被公开。 必填项已用*标注

Captcha Code