0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

VPSを借りる [PHP] #3

Last updated at Posted at 2020-10-03

#PHP
※How to Install PHP on CentOS 8

DOMAIN=yourdomain

sudo dnf install @php php-opcache php-gd

php -v

sudo systemctl enable --now php-fpm

sudo cp -p /etc/php-fpm.d/www.conf /etc/php-fpm.d/www.conf.origin
sudo sed -i -e "s/^user = apache/user = nginx/g" /etc/php-fpm.d/www.conf
sudo sed -i -e "s/^group = apache/group = nginx/g" /etc/php-fpm.d/www.conf
diff -u /etc/php-fpm.d/www.conf.origin /etc/php-fpm.d/www.conf

sudo chown -R root:nginx /var/lib/php
sudo systemctl restart php-fpm

sudo tee /var/www/$DOMAIN/public_html/index.php << EOF
<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>Welcome to $DOMAIN</title>
  </head>
  <body>
    
    <?php echo '<h1>Success! $DOMAIN home page! written in PHP!</h1>'; ?> 
  </body>
</html>
EOF

sudo tee /var/www/$DOMAIN/public_html/phpinfo.php << EOF
<?php
    phpinfo();
?>
EOF

sudo tee /var/www/$DOMAIN/public_html/mbinfo.php << EOF
<?php
    print_r(mb_get_info());
?>
EOF

sudo chown -R nginx: /var/www/$DOMAIN
sudo restorecon -RF /var/www/$DOMAIN/public_html/

sudo tee /etc/nginx/conf.d/$DOMAIN.conf << EOF
server {
    listen 80;
    listen [::]:80;

    server_name www.$DOMAIN $DOMAIN;

    include snippets/letsencrypt.conf;

    location / {
        return 301 https://\$host\$request_uri;
    }
}

server {
    listen 443 ssl http2;

    server_name www.$DOMAIN $DOMAIN;

    ssl_certificate /etc/letsencrypt/live/$DOMAIN/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/$DOMAIN/privkey.pem;
    ssl_trusted_certificate /etc/letsencrypt/live/$DOMAIN/chain.pem;

    include snippets/ssl.conf;

    root /var/www/$DOMAIN/public_html;

    index index.php;

    access_log /var/log/nginx/$DOMAIN.access.log;
    error_log /var/log/nginx/$DOMAIN.error.log;

    location ~ \.php\$ {
        try_files \$uri =404;
        fastcgi_pass unix:/run/php-fpm/www.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
        include fastcgi_params;
    }
}
EOF

sudo nginx -t

sudo systemctl reload nginx
systemctl status nginx

image.png
VPSを借りる [VPS、SSH、Nginx] #1
VPSを借りる [HTTPS] #2

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?