Install NGINX and PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/bash
set -e
set -u
set -o pipefail
FILE=""
banner()
{
echo "+------------------------------------------+"
printf "| %-40s |\n" "`date`"
echo "| |"
printf "|`tput bold` %-40s `tput sgr0`|\n" "$@"
echo "+------------------------------------------+"
}
DOMAIN_NAME=your_domain
sudo echo
banner "Upgrading and Updating"
sudo apt-get update && sudo apt-get upgrade -y
banner "Installing NGINX"
sudo apt-get install nginx -y
sudo service nginx start
banner "Installing MySQL and PHP"
sudo apt install mysql-server -y
sudo apt install php-fpm php-mysql -y
banner "Configuring NGINX"
sudo mkdir -p /var/www/$DOMAIN_NAME
sudo chown -R root:root /var/www/$DOMAIN_NAME
sudo chmod -R 755 /var/www/$DOMAIN_NAME
FILE=$DOMAIN_NAME
echo 'server {' > $FILE
echo ' listen 80;' >> $FILE
echo " server_name $DOMAIN_NAME www.$DOMAIN_NAME;" >> $FILE
echo " root /var/www/$DOMAIN_NAME;" >> $FILE
echo '' >> $FILE
echo ' index index.html index.htm index.php;' >> $FILE
echo '' >> $FILE
echo ' location / {' >> $FILE
echo ' try_files $uri $uri/ =404;' >> $FILE
echo ' }' >> $FILE
echo '' >> $FILE
echo ' location ~ \.php$ {' >> $FILE
echo ' include snippets/fastcgi-php.conf;' >> $FILE
echo ' fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;' >> $FILE
echo ' }' >> $FILE
echo '' >> $FILE
echo ' location ~ /\.ht {' >> $FILE
echo ' deny all;' >> $FILE
echo ' }' >> $FILE
echo '' >> $FILE
echo '}' >> $FILE
sudo chmod -R 644 $FILE
sudo chown -R root:root $FILE
sudo mv $FILE /etc/nginx/sites-available
sudo ln -s /etc/nginx/sites-available/$DOMAIN_NAME /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
banner "Creating sample web site files"
FILE=index.html
echo '<html>' > $FILE
echo ' <head>' >> $FILE
echo ' <title>$DOMAIN_NAME website</title>' >> $FILE
echo ' </head>' >> $FILE
echo ' <body>' >> $FILE
echo ' <h1>Hello World!</h1>' >> $FILE
echo '' >> $FILE
echo " <p>This is the landing page of <strong>$DOMAIN_NAME</strong>.</p>" >> $FILE
echo ' </body>' >> $FILE
echo '</html>' >> $FILE
sudo chmod -R 644 $FILE
sudo chown -R www-data:www-data $FILE
sudo mv $FILE /var/www/$DOMAIN_NAME
FILE=info.php
echo '<?php phpinfo();' > $FILE
sudo chmod -R 644 $FILE
sudo chown -R www-data:www-data $FILE
sudo mv $FILE /var/www/$DOMAIN_NAME/
exit
### test files do not work!!
source: <https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-20-04>
sudo apt install php7.4 -y
sudo apt-get install php7.4-fpm php7.4-cli php7.4-mysql php7.4-curl php7.4-json -y
sudo systemctl start php7.4-fpm
sudo systemctl enable php7.4-fpm
ln -s /etc/nginx/sites-available/example /etc/nginx/sites-enabled/
sudo unlink /etc/nginx/sites-enabled/default
sudo systemctl restart nginx
cat << 'EOF' > /var/www/html/info.php
<?php phpinfo();
EOF
Enable PHP in the NGINX site configuration
1
2
3
sudo service nginx reload
sudo apt-get install php-apc -y
sudo nano /etc/php5/fpm/conf.d/21-apc.ini
Add this:
1
2
3
4
5
6
apc.enabled=1
apc.shm_size=128M
apc.ttl=3600
apc.user_ttl=7200
apc.gc_ttl=3600
apc.max_file_size=1M
Get PHP configuration changes made
1
service php5-fpm restart
##Install MySQL
1
apt-get install mysql-server mysql-client php5-mysql -y
##Make new NGINX web site
1
nano /etc/nginx/sites-available/my_new_site
More to come.