Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save niteshpurohit/65211b8ab56ab5c0abcfbb2dd5c17835 to your computer and use it in GitHub Desktop.
Save niteshpurohit/65211b8ab56ab5c0abcfbb2dd5c17835 to your computer and use it in GitHub Desktop.
Setup PHP Server with Letsencrypt

php and mods

sudo yum install -y php

sudo yum install -y php-zip php-xml php-gd

httpd

sudo yum install -y httpd

sudo systemctl start httpd

sudo systemctl enable httpd

configuring user

sudo usermod -a -G apache ec2-user

ec2-user = your username

after this exit and login back


After logining back

sudo chown -R ec2-user:apache /var/www

sudo chmod 2775 /var/www && find /var/www -type d -exec sudo chmod 2775 {} \;

find /var/www -type f -exec sudo chmod 0664 {} \;

ssl

sudo yum install -y mod_ssl

add certbot repo

sudo wget -r --no-parent -A 'epel-release-*.rpm' http://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/

sudo rpm -Uvh dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-*.rpm

sudo yum-config-manager --enable epel*

Configure httpd.conf for certbot

Edit the main Apache configuration file, /etc/httpd/conf/httpd.conf. Locate the "listen 80" directive and add the following lines after it, replacing the example domain names with the actual Common Name and Subject Alternative Name (SAN) to configure:

sudo nano /etc/httpd/conf/httpd.conf

then use this template

	<VirtualHost *:80>
		DocumentRoot "/var/www/html"
		ServerName "example.com"
		ServerAlias "www.example.com"
	</VirtualHost>

restart httpd

sudo systemctl restart httpd

install and run certbot

sudo yum install -y certbot python2-certbot-apache

sudo certbot

follow on screen instructions

use your EMAIL when asked for email

then restart httpd

sudo systemctl restart httpd

automate certbot

open /etc/crontab and paste

sudo nano /etc/crontab

39      1,13    *       *       *       root    certbot renew --no-self-upgrade

then restart crond

sudo systemctl restart crond

setup php.ini and httpd conf according to app

#PHP

sudo nano /etc/php.ini

find and set these values

upload_max_filesize = 20M
post_max_size = 28M
memory_limit = -1

httpd

sudo nano /etc/httpd/conf/httpd.conf

'<Directory "/var/www/html">' Directory entery

replace line of AllowOverride from AllowOverride All

restart httpd

sudo systemctl restart httpd

setup code sync

Glossary

to start httpd

sudo systemctl start httpd

to stop httpd

sudo systemctl stop httpd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment