How to set up a Raspberry Pi web server – Tom’s Hardware

One of the most popular uses for the Raspberry Pi is as a web server that lives on your local network. Whether you need an intranet for your office or a small server for web development, the Pi is a great choice. In fact, at Tom’s Hardware we have a local Pi web server that we use to deliver our laptop battery test content, which involves continuous browsing over Wi-Fi.

To run your web server, you will need a Raspberry Pi connected to your local network and running a fairly recent version of the Raspbian operating system. These instructions will work on just about any model, including the mighty Raspberry Pi 4 and the tiny Raspberry Pi Zero W. If you need to install Raspbian, check out our tutorial on how to set up a Raspberry Pi or, better yet, how to do a headless installation (no keyboard or screen required).

1. Go to command prompt / terminal. You can access it by pressing CTRL + ALT + T from the Raspbian desktop or by connecting remotely via SSH if you have configured it. Some users also configure the Raspberry Pi to boot directly from the command prompt.

2. Update your packages typing

sudo apt-get update

This will ensure that you get the latest versions of every file you download after that.

3. Install Apache2 with the command:

sudo apt-get install apache2 -y

4. Install php for your server by typing:

sudo apt-get install php libapache2-mod-php -y

5. Install mariadb so you can use a mysql database with your website. You start by typing:

sudo apt-get install mariadb-server

Then once the download is complete. You must perform the formal installation by typing:

sudo mysql_secure_installation

You will be prompted for a root password. You can leave it blank.

6. Install the php-mysql connector so that php pages can access the database.

sudo apt install php-mysql

7. Restart Apache2 so all changes are in progress.

restart the sudo apache2 service

8. Test your server. On the Raspberry Pi itself, you should be able to navigate to http: // localhost and see a test page. From another computer on the same network, you should be able to get there by visiting http: //raspberrypi.local or http: // raspberrypi, provided your Raspberry Pi hostname is raspberrypi.

9. Build your website by putting html or PHP files in the / var / www / html phone book.

Changing the hostname of your server

By default, the hostname of your Raspberry Pi is “raspberrypi”. But it’s not only a boring address for a website, but it’s also problematic if you have more than one Pi on your network. Fortunately, it’s up to everyone to change the hostname to something else.

1. Enter the Raspberry Pi configuration tool by typing it into the terminal.

sudo raspi-config

Alternatively, you can launch the windowed version by going to Preferences-> Raspberry Pi Configuration from the Start menu, but why like to do it through the command line utility instead.

2. Select Network Options

3. Select the hostname

4. Press OK
to avoid a warning about using characters other than letters, numbers, or a hyphen (but only if the hyphen is in the middle of the name).

5. Enter your hostname and press OK.

6. Select Finish.

7. Select Yes when prompted to restart.

After restarting, your Raspberry Pi will have its new name.

How to set up FTP on your Pi web server

You won’t have a lot of web server if you don’t put certain web pages and media files in the / var / www / html case. And while you can do all of your web development on the Pi, most people will probably want to write the code on their main PC and then copy it. And one of the best ways to do that is through FTP. Here’s how.

1. Enable SSH on your Raspberry Pi if you haven’t already. You can do this by accessing the Interface Options-> SSH menu from rasp-config. Or, if you are on the desktop, you can go to Preferences-> Raspberry Pi Configuration and click on the interfaces tab.

2. Change the permissions for the / var / www / folder (and all underlying folders) so that you can write files to it. To do this, you must enter the following commands.

sudo chown pi / var / www / html

3. Use an FTP client on your PC and make sure you configure it to use SFTP protocol, not just FTP. If you are using Windows, we recommend Filezilla, which is the leading free FTP application.

The default username and password are “pi” and “raspberry” as they are for SSH.


Source link

Comments are closed.