Raspberry Pi Web Server Installation
Raspberry Pi Web Server Installation
Hello friends, in this article I will try to explain how you can install a Web Server on your Raspberry Pi device. By the end of the article, we will have installed tools available on basic web servers like Apache, Php, FTP, MySQL, and PhpMyAdmin to our system.
Anyway, let’s not extend the introduction further and start with the installation.
Apache 2 Installation
sudo apt install apache2 -y
First, we type the code above and start the Apache 2 installation. After the installation, you can access the web page by entering the local network IP address of your Raspberry device into your browser, either from any device connected to the same network or from the Raspberry device itself. When you do, you will see a page like below and it will say "It's Work" on the page.
If you do not know the necessary IP address to access the page above, you can find it by entering the following code into the console/terminal
hostname -I
This command will give you an output like below.
If we have reached this point without a problem, now we need to set the necessary permissions for Apache2.
Apache2 Permission Settings
sudo a2enmod rewrite sudo systemctl restart apache2 sudo chown -R pi:www-data /var/www/html/ sudo chmod -R 770 /var/www/html/ sudo nano /etc/apache2/apache2.conf // with this command we open the apache2.conf file.
You need to enter the codes above one by one in order, the last command allows us to edit a file.
When you first enter the file, it will look like the following.
Directory /var/www/
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
/Directory
You need to change the "AllowOverride None" part here to "AllowOverride All". So, the final state of the file should be as follows.
Directory /var/www/
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
/Directory
Note: You can save by pressing CTRL + O and when you press Enter the file will be saved. To exit the file, you need to press CTRL + X.
After making our file look like this, we save and close it. Then, we need to restart our Apache server; you can use the following command for this.
sudo service apache2 restart
Right after restarting, if you want, go to your web page as above and check. If it opens, there is no problem.
PHP Installation
sudo apt install php libapache2-mod-php -y
With this command PHP 7 will be installed without any problems.
After installation, to get information about our PHP version and status, we need to create a file named inde.php inside the www folder and then call the Php Info function.
To delete the index.html file that comes with the Apache installation, we call the code below.
sudo rm /var/www/html/index.html
Immediately after this code, to create index.php and call the php info function, we enter the code below.
echo "<?php phpinfo ();?>" > /var/www/html/index.php
If you see a screen like the one below after these steps, it means PHP has been installed successfully.
MYSQL Installation
sudo apt install mysql-server php-mysql -y // Our code for MySQL installation. If you get an error, you can install mariaDB with sudo apt install mariadb-server php-mysql -y. sudo service apache2 restart // Here we restart apache sudo mysql_secure_installation // We open security-related setups.
We enter the codes above in order.
After entering our last code, it will ask you a few questions. Let's go through them one by one.
- First, it will ask you to enter your device password. (If you are using RaspiOS, it is "raspberry". The one you used to log in.)
- It asks if you want to set a new password for SQL, press "Y" and enter your new SQL password twice.
- Press "Y" to close anonymous users.
- Press "Y" to prevent remote root access.
- Press "Y" to remove the test database.
- Press "Y" to update the tables containing access information.
If you have performed the steps completely, a screen like below will greet you and it will say "Thanks for using MariaDB!"
Our MySQL installation is now complete here.
PhpMyAdmin Installation
sudo apt install phpmyadmin -y
We start the installation with the above code.
A screen like this appears, here select "Apache2" and press enter.
On the part about "Dbconfig-common" select "No" and press enter.
At the end of the process, you can now access phpmyadmin from the address "ipadress/phpmyadmin".
If you see a web page like the one above when you access the address, it means the installation is complete without any problems. Now, to avoid dealing with constantly uploading site files with a usb to our device, it would be good to install an FTP server.
Note: If, after these steps, when you try to access PhpMyAdmin you get
Note: If, after these steps, when you try to access PhpMyAdmin you get
NOT FOUND The requested URL /phpmyadmin was not found on this server.
if you get such an error, what you need to do is this.
sudo nano /etc/apache2/apache2.conf
Include /etc/phpmyadmin/apache.conf
then restart Apache again.
sudo service apache2 restart
After refreshing Apache, it should now be accessible without any problem.
Note2: You cannot login with "root" via PhpMyAdmin, so you need to create an account.
sudo mysql -uroot -p CREATE USER 'username'@'localhost' IDENTIFIED BY 'yourpassword'; GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost' WITH GRANT OPTION; FLUSH PRIVILEGES;
with this you can create an account and login with the account you created.
FTP Server Installation
First, start the installation with the command below.
sudo apt install vsftpd -y
Then, to open the vsftpd file for editing, use the code below.
sudo nano /etc/vsftpd.conf
Inside the file
local_enable=YESssl_enable=NO
Find these parts and
#local_enable=YES#ssl_enable=NO
Change them as above, then you need to add the following at the very bottom of the file.
# CUSTOMssl_enable=YESlocal_enable=YESchroot_local_user=YESlocal_root=/var/www user_sub_token=piwrite_enable=YES local_umask=002allow_writeable_chroot=YES
ftpd_banner= welcome to urhoba.net FTP service.
You can write whatever you want in place of urhoba.net here. This is the message that will be shown when users or you connect.
Now, you need to run the following commands in order.
sudo usermod -a -G www-data pi sudo usermod -m -d /var/www pi sudo chown -R www-data:www-data /var/www sudo chmod -R 775 /var/www sudo reboot
When you run these commands, your device will restart at the end and if you didn’t make any mistakes, our FTP server will now be working.
Host: ftp://ipadressUsername: PiPassword: raspberry (Same as the one you use to access the device.)Port: 21
You can now log in with this information and any ftp client program, and upload your site files.









Yorum Gönder