the Internet

How to configure an Apache web server on Raspberry Pi

Usually web developers use local web servers, on these servers web page programmers can view their projects in order to see the result that their projects would have for the user. For this purpose, we can use ARM cards ( Raspberry PI, Orange Pi, Pirock etc.) These ARM cards have endless uses, ranging from a small PC to carry anywhere, to building our own network attached storage (NAS) server.

To carry out our web server project, in this case we will use the ARM Raspberry Pi 3 card. This device is an ARM architecture card, that is to say a very small computer. The main purpose of the Raspberry Pi was to stimulate computer science education. In RedesZone we have a full report with the history of Raspberry Pi:

The main utility of this web server is that developers can locally test their web projects developed in HTML, CSS and PHP, and thus have an overview of the status of their projects without having to go into production.

Before we start to mount our web server on a Raspberry Pi, we need to follow some small instructions to start mounting our web server:

  • Minimum knowledge of Linux and its terminal
  • Our ARM card must have a Linux system installed on its SD card (Raspbian, Ubuntu Mate, Linux Mint etc.)
  • LAN connection and Internet connection on our Raspberry

Steps for preparing our Raspberry Pi

First of all, we will start by preparing our Raspberry Pi to carry out the development of our web server. Therefore, we need to update all the drivers and packages for our Linux operating system. To do this, we will open a terminal window and run the following commands:

sudo apt update
sudo apt upgrade -y

The commands may vary depending on the distribution we use, the previous commands will work in distributions derived from Debian, for other distributions we will only have to locate which command is to manage the packages. The packages we will use will be Apache to create the server, PHP for our web projects and MySQL for the management of our databases. As an additional package, we will use an FTP server to establish connections to our web server and manage files locally or remotely.

Once the execution of both commands is complete, we will prepare our network interface to assign a local fixed IP address to our ARM card, although we can also use static DHCP from our router. To do this, you must modify the "interfaces" file in the path  / etc / network / interfaces . And at the end of the file we will put the following:

auto eth0
iface eth0 inet static
address 192.168.1.33
netmask 255.255.255.0
gateway 192.168.1.1

It is important to mention that we have to put an IP in the 192.168.1.0/24 subnet which is not in use, we can choose ranges between 2-254, as long as the main router uses the first available IP.

As we are using the private IP type C 192.168.XX with the mask 255.255.255.0, we can also use the private IP type A 10.XXX with the mask 255.0.0.0. It all depends on the range of IP addresses we have in our network.

To modify the file, we will run:

sudo nano /etc/network/interfaces

The command dwarf will provide us with a small editor in our terminal, to be able to modify the above mentioned file. Instead of using nano, we can use any terminal editor like vi, vim or emac .

Installation of Apache, PHP and MySQL

We will start by installing the first package and start with Apache, which will act as the server. For this we need to open a terminal and run the following command:

sudo apt install apache2 -y

Once the installation of our Apache server is complete, we can check if it is running. To do this, we need to open a browser, and in the address bar go to the address http://192.168.1.33 (in my case) or http: // localhost if we are on the Raspberry Pi itself with graphical user interface. Where the next page will appear.

The next step is to install the PHP server. We will need to open a terminal window again and we will need to run the following:

sudo apt install php5 libapache2-mod-php5 –y

Once the installation process is complete, we will restart the server with the following command for the changes to take effect:

sudo service apache2 restart

To do away with the technologies and our web server seems complete, we need to install a database administrator, in our case we will use MySQL. To perform the installation of MySQL. We will run the following command:

sudo apt-get install mysql-server mysql-client php5-mysql

Once everything has been properly installed, we can directly run the MySQL database as follows:

sudo service mysql start

To check if the databases are already running, type this in the terminal:

mysql -u root –p[code]

Finalmente, para manejar nuestras bases de datos de una forma más eficiente y cómoda usaremos phpmyadmin. Para su instalación ejecutaremos el siguiente comando:

[code]sudo apt install -y phpmyadmin

Once the installation is complete, to access the interface, simply open the browser and enter the following address http://192.168.1.33/phpmyadmin or http: // localhost / phpmyadmin. With our phpmyadmin control panel, it will be much easier to manage all our databases because we will manage them in a more visual way.

Installing the FTP server on Raspberry Pi

In this step, we will install an FTP server to be able to send files from any computer to our Raspberry Pi, and from the Raspberry Pi itself to a computer where our projects may need them. It is a straightforward process. First, we are going to change the permissions of the / var / www directory so that any user has permissions and can view the contents.

sudo chown -R pi /var/www

The next command to run would be :

sudo apt install vsftpd

Once the whole process is finished, you have to edit the vsftpd.config file and for that you just have to write:

sudo nano /etc/vsftpd.conf

When the file editor opens, we will need to modify the following lines:

  • anonymous_enable = YES becomes  anonymous_enable = NO
  • uncomment  local_enable = YES
  • uncomment  write_enable = YES

At this point you have to go to the end of the file and add " force_dot_files = YES "

Once you have completed the previous steps, press ctrl + X and type a ' y ' , then press Enter to save the changes to the file. The next step is to restart the FTP service with the following command:

sudo service vsftpd restart

Finally, with this we will have everything ready and our web server complete and functional. And we can have all of our web projects hosted on our Raspberry Pi.

Similar items

Leave your comment

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

Button back to top