Forked from jerry-gdd/Ubuntu 16.04 PHP7 setup for Craft CMS
Created
February 26, 2018 19:02
-
-
Save brooks/ce89661142e98ec187fdd9d35a766d3b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1) Get the latest available packages | |
sudo apt-get update | |
2) Install PHP7 and relevant extensions | |
Core PHP: | |
sudo apt-get install php7.0-fpm php7.0-cli php7.0-common php7.0-curl | |
Extensions needed for Craft: | |
sudo apt-get install php7.0-mysql php7.0-mbstring php7.0-mcrypt php-imagick php7.0-xml | |
breakdown: | |
- php7.0-mysql, for php to interact with the mysql database | |
- php7.0-mbstring, for managing non-ASCII strings | |
- php7.0-mcrypt, for data encryption and decryption | |
- php-imagick, for image transforms | |
- php7.0-xml, you can run craft without this one, but it would set off an errors when trying to connect asset sources to AWS s3 | |
Install Composer: | |
sudo apt-get install composer | |
Composer is the php package manager, needed install phpdotenv, which we need to manage sensitive credentials in a multi-environment setup. | |
3) Install other craft Dependencies: | |
sudo apt-get install git nginx mysql-server | |
breakdown: | |
- git, needed to clone code from remote repo to the server. | |
- nginx, webserver. I prefer nginx to apache due to the more readable syntax. | |
- mysql-server, needed for database migration tasks. Even if you end up hosting your DB on another instance (i.e. AWS RDS), you still need this on your EC2 instance to interact with the other server. | |
4) Add a new Linux user for deployments and set it to the same user group used by php | |
sudo adduser deploy | |
sudo groupadd web | |
sudo usermod -a -G web deploy | |
sudo usermod -a -G web www-data | |
5) Give the new user Sudo privileges | |
sudo visudo | |
After the line: | |
# User privilege specification | |
root ALL=(ALL:ALL) ALL | |
Add: | |
deploy ALL=(ALL:ALL) ALL | |
6) Configure nginx | |
sudo nano /etc/nginx/sites-available/your_site_name | |
paste in: | |
server { | |
listen 80; | |
listen [::]:80; | |
root /var/www/your_project/current/public; | |
index index.php index.html index.htm; | |
server_name ip_or_url_to_your_server; | |
location / { | |
try_files $uri $uri/ @rewrites; | |
} | |
location @rewrites { | |
rewrite ^(.*) /index.php?p=$1 last; | |
} | |
location ~ \.php$ { | |
try_files $uri =404; | |
fastcgi_split_path_info ^(.+\.php)(/.+)$; | |
fastcgi_pass unix:/run/php/php7.0-fpm.sock; | |
fastcgi_index index.php; | |
include fastcgi_params; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
} | |
expires off; | |
error_page 404 /index.php; | |
client_max_body_size 300M; | |
} | |
enable the config with a symbolic link: | |
sudo ln -s /etc/nginx/sites-available/your_site_name /etc/nginx/sites-enabled/your_site_name | |
restart nginx to load the new config: | |
sudo service nginx restart | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment