Install LEMP Stack on Debian 9
Installing Nginx, Mariadb and PHP
Installation of nginx, MariaDB and PHP by bellow command line from bash terminal
apt install nginx mysql-server mysql-client php-fpm php-mysql libfcgi0ldbl
Now start all needed services with systemd and enable them to start at boot# systemctl start php7.0-fpm nginx mysql
# systemctl enable php7.0-fpm nginx mysql
Configuring LEMP StackNow Configure the mysql through bellow command line and use "y" for every question and set the mysql root password.
mysql_secure_installation
Now you need to bind socket for fastcgi through bellow command line cgi-fcgi -bind -connect /run/php/php7.0-fpm.sock
Now we are going to configure sites in nginx configuration folder. First we move default config as backup for security purposemv /etc/nginx/sites-available/default /etc/nginx/sites-available/df.bk
After that we will make our own configuration file by bellow command linenano /etc/nginx/sites-available/default
After that paste the bellow lines on the "default" empty file 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/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
}
}
echo "<?php phpinfo(); ?>" > /var/www/html/index.php
Now check the mysql is working properly or not. First create a database user and password also a database on the mysql by follow command line mysql -u root -e "CREATE USER 'hackthesec'@'%' IDENTIFIED BY 'test@123';"
mysql -u root -e "GRANT ALL PRIVILEGES ON *.* TO 'hackthesec'@'%' WITH GRANT OPTION"
To check the mysql is working or not use the following commandnano /var/www/html/db.php
<?php
$dbh = mysqli_connect('localhost', 'hackthesec', 'test@123');
if (!$dbh) {
die('Could not connect: ' . mysqli_error());
}
echo 'Connected successfully';
mysqli_close($dbh);
?>
Now reboot the system or restart the services ..
systemctl restart php7.0-fpm nginx mysql
Now open your web browser and hit your web server ip you will see the bellow test page.Allow lamp on firewall through bellow commands
ufw allow 3306/tcp
ufw allow 80/tcp
ufw allow 443/tcp (allow if you use https)
@Hackthesec
0 comments:
Post a Comment