Nginx, PHP, MySQL, phpMyAdmin, which is often referred to as the LNMP suite, but here MySQL is replaced with a newer version of MariaDB on the Raspberry Pi. The following is the detailed process of installing LNMP on the Raspberry Pi.

Install Nginx

sudo apt-get install nginx-light

Install PHP7.3

sudo apt-get install php7.3-fpm

Configure Nginx

The default location of the Nginx configuration file is: /etc/nginx/nginx.conf, while configuring PHP only needs to modify the / etc / nginx / sites-available / default file. Modify the nginx configuration:

sudo nano /etc/nginx/sites-available/default
# Default server configuration
#
server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html index.php;

        server_name _;

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

        # pass PHP scripts to FastCGI server
        #
        location ~ \.php$ {
        #       include snippets/fastcgi-php.conf;
        #
        #       # With php-fpm (or other unix sockets):
                fastcgi_pass unix:/run/php/php7.3-fpm.sock;
        #       # With php-cgi (or other tcp sockets):
        #       fastcgi_pass 127.0.0.1:9000;
        # Set the path of the script file request
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        # Load fastcgi configuration file 
                include fastcgi_params;
        }

}

Restart nginx after modification, you can configure nginx and php:

sudo nginx -s reload

At this time, you can check whether the configuration is successful. Create a new index.php in the root directory of the website (/var/www/html) and enter the following content:

<?php phpinfo(); ?>

After saving and exiting, open http://raspberr pi ip/index.php in the browser, and you can see the phpinfo information, indicating that the php and nginx configuration is successful!

Install MySQL and phpMyAdmin

sudo apt-get install mariadb-server-10.3 phpmyadmin

An option to configure phpMyAdmin will appear in the middle. Since the web server used by the Raspberry Pi is Nginx, press "Esc" to exit here.

Near the end of the installation, another configuration option appeared:

Configuring phpmyadmin                          
  │ Otherwise, you should probably choose this option.              
  │ Configure database for phpmyadmin with dbconfig-common? 

Click yes to configure. You are then asked to enter a password to register with the mysql server.

Enter the password and click "OK" to confirm again. After the installation is complete, connect phpmyadmin to the root directory of the nginx server, so establish a soft link:

sudo ln -s /usr/share/phpmyadmin /var/www/html

Change database password

After the database is installed, there is no password. For security, modify the database encryption method and set a password. Login database:

sudo mysql -u root -p 

You can log in without password. Modify the encryption method:

update mysql.user set plugin='mysql_native_password';

Modify the password:

update mysql.user set password=PASSWORD where User='root'; #replace PASSWORD with your own password

Refresh:

flush privileges; 

At this time, a password is required to log in to the database.

This completes the steps of setting up a web server on the Raspberry Pi. A total of Nginx, PHP 7.3, MariaDB, and phpMyAdmin have been installed on the Raspberry Pi. You can log in to http://RaspPi IP/phpMyAdmin to manage the database (login name is root, password is the password you updated). You can also put the website file under /var/www/html, so as to easily set up a personal blog website on the Raspberry Pi.

Install wordpress

download wordpress

Enter the root directory and download the wordpress:

cd /var/www/html
wget https://wordpress.org/latest.zip
unzip latest.zip
cp -R wordpress/. .

Configure MySQL

http://RaspPi IP/phpMyAdmin

Click "New" in the left panel:

Enter the name of the database, here I use wordpress. You also need to select a collation, here I use the utf8_general_ci. Click Create to finish.

Open the webpage on browser:

http://RaspPi IP/

Here, the database is wordpress, the USername is root, and the password You updated password, and use default localhost as Database Host. Then click Submit to process.

That's all, enjoy!

Last modified: February 15, 2020

Author

Comments

Leave a Reply