Skip to main content

Some notes about caddy webserver installation on Linux

 

caddy

https://caddyserver.com/docs/install#debian-ubuntu-raspbian

sudo apt update

sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https

curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo tee /etc/apt/trusted.gpg.d/caddy-stable.asc

curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list

sudo apt update

sudo apt install caddy


# the code sits in /var/www

# create link to the local directory

ln -s /var/www/ /home/xxx/myprojects/web


# set the user to be xxx and the group caddy

sudo chown -R xxx:caddy ./www  


# add us to caddy groups

sudo usermod -a -G caddy xxx

sudo usermod -a -G www-data xxx


Install php-fpm

sudo apt install php-cli php-fpm php-mysql php-mbstring php-curl

https://www.howtoforge.com/tutorial/ubuntu-caddy-web-server-installation/


configure caddy with php

sudo nano /etc/php/8.1/fpm/pool.d/www.conf

#change users to caddy (user, group, listen.owner, listen.group)

#take the socket name: listen = /run/php/php8.1-fpm.sock

nano php.ini # set E_ALL view all errors

sudo systemctl restart php8.1-fpm

#set socket in Caddyfile: php_fastcgi unix//run/php/php8.1-fpm.sock

sudo service caddy stop && sudo service caddy start

 

Caddyfile
website.com {
#:80 {
tls /var/www/fullchain.pem /var/www/privkey.pem

# Set this path to your site's directory.
root * /var/www/website.com
php_fastcgi unix//run/php/php7.4-fpm.sock

# Enable the static file server.
# file_server
rewrite /symbol/* s.php?s={path}
# rewrite /symbol/ {
# r ^/(\w+)/?$
# to /symbol.php?symbol={1}
# }
file_server

encode gzip

log {
output file /var/log/caddy/example.com.access.log {
roll_size 3MiB
roll_keep 5
roll_keep_for 48h
}
format console
}
# Another common task is to set up a reverse proxy:
# reverse_proxy localhost:8080

# Or serve a PHP site through php-fpm:
# php_fastcgi localhost:9000

#RewriteRule ^symbol/jscss/([^/]*)\.([^/]*)$ /jscss/$1.$2 [L] # no need for those since we used <base href="../" />
#RewriteRule ^symbol/images/([^/]*)\.([^/]*)$ /images/$1.$2 [L]
#rewrite /symbol/* / symbol.php?symbol={query}

 

 

I had the same problem whith my docker php-fpm and I fixed it by modifing parameters

 in these files: /usr/local/etc/php-fpm.d/www.conf /usr/local/etc/php-fpm.d/www.conf.default

The new parameters are :

pm = dynamic
pm.max_children = 25
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 20
pm.max_requests = 500

 

 

- ADD how to enabled logs in PHP 

 

Comments

Popular posts from this blog

Using phpword to merge two Mircrosoft Office Word .docx documents

How to combine or embed and insert another .docx file (Microsoft office docx word document) into another one using PHPWord Joining two .docx document using php ( phpword library ) $mainTemplateProcessor = new \PhpOffice\PhpWord\TemplateProcessor("file1"); //$mainTemplateProcessor ->setValue('var_name', $value); $innerTemplateProcessor = new \PhpOffice\PhpWord\TemplateProcessor("file2"); //$innerTemplateProcessor->setValue('var2_name', $value2); // extract internal xml from template that will be merged inside main template $innerXml = $innerTemplateProcessor->gettempDocumentMainPart(); $innerXml = preg_replace('/^[\s\S]*<w:body>(.*)<\/w:body>.*/', '$1', $innerXml); // remove tag containing header, footer, images $innerXml = preg_replace('/<w:sectPr>.*<\/w:sectPr>/', '', $innerXml); // inject internal xml inside main template $mainXml = $mainTemplateProcessor->gettempDocumentMainPart(

Bypassing the error by "go get" "tls: failed to verify certificate: x509: certificate signed by unknown authority"

When I was trying to download dependencies for my go project in an old Ubuntu machine I was getting this error all the time: "go: gopkg.in/alexcesaro/quotedprintable.v3@v3.0.0-20150716171945-2caba252f4dc: Get "https://proxy.golang.org/gopkg.in/alexcesaro/quotedprintable.v3/@v/v3.0.0-20150716171945-2caba252f4dc.mod": tls: failed to verify certificate: x509: certificate signed by unknown authority" Which the main part of it was go get failing to authenticate: " tls: failed to verify certificate: x509: certificate signed by unknown authority " I tried many things but couldn't make it work until I found the way: export GOINSECURE="proxy.golang.go" This will tell go get to ignore certification validity. Then export GOPROXY=direct This will tell go get to by pass proxy Then git config --global http.sslverify false And only after those I could run again: go get And it worked