├── README.md ├── screenshot.png └── script.sh /README.md: -------------------------------------------------------------------------------- 1 | # About 2 | 3 | ### install Important softwares on fresh Ubuntu instance 4 | 5 | - ✅ PREPAIRE Installing 6 | - ✅ REMOVING APACHE 7 | - ✅ Installing PHP 8.2 8 | - ✅ Installing NGINX 9 | - ✅ OPEN NGINX PORTS 10 | - ✅ Installing PHP EXTENSIONS 11 | - ✅ INCREASING FPM UPLOAD VALUES 12 | - ✅ Installing NPM 13 | - ✅ Installing CERTBOT (SSL GENERATOR) 14 | - ✅ CREATING NGINX FILE FOR [example.com](http://example.com/) 15 | - ✅ GENERATING SSL CERTIFICATE FOR [example.com](http://example.com/) 16 | - ✅ Finalize Installing 17 | - ✅ Installing MySQL 18 | - ✅ Pushing Cronjobs 19 | 20 | ### How to Use 21 | 22 | ```php 23 | 24 | wget -q https://raw.githubusercontent.com/peter-tharwat/new-ubuntu-laravel/master/script.sh -O script.sh ; sudo chmod +x script.sh ; ./script.sh -d example.com 25 | # Replace example.com with your domain 26 | ``` 27 | ![https://raw.githubusercontent.com/peter-tharwat/new-ubuntu-laravel/master/screenshot.png](https://raw.githubusercontent.com/peter-tharwat/new-ubuntu-laravel/master/screenshot.png) 28 | 29 | ### How To Debug LIVE 30 | 31 | ```php 32 | tail -f script_log.log 33 | ``` 34 | 35 | ### 36 | Made With Love By [PeterAyoub](https://PeterAyoub.me/) 37 | 38 | -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peter-tharwat/new-ubuntu-laravel/dac719d6a4deef23700aa50688252558e82bcca9/screenshot.png -------------------------------------------------------------------------------- /script.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | script_log_file="script_log.log" 4 | green_color="\033[1;32m" 5 | no_color="\033[0m" 6 | MYSQL_ROOT_PASSWORD=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 1) 7 | 8 | 9 | while getopts d: flag 10 | do 11 | case "${flag}" in 12 | d) domain=${OPTARG};; 13 | esac 14 | done 15 | 16 | 17 | 18 | 19 | echo $no_color"PREPAIRE INSTALLING"; 20 | rm -rf /var/lib/dpkg/lock >> $script_log_file 2>/dev/null 21 | rm -rf /var/lib/dpkg/lock-frontend >> $script_log_file 2>/dev/null 22 | rm -rf /var/cache/apt/archives/lock >> $script_log_file 2>/dev/null 23 | sudo apt-get update >> $script_log_file 2>/dev/null 24 | echo $green_color"[SUCCESS]"; 25 | echo $green_color"[######################################]"; 26 | 27 | 28 | echo $no_color"REMOVING APACHE"; 29 | sudo apt-get purge apache -y >> $script_log_file 2>/dev/null 30 | sudo apt-get purge apache* -y >> $script_log_file 2>/dev/null 31 | sudo kill -9 $(sudo lsof -t -i:80) >> $script_log_file 2>/dev/null 32 | sudo kill -9 $(sudo lsof -t -i:443) >> $script_log_file 2>/dev/null 33 | echo $green_color"[SUCCESS]"; 34 | echo $green_color"[######################################]"; 35 | 36 | echo $no_color"INSTALLING NGINX"; 37 | sudo apt-get update >> $script_log_file 2>/dev/null 38 | sudo apt install nginx -y >> $script_log_file 2>/dev/null 39 | echo $green_color"[SUCCESS]"; 40 | echo $green_color"[######################################]"; 41 | 42 | 43 | echo $no_color"OPEN NGINX PORTS"; 44 | echo "y" | sudo ufw enable >> $script_log_file 2>/dev/null 45 | sudo ufw allow 'Nginx HTTP' >> $script_log_file 2>/dev/null 46 | sudo ufw allow 'Nginx HTTPS' >> $script_log_file 2>/dev/null 47 | sudo ufw allow '8443' >> $script_log_file 2>/dev/null 48 | sudo ufw allow OpenSSH >> $script_log_file 2>/dev/null 49 | sudo add-apt-repository universe -y >> $script_log_file 2>/dev/null 50 | echo $green_color"[SUCCESS]"; 51 | echo $green_color"[######################################]"; 52 | 53 | echo $no_color"RESTARTING NGINX"; 54 | sudo pkill -f nginx & wait $! >> $script_log_file 2>/dev/null 55 | sudo systemctl start nginx >> $script_log_file 2>/dev/null 56 | sudo service nginx restart >> $script_log_file 2>/dev/null 57 | echo $green_color"[SUCCESS]"; 58 | echo $green_color"[######################################]"; 59 | 60 | echo $no_color"INSTALLING PHP 8.2"; 61 | sudo apt-get update >> $script_log_file 2>/dev/null 62 | sudo apt install lsb-release ca-certificates apt-transport-https software-properties-common -y >> $script_log_file 2>/dev/null 63 | sudo add-apt-repository ppa:ondrej/php -y >> $script_log_file 2>/dev/null 64 | sudo apt-get update >> $script_log_file 2>/dev/null 65 | sudo apt install php8.2 -y >> $script_log_file 2>/dev/null 66 | echo $green_color"[SUCCESS]"; 67 | echo $green_color"[######################################]"; 68 | 69 | # install php 8.2 fpm 70 | echo $no_color"INSTALLING PHP 8.2 FPM"; 71 | sudo apt install php8.2-fpm -y >> $script_log_file 2>/dev/null 72 | echo $green_color"[SUCCESS]"; 73 | echo $green_color"[######################################]"; 74 | echo $no_color"INSTALLING PHP 8.2 COMMON"; 75 | sudo apt install php8.2-common -y >> $script_log_file 2>/dev/null 76 | echo $green_color"[SUCCESS]"; 77 | echo $green_color"[######################################]"; 78 | 79 | #install php 8.3 80 | echo $no_color"INSTALLING PHP 8.3"; 81 | sudo apt install php8.3 -y >> $script_log_file 2>/dev/null 82 | echo $green_color"[SUCCESS]"; 83 | echo $green_color"[######################################]"; 84 | 85 | # install php 8.3 fpm 86 | echo $no_color"INSTALLING PHP 8.3 FPM"; 87 | sudo apt install php8.3-fpm php8.3-redis -y >> $script_log_file 2>/dev/null 88 | echo $green_color"[SUCCESS]"; 89 | echo $green_color"[######################################]"; 90 | 91 | echo $no_color"INSTALLING PHP EXTENSIONS"; 92 | # install php 8.2 extensions 93 | sudo apt install redis-server php8.2-redis php8.2 openssl php8.2-fpm php8.2-common php8.2-curl php8.2-mbstring php8.2-mysql php8.2-xml php8.2-zip php8.2-gd php8.2-cli php8.2-xml php8.2-imagick php8.2-xml php8.2-intl php-mysql -y >> $script_log_file 2>/dev/null 94 | # install php 8.3 extensions 95 | sudo apt install php8.3 openssl php8.3-fpm php8.3-common php8.3-curl php8.3-mbstring php8.3-mysql php8.3-xml php8.3-zip php8.3-gd php8.3-cli php8.3-xml php8.3-imagick php8.3-xml php8.3-intl php-mysql -y >> $script_log_file 2>/dev/null 96 | sudo apt-get purge apache -y >> $script_log_file 2>/dev/null 97 | sudo apt-get purge apache* -y >> $script_log_file 2>/dev/null 98 | echo $green_color"[SUCCESS]"; 99 | echo $green_color"[######################################]"; 100 | 101 | echo $no_color"INSTALLING NPM"; 102 | sudo apt install npm -y >> $script_log_file 2>/dev/null 103 | echo $green_color"[SUCCESS]"; 104 | echo $green_color"[######################################]"; 105 | 106 | echo $no_color"INSTALLING CERTBOT (SSL GENERATOR)"; 107 | sudo apt-get install snap -y >> $script_log_file 2>/dev/null 108 | sudo apt-get install snapd -y >> $script_log_file 2>/dev/null 109 | sudo snap install core >> $script_log_file 2>/dev/null 110 | sudo snap refresh core >> $script_log_file 2>/dev/null 111 | sudo snap install --classic certbot >> $script_log_file 2>/dev/null 112 | sudo ln -s /snap/bin/certbot /usr/bin/certbot >> $script_log_file 2>/dev/null 113 | echo $green_color"[SUCCESS]"; 114 | echo $green_color"[######################################]"; 115 | 116 | echo $green_color"[######################################]"; 117 | echo $no_color"INSTALLING COMPOSER"; 118 | sudo apt-get update >> $script_log_file 2>/dev/null 119 | sudo apt-get purge composer -y >> $script_log_file 2>/dev/null 120 | php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" >> $script_log_file 2>/dev/null 121 | php composer-setup.php >> $script_log_file 2>/dev/null 122 | sudo mv composer.phar /usr/local/bin/composer >> $script_log_file 2>/dev/null 123 | echo $green_color"[SUCCESS]"; 124 | echo $green_color"[######################################]"; 125 | 126 | echo $no_color"RESTARTING NGINX"; 127 | sudo pkill -f nginx & wait $! >> $script_log_file 2>/dev/null 128 | sudo systemctl start nginx >> $script_log_file 2>/dev/null 129 | sudo service nginx restart >> $script_log_file 2>/dev/null 130 | echo $green_color"[SUCCESS]"; 131 | echo $green_color"[######################################]"; 132 | 133 | echo $no_color"CREATING NGINX FILE FOR $domain"; 134 | sudo rm -rf /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default >> $script_log_file 2>/dev/null 135 | sudo touch /etc/nginx/sites-available/$domain >> $script_log_file 2>/dev/null 136 | sudo bash -c "echo 'server { 137 | listen 80; 138 | listen [::]:80; 139 | root /var/www/html/'$domain'/public; 140 | index index.php index.html index.htm index.nginx-debian.html; 141 | server_name '$domain' www.'$domain'; 142 | location / { 143 | try_files \$uri \$uri/ /index.php?\$query_string; 144 | } 145 | location ~ \.php$ { 146 | include snippets/fastcgi-php.conf; 147 | fastcgi_pass unix:/var/run/php/php8.2-fpm.sock; 148 | } 149 | location ~ /\.ht { 150 | deny all; 151 | } 152 | }' > /etc/nginx/sites-available/$domain" >> $script_log_file 2>/dev/null 153 | ln -s /etc/nginx/sites-available/$domain /etc/nginx/sites-enabled/ >> $script_log_file 2>/dev/null 154 | sudo mkdir /var/www/html/$domain >> $script_log_file 2>/dev/null 155 | sudo mkdir /var/www/html/$domain/public >> $script_log_file 2>/dev/null 156 | sudo bash -c "echo '

Welcome

$domain

' > /var/www/html/$domain/public/index.php" >> $script_log_file 2>/dev/null 157 | echo $green_color"[SUCCESS]"; 158 | echo $green_color"[######################################]"; 159 | 160 | 161 | echo $no_color"RESTARTING NGINX"; 162 | sudo pkill -f nginx & wait $! >> $script_log_file 2>/dev/null 163 | sudo systemctl start nginx >> $script_log_file 2>/dev/null 164 | sudo service nginx restart >> $script_log_file 2>/dev/null 165 | echo $green_color"[SUCCESS]"; 166 | echo $green_color"[######################################]"; 167 | 168 | 169 | 170 | 171 | echo $no_color"GENERATING SSL CERTIFICATE FOR $domain" 172 | certbot --nginx -d $domain -d www.$domain --non-interactive --agree-tos -m admin@$domain >> $script_log_file 2>/dev/null 173 | rm -rf /etc/nginx/sites-available/$domain >> $script_log_file 2>/dev/null 174 | sudo touch /etc/nginx/sites-available/$domain >> $script_log_file 2>/dev/null 175 | 176 | sudo bash -c "echo 'server { 177 | listen 80; 178 | #access_log off; 179 | root /var/www/html/'$domain'/public; 180 | index index.php index.html index.htm index.nginx-debian.html; 181 | client_max_body_size 1000M; 182 | fastcgi_read_timeout 8600; 183 | proxy_cache_valid 200 365d; 184 | if (!-d \$request_filename) { 185 | rewrite ^/(.+)/$ /\$1 permanent; 186 | } 187 | if (\$request_uri ~* "\/\/") { 188 | rewrite ^/(.*) /\$1 permanent; 189 | } 190 | location ~ \.(env|log|htaccess)\$ { 191 | deny all; 192 | } 193 | location ~*\.(?:js|jpg|jpeg|gif|png|css|tgz|gz|rar|bz2|doc|pdf|ppt|tar|wav|bmp|rtf|swf|ico|flv|txt|woff|woff2|svg|mp3|jpe?g,eot|ttf|svg)\$ { 194 | access_log off; 195 | expires 360d; 196 | add_header Access-Control-Allow-Origin *; 197 | add_header Pragma public; 198 | add_header Cache-Control \"public\"; 199 | add_header Vary Accept-Encoding; 200 | try_files \$uri \$uri/ /index.php?\$query_string; 201 | } 202 | location / { 203 | add_header Access-Control-Allow-Origin *; 204 | if (\$request_uri ~* \"^(.*/)index\.php(/?)(.*)\") { 205 | return 301 \$1\$3; 206 | } 207 | if (\$host ~* ^(www)) { 208 | rewrite ^/(.*)\$ https://'$domain'/\$1 permanent; 209 | } 210 | if (\$scheme = http) { 211 | return 301 https://'$domain'\$request_uri; 212 | } 213 | try_files \$uri \$uri/ /index.php?\$query_string; 214 | } 215 | 216 | location ~ \.php\$ { 217 | include snippets/fastcgi-php.conf; 218 | fastcgi_pass unix:/var/run/php/php8.3-fpm.sock; 219 | } 220 | listen 443 ssl; # managed by Certbot 221 | server_name '$domain' www.'$domain'; 222 | ssl_certificate /etc/letsencrypt/live/'$domain'/fullchain.pem; # managed by Certbot 223 | ssl_certificate_key /etc/letsencrypt/live/'$domain'/privkey.pem; # managed by Certbot 224 | include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot 225 | ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot 226 | }' > /etc/nginx/sites-available/$domain" >> $script_log_file 2>/dev/null 227 | echo $green_color"[SUCCESS]"; 228 | echo $green_color"[######################################]"; 229 | 230 | echo $no_color"RESTARTING NGINX"; 231 | sudo service nginx restart >> $script_log_file 2>/dev/null 232 | echo $green_color"[SUCCESS]"; 233 | echo $green_color"[######################################]"; 234 | 235 | if ! [ -x "$(command -v mysql)" >> $script_log_file 2>/dev/null ]; then 236 | echo $no_color"INSTALLING MYSQL"; 237 | export DEBIAN_FRONTEND=noninteractive 238 | echo debconf mysql-server/root_password password $MYSQL_ROOT_PASSWORD | sudo debconf-set-selections >> $script_log_file 2>/dev/null 239 | echo debconf mysql-server/root_password_again password $MYSQL_ROOT_PASSWORD | sudo debconf-set-selections >> $script_log_file 2>/dev/null 240 | sudo apt-get -qq install mysql-server >> $script_log_file 2>/dev/null 241 | 242 | sudo apt-get -qq install expect >> $script_log_file 2>/dev/null 243 | tee ~/secure_our_mysql.sh << EOF >> $script_log_file 2>/dev/null 244 | spawn $(which mysql_secure_installation) 245 | 246 | expect "Enter password for user root:" 247 | send "$MYSQL_ROOT_PASSWORD\r" 248 | expect "Press y|Y for Yes, any other key for No:" 249 | send "y\r" 250 | expect "Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG:" 251 | send "0\r" 252 | expect "Change the password for root ? ((Press y|Y for Yes, any other key for No) :" 253 | send "n\r" 254 | expect "Remove anonymous users? (Press y|Y for Yes, any other key for No) :" 255 | send "y\r" 256 | expect "Disallow root login remotely? (Press y|Y for Yes, any other key for No) :" 257 | send "n\r" 258 | expect "Remove test database and access to it? (Press y|Y for Yes, any other key for No) :" 259 | send "y\r" 260 | expect "Reload privilege tables now? (Press y|Y for Yes, any other key for No) :" 261 | send "y\r" 262 | EOF 263 | sudo expect ~/secure_our_mysql.sh >> $script_log_file 2>/dev/null 264 | rm -v ~/secure_our_mysql.sh >> $script_log_file 2>/dev/null 265 | echo $green_color"[SUCCESS] YOUR ROOT PASSWORD IS : $MYSQL_ROOT_PASSWORD"; >> $script_log_file 2>/dev/null 266 | sudo bash -c "echo $MYSQL_ROOT_PASSWORD > /var/www/html/mysql" >> $script_log_file 2>/dev/null 267 | echo $green_color"[SUCCESS]"; 268 | echo $green_color"[######################################]"; 269 | fi 270 | 271 | echo $green_color"CHANGING PHP FPM UPLOAD VALUES"; 272 | sudo sed -i 's/post_max_size = 8M/post_max_size = 1000M/g' /etc/php/8.2/fpm/php.ini >> $script_log_file 2>/dev/null 273 | sudo sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 1000M/g' /etc/php/8.2/fpm/php.ini >> $script_log_file 2>/dev/null 274 | sudo sed -i 's/max_execution_time = 30/max_execution_time = 300/g' /etc/php/8.2/fpm/php.ini >> $script_log_file 2>/dev/null 275 | sudo sed -i 's/memory_limit = 128/memory_limit = 12800/g' /etc/php/8.2/fpm/php.ini >> $script_log_file 2>/dev/null 276 | sudo service php8.2-fpm restart >> $script_log_file 2>/dev/null 277 | echo $green_color"[SUCCESS]"; 278 | echo $green_color"[######################################]"; 279 | 280 | 281 | if ! [ -x "$(command -v mysql)" >> $script_log_file 2>/dev/null ]; then 282 | echo $green_color"[MYSQL ALREADY INSTALLED!]"; 283 | echo $green_color"[######################################]"; 284 | fi 285 | 286 | echo $no_color"PUSHING CRONJOBS"; 287 | (crontab -l 2>/dev/null; echo "################## START $domain ####################") | crontab - 288 | (crontab -l 2>/dev/null; echo "* * * * * cd /var/www/html/$domain && rm -rf ./.git/index.lock && rm -rf ./.git/index && git reset --hard HEAD && git clean -f -d && git pull origin master --allow-unrelated-histories") | crontab - 289 | (crontab -l 2>/dev/null; echo "* * * * * cd /var/www/html/$domain && php artisan queue:restart && php artisan queue:work >> /dev/null 2>&1") | crontab - 290 | (crontab -l 2>/dev/null; echo "* * * * * cd /var/www/html/$domain && php artisan schedule:run >> /dev/null 2>&1") | crontab - 291 | (crontab -l 2>/dev/null; echo "* * * * * cd /var/www/html/$domain && chmod -R 777 *") | crontab - 292 | (crontab -l 2>/dev/null; echo "################## END $domain ####################") | crontab - 293 | echo $green_color"[SUCCESS]"; 294 | echo $green_color"[######################################]"; 295 | 296 | echo $no_color"FINALIZE INSTALLING"; 297 | sudo apt-get autoremove -y >> $script_log_file 2>/dev/null 298 | sudo bash -c "echo 'net.core.netdev_max_backlog = 65535'" | sudo tee -a /etc/sysctl.conf >> $script_log_file 2>/dev/null 299 | sudo bash -c "echo 'net.core.somaxconn = 65535'" | sudo tee -a /etc/sysctl.conf >> $script_log_file 2>/dev/null 300 | sudo apt-get autoclean -y >> $script_log_file 2>/dev/null 301 | sudo apt-get update >> $script_log_file 2>/dev/null 302 | echo $green_color"[SUCCESS]"; 303 | echo $green_color"[######################################]"; 304 | 305 | 306 | echo $green_color"[MADE WITH LOVE BY Peter Ayoub PeterAyoub.me]"; 307 | echo $green_color"[####################]"; 308 | --------------------------------------------------------------------------------