# Instructions how to setup new AWS EC2 instance with Ubuntu Server 16.04 LTS and install PHP Laravel project and HTTPS # This is not a bash script, you have to run and control all commands manually sudo apt-get install nginx mysql-server sudo mysql_secure_installation sudo add-apt-repository ppa:ondrej/php && sudo apt-get update sudo apt-get install php7.1 php7.1-cli php7.1-common php7.1-mysql php7.1-fpm php7.1-curl php7.1-gd php7.1-bz2 php7.1-mcrypt php7.1-json php7.1-tidy php7.1-mbstring php-redis php-memcached php7.1-zip php7.1-dom php7.1-gmp # run after installation to create config directory from current user sudo apt-get install mc mc sudo mcedit /etc/php/7.1/fpm/php.ini # cgi.fix_pathinfo=0 sudo systemctl restart php7.1-fpm sudo mcedit /etc/nginx/sites-available/default server { listen 80 default_server; listen [::]:80 default_server; root /var/www/html; #! index index.php index.html index.htm index.nginx-debian.html; server_name _; #! location / { try_files $uri $uri/ /index.php?$query_string; } #! location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.1-fpm.sock; } #! location ~ /\.ht { deny all; } } sudo nginx -t sudo systemctl reload nginx echo "<?php phpinfo();" | sudo tee /var/www/html/info.php > /dev/null # check http://11.22.33.44/info.php sudo rm /var/www/html/info.php sudo chown -R "$USER":www-data /var/www/ sudo find /var/www/ -type f -exec chmod 660 {} \; && sudo find /var/www/ -type d -exec chmod 2770 {} \; sudo usermod -a -G www-data ubuntu # https sudo apt-get install software-properties-common && sudo add-apt-repository ppa:certbot/certbot && sudo apt-get update && sudo apt-get install python-certbot-nginx sudo mcedit /etc/nginx/sites-available/default # server_name my.domain.name; sudo systemctl reload nginx sudo certbot --nginx echo -e '#!/bin/sh\n\ncertbot renew\n' | sudo tee /etc/cron.daily/certbot-renew > /dev/null sudo chmod 0755 /etc/cron.daily/certbot-renew sudo certbot renew --dry-run sudo apt-get install git curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer cd /var && rm -rf www/html # set repository URL here git clone ... www cd www git checkout dev ln -s public html composer install sudo chgrp -R www-data storage bootstrap/cache sudo chmod -R ug+rwx storage bootstrap/cache sudo chmod -R 0777 storage/framework/cache cp .env.example .env && php artisan key:generate # set values in .env file - APP_NAME, DB_DATABASE, and other sudo apt-get install nginx mysql-server sudo mysql_secure_installation mysql_secure_installation asks a few setup questions. Would you like to setup VALIDATE PASSWORD plugin? n Change the password for root? n Remove anonymous users? y Disallow root login remotely? y Remove test database and access to it? y Reload privilege tables now? y sudo add-apt-repository ppa:ondrej/php && sudo apt-get update sudo apt-get install php7.1 php7.1-cli php7.1-common php7.1-mysql php7.1-fpm php7.1-curl php7.1-gd php7.1-bz2 php7.1-mcrypt php7.1-json php7.1-tidy php7.1-mbstring php-redis php-memcached php7.1-zip php7.1-dom php7.1-gmp sudo apt-get install mc mc sudo mc , since the configuration files will be created by the root user, and when starting from the normal user there will be an access error. sudo mcedit /etc/php/7.1/fpm/php.ini # cgi.fix_pathinfo=0 sudo systemctl restart php7.1-fpm cgi.fix_pathinfo setting, uncomment and put 0. This is the closing of the vulnerability, you can read more here . sudo mcedit /etc/nginx/sites-available/default server { listen 80 default_server; listen [::]:80 default_server; root /var/www/html; #! index index.php index.html index.htm index.nginx-debian.html; server_name _; #! location / { try_files $uri $uri/ /index.php?$query_string; } #! location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.1-fpm.sock; } #! location ~ /\.ht { deny all; } } index - add index.phptry_files - remove =404 , add /index.php?$query_stringlocation ~ \.php$ - uncomment the section, change the name of the file with the socketlocation ~ /\.ht - uncomment the section for * .htaccess files sudo nginx -t sudo systemctl reload nginx echo "<?php phpinfo();" | sudo tee /var/www/html/info.php > /dev/null # check http://11.22.33.44/info.php sudo rm /var/www/html/info.php 11.22.33.44 denotes the instance IP address. sudo chown -R "$USER":www-data /var/www/ sudo find /var/www/ -type f -exec chmod 660 {} \; && sudo find /var/www/ -type d -exec chmod 2770 {} \; sudo usermod -a -G www-data ubuntu www-data user from the www-data group, SSH connects with the ubuntu user. You need to add ubuntu to this group, otherwise there may be problems with access. For example, when a console command creates a folder where the recording will go when the site is opened via the web. sudo apt-get install software-properties-common && sudo add-apt-repository ppa:certbot/certbot && sudo apt-get update && sudo apt-get install python-certbot-nginx sudo mcedit /etc/nginx/sites-available/default # server_name my.domain.name; sudo systemctl reload nginx sudo certbot --nginx echo -e '#!/bin/sh\n\ncertbot renew\n' | sudo tee /etc/cron.daily/certbot-renew > /dev/null sudo chmod 0755 /etc/cron.daily/certbot-renew sudo certbot renew --dry-run sudo apt-get install git curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer cd /var && rm -rf www/html # set repository URL here git clone ... www cd www git checkout dev ln -s public html composer install html folder, you need to remove it and make a symlink to the folder where the index.php is in the project. In Laravel, this is the public folder. sudo chgrp -R www-data storage bootstrap/cache sudo chmod -R ug+rwx storage bootstrap/cache sudo chmod -R 0777 storage/framework/cache cp .env.example .env && php artisan key:generate Source: https://habr.com/ru/post/344908/
All Articles