Raspberry Pi has a lot of firmware version for choosing, here I recommanded the official Raspbian as exmaple (Raspbian Stretch). Configure the IP of your Raspberry Pi. Then SSH up and start the installation.

Root permission is recommended for below execution.

1. Install Nginx and PHP7

sudo apt-get update
sudo apt-get install nginx php7.0-fpm php7.0-cli php7.0-curl php7.0-gd php7.0-mcrypt php7.0-cgi
sudo service nginx start
sudo service php7.0-fpm restart

If the installation is successful, you can access Nginx’s default page via http:// your-raspberry-pi-IP. Nginx’s root directory is “/var/www./html”

2. Install MySql

sudo apt-get install mysql-server mysql-client

sudo service mysql restart

When you install mysql for the first time, you may be prompted for your password. Don’t forget your password. If not any indication, then it may installed without password. You are able to change it via

  • Connecting the mysql
use mysql;
  • Change the password as “xxxxxx”
setpassword=PASSWORD('xxxxxx');
  • Refresh and Quit;
flush privileges;
exit; 
The process of setting mysql password

3. Enable Nginx to handle PHP

sudonano /etc/nginx/sites-available/default

Find the below part,

location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }
Then change as,

location / {
index  index.html index.htm index.php default.html default.htm default.php;
}
 
location ~\.php$ {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

“Ctrl + O” save it and “Ctrl + X” to quite

Then restart the Nginx.

sudo service nginx restart

Create a test page in the root folder under the default file (/var/www/html) : index.php, something like below example,

<?phh
phpinfo<>;
?>

browse the http://localhost on your Raspberry Pi, or visit http://your-raspberry-pi-IP-address/, to check if you can get correct PHP info output.

At this point our LNMP environment configuration is complete! The next step is to install phpmyadmin into the specified directory. We will talk about it in other sessions.

Leave a Reply

Your email address will not be published. Required fields are marked *