LEMP , WP , SSL install and configuration on Ubuntu 18.04
-
Install Nginx
sudo apt install -y nginx
Install and Configure Maria DB
sudo apt install -y mariadb-server sudo systemctl enable mariadb sudo systemctl start mariadb
Setup WP database
sudo mysql_secure_installation mysql -u root -p
Then create database and user
CREATE DATABASE wp_db; CREATE USER wpuser IDENTIFIED BY 'Passw0rd2'; GRANT ALL ON wp_db.* TO `wpuser`;
Install Certbot
sudo apt install python-certbot-nginx -y
Install PHP
sudo apt install -y php sudo apt install -y php-pear php-fpm php-dev php-zip php-curl php-xmlrpc php-gd php-mysql php-mbstring php-xml libapache2-mod-php
Configure PHP
sudo sh -c "sed -i '/cgi.fix_pathinfo=1/c\cgi.fix_pathinfo=0' /etc/php/7.2/fpm/php.ini" sudo sh -c "echo '' >> /etc/php/7.2/fpm/php.ini" sudo sh -c "echo '' >> /etc/php/7.2/fpm/php.ini" sudo sh -c "echo ';***********************************************************' >> /etc/php/7.2/fpm/php.ini" sudo sh -c "echo '; Wordpress Settings ' >> /etc/php/7.2/fpm/php.ini" sudo sh -c "echo ';***********************************************************' >> /etc/php/7.2/fpm/php.ini" sudo sh -c "echo 'upload_max_filesize = 500M' >> /etc/php/7.2/fpm/php.ini" sudo sh -c "echo 'post_max_size = 2000M' >> /etc/php/7.2/fpm/php.ini" sudo sh -c "echo 'memory_limit = 2000M' >> /etc/php/7.2/fpm/php.ini" sudo sh -c "echo 'max_execution_time = 120' >> /etc/php/7.2/fpm/php.ini"
Create Website Configuration
sudo sh -c "cat > /etc/nginx/sites-available/mywebsite.com <<\EOF server { listen 80; listen [::]:80; root /var/www/html; index index.php index.html index.htm; server_name mywebsite.com www.mywebsite.com; client_max_body_size 500M; location / { try_files \$uri \$uri/ /index.php?\$args; } location = /favicon.ico { log_not_found off; access_log off; } location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { expires max; log_not_found off; } location = /robots.txt { allow all; log_not_found off; access_log off; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name; include fastcgi_params; } } EOF "
Configure site link for nginx
sudo sh -c "ln -s /etc/nginx/sites-available/mywebsite.com /etc/nginx/sites-enabled/" sudo sh -c "rm -f /etc/nginx/sites-available/default" sudo sh -c "rm -f /etc/nginx/sites-enabled/default" sudo systemctl restart nginx
Install Wordpress
sudo sh -c "wget https://wordpress.org/latest.tar.gz -o /var/www/html/latest.tar.gz" sudo sh -c "tar -zxvf latest.tar.gz -C /var/www/html/ --strip-components=1" sudo sh -c "rm -rf /var/www/html/latest.tar.gz" sudo sh -c "cp /var/www/html/wp-config-sample.php /var/www/html/wp-config.php"
Set permissions
sudo chown -R www-data:www-data /var/www/html/* sudo chmod -R 755 /var/www/html/*
Set WP config
sudo sh -c "sed -i '/database_name_here/c\define\( '\''DB_USER'\'', '\''wpuser'\'' \);' /var/www/html/wp-config.php" sudo sh -c "sed -i '/username_here/c\define\( '\''DB_NAME'\'', '\''wp_db'\'' \);' /var/www/html/wp-config.php" sudo sh -c "sed -i '/password_here/c\define\( '\''DB_PASSWORD'\'', '\''Passw0rd2'\'' \);' /var/www/html/wp-config.php"
Install SSL
Note: you must point your DNS to this server to your server before completing this step. Otherwise you will not be able to prove domain ownership
sudo certbot --nginx -m [email protected] -d mywebsite.com -d www.mywebsite.com