- How to install Apache2 + PHP-FPM on Raspberry Pi
- 1. Add a «non-free» component to /etc/apt/sources.list, if not already there and add deb-src source
- 2. Update/upgrade and a good habit is to install the time synchronization and postfix
- 3. Install Apache, php-fpm and other packages according to your needs
- 4. Install all dependencies for libapache-mod-fastcgi
- 5. Install libapache-mod-fastcgi from source
- 6. Enable mods rewrite, actions etc. and restart apache
- 7. Install MySQL server and PHPMyAdmin if needed
- 8. Add group and user for your domain. First uid and gid is 10000 and home user (domain) directory is in /home/
- 9. Create structure logs and web directory
- 10. Add php-fpm.conf for your mydomain.com and edit mydomain.com.conf
- 11. Modify /etc/php5/fpm/pool.d/mydomain.com.conf
- 12. Create Apache virtual host
- 13. Create index.php file in your web home directory and insert phpinfo function into this file
- 14. Create vhost symlink from sites-available to sites-enabled directory and restart apache and php5-fpm
- 15. Enjoy!
- Как установить веб-сервер Apache на Raspberry Pi
- Установка Apache
- Установка PHP
- Выводы
- Tutorial — Install Apache, PHP and MySQL on a Raspberry Pi 2
- Before we start
- 1. Let’s start
- 2. Install Apache
- 3. Install PHP
- 4. Install MySQL
- Conclusion
- Sign up for more like this.
- Install NodeJS 18 on Ubuntu 22.04
- Install Home Assistant on Docker
- Install Portainer to manage Docker volumes, images and containers
How to install Apache2 + PHP-FPM on Raspberry Pi
We have prepared a simple tutorial on how to install the Apache web server with PHP-FPM in Raspbian. It takes a few minutes to prepare Raspberry Pi to launch your website.
1. Add a «non-free» component to /etc/apt/sources.list, if not already there and add deb-src source
root@raspberrypi:~# cat /etc/apt/sources.list deb http://mirrordirector.raspbian.org/raspbian/ wheezy main contrib non-free rpi root@raspberrypi:~# cat >> /etc/apt.sources.list deb-src http://mirrordirector.raspbian.org/raspbian/ wheezy main contrib non-free rpi ^C root@raspberrypi:~# cat /etc/apt/sources.list deb http://mirrordirector.raspbian.org/raspbian/ wheezy main contrib non-free rpi deb-src http://mirrordirector.raspbian.org/raspbian/ wheezy main contrib non-free rpi
2. Update/upgrade and a good habit is to install the time synchronization and postfix
root@raspberrypi:~# apt-get update && apt-get -y upgrade root@raspberrypi:~# apt-get install postfix ntp ntpdate
3. Install Apache, php-fpm and other packages according to your needs
root@raspberrypi:~# apt-get install apache2-mpm-worker php5-fpm php-apc
4. Install all dependencies for libapache-mod-fastcgi
root@raspberrypi:~# apt-get install debhelper dpatch libtool cdbs libapr1-dev apache2-threaded-dev
5. Install libapache-mod-fastcgi from source
root@raspberrypi:~# apt-get -b source libapache-mod-fastcgi root@raspberrypi:~# dpkg -i libapache2-mod-fastcgi*.deb
6. Enable mods rewrite, actions etc. and restart apache
root@raspberrypi:~# a2enmod rewrite ssl actions include root@raspberrypi:~# service apache2 restart
Advertisement:
7. Install MySQL server and PHPMyAdmin if needed
root@raspberrypi:~# apt-get install mysql-client mysql-server php5-mysql phpmyadmin
8. Add group and user for your domain. First uid and gid is 10000 and home user (domain) directory is in /home/
root@raspberrypi:~# addgroup --gid 10000 group001 root@raspberrypi:~# adduser --home /home/mydomain.com --shell /dev/null --uid 10000 --gid 10000 --disabled-password --disabled-login --gecos '' user001
9. Create structure logs and web directory
root@raspberrypi:~# mkdir /home/mydomain.com/logs # for Apache logs root@raspberrypi:~# mkdir /home/mydomain.com/logs/php/ # for PHP logs root@raspberrypi:~# mkdir /home/mydomain.com/www # for your web page root@raspberrypi:~# mkdir /home/mydomain.com/tmp # for temp root@raspberrypi:~# mkdir /home/mydomain.com/sessions # for sessions root@raspberrypi:~# chown -R user001:group001 /home/mydomain.com/
10. Add php-fpm.conf for your mydomain.com and edit mydomain.com.conf
root@raspberrypi:~# cp /etc/php5/fpm/pool.d/www.conf /etc/php5/fpm/pool.d/mydomain.com.conf root@raspberrypi:~# nano /etc/php5/fpm/pool.d/mydomain.com.conf
11. Modify /etc/php5/fpm/pool.d/mydomain.com.conf
; pool name ('www' here) [mydomain.com] . ; Unix user/group of processes user = user001 group = group001 . ; The address on which to accept FastCGI requests. listen = /var/run/php5-fpm-mydomain.com.sock . ; Set permissions for unix socket, if one is used. In Linux, read/write listen.owner = user001 listen.group = group001 listen.mode = 0666 . ; Default Value: nothing is defined by default except the values in php.ini . ; add php.ini admin values php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f noreply@mydomain.com php_flag[display_errors] = off php_admin_value[error_log] = /home/mydomain.com/logs/php/fpm-php.www.log php_admin_flag[log_errors] = on php_admin_value[upload_tmp_dir] = /home/mydomain.com/tmp php_admin_value[session.save_path] = /home/mydomain.com/sessions php_admin_value[open_basedir] = /home/mydomain.com/www:/home/mydomain.com/tmp:/home/mydomain.com/sessions php_admin_value[mail.log] = /home/mydomain.com/logs/mail.log php_admin_value[memory_limit] = 64M php_admin_value[post_max_size] = 18M php_admin_value[max_execution_time] = 60 php_admin_value[allow_url_fopen] = Off php_admin_value[upload_max_filesize] = 18M php_admin_value[date.timezone] = Europe/Prague
12. Create Apache virtual host
root@raspberrypi:~# nano /etc/apache2/sites-available/mydomain.com.conf
# eliminate wwwServerName www.mydomain.com Redirect 301 / http://mydomain.com/ ServerAdmin iam@mydomain.com ServerName mydomain.com DocumentRoot /home/mydomain.com/www Options -Indexes -FollowSymLinks -MultiViews AllowOverride All Order allow,deny allow from all # eliminate log warning about ico Redirect 404 /favicon.icoErrorDocument 404 "No favicon" # *.php3-5 file extension (enable different extensions in /etc/php5/fpm/pool.d/mydomain.com.conf first)SetHandler application/x-httpd-php # FastCGI Action application/x-httpd-php /php5-fcgi Alias /php5-fcgi /usr/lib/cgi-bin/mydomain.com FastCgiExternalServer /usr/lib/cgi-bin/mydomain.com -socket /var/run/php5-fpm-mydomain.com.sock -pass-header Authorization # apache logs ErrorLog /home/mydomain.com/logs/error.log LogLevel warn CustomLog /home/mydomain.com/logs/access.log combined
13. Create index.php file in your web home directory and insert phpinfo function into this file
root@raspberrypi:~# nano /home/mydomain.com/www/index.php
14. Create vhost symlink from sites-available to sites-enabled directory and restart apache and php5-fpm
root@raspberrypi:~# ln -s /etc/apache2/sites-available/mydomain.com.conf /etc/apache2/sites-enabled/ root@raspberrypi:~# service apache2 restart && service php5-fpm restart [ ok ] Restarting web server: apache2 . waiting . [ ok ] Restarting PHP5 FastCGI Process Manager: php5-fpm.
15. Enjoy!
Как установить веб-сервер Apache на Raspberry Pi
HTTP-сервер Apache — один из самых популярных веб-серверов в мире. Это кроссплатформенный HTTP-сервер с открытым исходным кодом, который обслуживает большую часть веб-сайтов в Интернете. Apache предоставляет множество мощных функций, которые можно расширить с помощью дополнительных модулей.
В этом руководстве мы объясним, как установить веб-сервер Apache на Raspberry Pi. Мы предполагаем, что на Raspberry Pi установлен Raspbian .
Установка Apache
Apache доступен в репозиториях Raspbian по умолчанию, и установка довольно проста.
Сначала обновите индекс пакета, а затем установите пакет apache2 , выполнив следующие команды:
sudo apt update
sudo apt install apache2
Вот и все, на данный момент у вас установлен веб-сервер Apache на Raspberry Pi.
Чтобы убедиться, что все работает http://PI_IP , откройте браузер, введите свой IP-адрес Raspberry Pi http://PI_IP и вы увидите страницу приветствия Apache по умолчанию, как показано на изображении ниже:
На странице представлена основная информация о файлах конфигурации Apache, вспомогательных скриптах и расположении каталогов.
Эта веб-страница Apache по умолчанию называется index.html и хранится в каталоге /var/www/html . Если вы хотите изменить эту страницу, вам необходимо отредактировать файл как пользователь sudo . Вы также можете удалить файл и добавить свои собственные HTML-файлы.
Файлы журнала Apache access.log и error.log находятся в каталоге /var/log/apache . Если вы столкнетесь с какой-либо проблемой, файлы журнала должны сообщить вам, что пошло не так.
Установка PHP
Если вы хотите обслуживать динамические файлы PHP на Raspberry Pi, вам необходимо установить модуль PHP и PHP Apache:
sudo apt install php libapache2-mod-php
После установки пакетов для включения модуля PHP перезапустите службу Apache:
sudo systemctl restart apache2
Чтобы проверить, правильно ли настроен ваш веб-сервер Apache для обработки PHP, создайте новый файл с именем info.php внутри каталога /var/www/html со следующим кодом:
Сохраните файл, откройте нужный браузер и перейдите по http://PI_IP/info.php . Эта страница покажет информацию о вашей конфигурации PHP.
Выводы
Вы успешно установили Apache и PHP на свою плату Raspberry Pi. Теперь вы можете начать использовать Apache в качестве веб-сервера или прокси-сервера.
Если у вас есть какие-либо вопросы или отзывы, не стесняйтесь оставлять комментарии.
Tutorial — Install Apache, PHP and MySQL on a Raspberry Pi 2
I’ve been running LAMP setups on Raspberry Pi’s for years, so am excited to use the little pocket-sized powerhouse that is the Raspberry Pi 2 as a web server. This is the first in a series that will see a quad core Raspberry Pi 2 run this WordPress site.
Before we start
There are some prerequisites; I assume you know your way around terminal, and know how to SSH onto your Raspberry Pi 2. These instructions will work directly on the Pi itself. I also assume you know the IP address of your Raspberry Pi.
1. Let’s start
First, connect to your Raspberry Pi 2. Skip this step if you’re working directly on your Raspi:
Replace ‘raspberrypi’ with the IP or hostname of your raspberry Pi. You should now be logged into your Raspberry Pi 2, and will see something like this:
There’s likely to be updates to install, so we’ll go ahead and do these now before we start installing anything:
sudo apt-get update && sudo apt-get upgrade
This used to take a little time on the old ones, but the new quad-core makes light work of the updates. You’ll be prompted to choose ‘Y’ or ‘n’, so just keep hitting ‘y’ until the updates are installed. Providing the updates went in OK, you’re ready to install Apache 2.4 and PHP 5.4
2. Install Apache
Next run the following command. This will install Apache 2.4, which is the web server that responds to http (and https if you like) requests:
sudo apt-get install apache2 apache2-utils
Technically, this is all we need to do to run a very basic web server from our Raspberry Pi. Give it a go, pop the IP address of your Raspberry Pi in your web browser. You should see something like this:
This is all fine and dandy, but our aim is to install WordPress, so we’re going to need PHP. Follow the next steps to do this.
3. Install PHP
This command will install the PHP 5 and the PHP libraries you’ll need for WordPress:
sudo apt-get install libapache2-mod-php5 php5 php-pear php5-xcache php5-mysql php5-curl php5-gd
That’s it, PHP 5 is now installed. We can test it to make sure it’s working by creating a index.php file and calling PHP Info. Change the directory to the default document root:
The permissions aren’t set correctly just yet, so for the time being, we’ll create a index file as sudo:
sudo echo "" | sudo tee index.php
Now visit index.php in your web browser, you will see PHP Info. You should see the following:
4. Install MySQL
MySQL is the database server which will hold our data for our WordPress installation. Installing MySQL is very straight forward. Run the following command:
sudo apt-get install mysql-server
Once the installation begins, you will be asked to provide a master password for your MySQL installation. Ensure you choose a good secure password, and it’s a good idea to give MySQL a different password to the one you use to access your Raspberry Pi.
[![Install MySQL Server](me/content/images/2015/08/Screen-Shot-2015-09-09-at-21.30.05.png?ssl=1)Finish off by installing MySQL client, which will allow us to create a user for our WordPress installation in the next tutorial:
sudo apt-get install mysql-client
Conclusion
So, we’ve installed Apache and PHP, along with other packages we need to run WordPress. We’ve also installed our database server MySQL, so next we’ll configure the permissions and install WordPress. Come back soon for the next tutorial.
Sign up for more like this.
Install NodeJS 18 on Ubuntu 22.04
Learn how to install NodeJS 18 on Ubuntu 22.04 in this quick tutorial.
Install Home Assistant on Docker
Whether you’re using Docker on the CLI or through Portainer, this tutorial will guide you through the installation process so you can manage your smart home devices yourself.
Install Portainer to manage Docker volumes, images and containers
Learn how to install and set up Portainer to manage your Docker containers, images and volumes in this tutorial.