- Set up php-mysql sever on Raspberry pi
- Update your Pi apt-get
- Install Apache
- Install PHP
- Change directory to Public Html and Grant ownership to pi user
- Install MySQL
- Create User Query
- Grant User Permissions
- Install PHPMyAdmin
- Edit Apache Config
- Restart Apache Service
- Reboot Raspberry Pi
- test it by going to localhost and then localhost/phpmyadmin
Before you can begin setting up a web server on your Raspberry Pi, you need to make sure it's up-to-date.
sudo apt-get update-> give you latest software packages and security updates.
Installing Apache on your Raspberry Pi allows you to serve web pages to anyone who visits your website.
sudo apt-get install apache2 -y
PHP is a server-side scripting language that is used to create dynamic web pages.
sudo apt install libapache2-mod-php
When you install Apache, it creates a user called "www-data" that owns the files in the Public Html directory. However, you want to be able to edit these files, so you need to grant ownership of the directory to the "pi" user.
cd /var/www
sudo chown pi: htmlInstalling MySQL on your Raspberry Pi allows you to create and manage databases that your web applications can use.
sudo apt install mariadb-server php-mysql -yWhen you create a database in MySQL, you need to create a user that has permission to access that database. The command CREATE USER creates a new user with a username and password.
-
run my sql
sudo mysql -
CREATE USER 'qasim'@'localhost' IDENTIFIED BY 'password';
After creating a new user, you need to grant that user permissions to access the database. The command GRANT ALL PRIVILEGES grants the user full access to all databases and tables.
GRANT ALL PRIVILEGES ON *.* to 'qasim'@'localhost' WITH GRANT OPTION;
The WITH GRANT OPTION clause in the GRANT command allows the user to grant their permissions to other users.
PHPMyAdmin will provide a graphical user interface for managing MySQL databases.
sudo apt-get install phpmyadmin
In order to use PHPMyAdmin, you need to tell Apache where to find the PHPMyAdmin configuration files tells Apache to include myphpadmin files when it starts up.
run this -> sudo nano /etc/apache2/apache2.conf
go to last line add->Include /etc/phpmyadmin/apache.conf
ctrl-x- Y
sudo /etc/init.d/apache2 restart
Finally, rebooting your Raspberry Pi ensures that all changes are loaded
sudo reboot