Alpine linux php fpm

How to install PHP 7 fpm on Alpine Linux

Step 1: Install the Nginx web server

Type the following apk command to install nginx server on an Alpine Linux:
# apk update && apk upgrade
# apk add nginx

Step 2: Install PHP 7 fpm on Alpine Linux

Type the following apk command to install the PHP 7.x language runtime engine:
# apk add php7 php7-fpm php7-opcache

Fig.01: Installing PHP 7

Step 3: Install the PHP 7.x modules

Add popular PHP modules such as MySQL, GD and others:
# apk add php7-gd php7-mysqli php7-zlib php7-curl

Fig.02: Installing PHP 7 modules

Or use the grep command along with the apk command:
# apk search php7 | grep -i gd

Step 4: Start the php-fpm7 server

Make sure the nginx and php-fpm7 starts when system reboots:
# rc-update add nginx default
* service nginx added to runlevel default
# rc-update add php-fpm7 default
* service php-fpm7 added to runlevel default

Command to restart nginx and PHP7-fpm server

# rc-service nginx restart
# rc-service php-fpm7 restart
Sample outputs:

Fig.03: Starting/Stopping PHP and Nginx services

Command to stop nginx and PHP7-fpm server

# rc-service nginx stop
# rc-service php-fpm7 stop

Command to start nginx and PHP7-fpm server

# rc-service nginx start
# rc-service php-fpm7 start

Источник

Nginx with PHP

Nginx (engine x) is an HTTP and reverse proxy server, a mail proxy server, and a generic TCP/UDP proxy server

Contents

Installation

Nginx package is available in the Alpine Linux repositories. To install it run:

apk update apk add nginx

Creating new user and group ‘www’ for nginx

adduser -D -g ‘www’ www

Create a directory for html files

mkdir /www chown -R www:www /var/lib/nginx chown -R www:www /www

Configuration

You may want to make backup of original nginx.conf file before writting your own

mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf.orig

Configuring Nginx to listen to port 80 and process .html or .htm files

Sample page

Controlling nginx

Start Nginx

After the installation Nginx is not running. To start Nginx, use start.

rc-service nginx start

You will get a feedback about the status.

Test configuration

When you’ve made any changes to your nginx configuration files, you should check it for errors before restarting/reloading nginx.
This will check for any duplicate configuration, syntax errors etc. To do this, run:

You will get a feedback if it failed or not. If everything is fine, you’ll see the following and can then move ahead to reload the nginx server.

Reload and Restart Nginx

Changes made in the configuration file will not be applied until the command to reload configuration is sent to nginx or it is restarted.
Reloading will do a «hot reload» of the configuration without server downtime. It will start the new worker processes with a new configuration and gracefully shutdown the old worker processes. If you have pending requests, then these will be handled by the old worker processes before it dies, so it’s an extremely graceful way to reload configs. If you want to reload the web server, use reload.

rc-service nginx reload

If you want to restart the web server, use restart.

rc-service nginx restart

Stop Nginx

If you want to stop the web server, use stop.

rc-service nginx stop

Runlevel

Normally you want to start the web server when the system is launching. This is done by adding Nginx to the needed runlevel.

rc-update add nginx default

Now Nginx should start automatically when you boot your machine next time. To test that run:

To make sure that Nginx is started run:

ps aux | grep nginx

You should get something like this:

Testing Nginx

This section is assuming that nginx is running and sample html page «/www/index.html» is created. Launch a web browser and point it to your web server. You should get:

Troubleshooting

If Nginx is not started check Nginx log file

Make sure that configuration file does not contain errors. Edit the file in case there are any errors.

nginx -t vi /etc/nginx/nginx.conf

Nginx with PHP

PHP5 Installation

PHP packages is available in the Alpine Linux repositories. To install php5 with modules run:

apk add php5-fpm php5-mcrypt php5-soap php5-openssl php5-gmp php5-pdo_odbc php5-json php5-dom php5-pdo php5-zip php5-mysql php5-mysqli php5-sqlite3 php5-apcu php5-pdo_pgsql php5-bcmath php5-gd php5-xcache php5-odbc php5-pdo_mysql php5-pdo_sqlite php5-gettext php5-xmlreader php5-xmlrpc php5-bz2 php5-memcache php5-mssql php5-iconv php5-pdo_dblib php5-curl php5-ctype

Читайте также:  Hex редактор для linux

Perhaps you do not need all these PHP modules. Install modules according to your needs.

Configuration of PHP5

Defining ENV variables which will be used in configuration. You can do this e.g. in /etc/profile.d/php5.sh.

PHP_FPM_USER=»www» PHP_FPM_GROUP=»www» PHP_FPM_LISTEN_MODE=»0660″ PHP_MEMORY_LIMIT=»512M» PHP_MAX_UPLOAD=»50M» PHP_MAX_FILE_UPLOAD=»200″ PHP_MAX_POST=»100M» PHP_DISPLAY_ERRORS=»On» PHP_DISPLAY_STARTUP_ERRORS=»On» PHP_ERROR_REPORTING=»E_COMPILE_ERROR\|E_RECOVERABLE_ERROR\|E_ERROR\|E_CORE_ERROR» PHP_CGI_FIX_PATHINFO=0

Modify variables according to your needs.

Modifying configuration file php-fpm.conf

sed -i «s|;listen.owner\s*=\s*nobody|listen.owner = $|g» /etc/php5/php-fpm.conf sed -i «s|;listen.group\s*=\s*nobody|listen.group = $|g» /etc/php5/php-fpm.conf sed -i «s|;listen.mode\s*=\s*0660|listen.mode = $|g» /etc/php5/php-fpm.conf sed -i «s|user\s*=\s*nobody|user = $|g» /etc/php5/php-fpm.conf sed -i «s|group\s*=\s*nobody|group = $|g» /etc/php5/php-fpm.conf sed -i «s|;log_level\s*=\s*notice|log_level = notice|g» /etc/php5/php-fpm.conf #uncommenting line

Modifying configuration file php.ini

sed -i «s|display_errors\s*=\s*Off|display_errors = $|i» /etc/php5/php.ini sed -i «s|display_startup_errors\s*=\s*Off|display_startup_errors = $|i» /etc/php5/php.ini sed -i «s|error_reporting\s*=\s*E_ALL &

E_STRICT|error_reporting = $|i» /etc/php5/php.ini sed -i «s|;*memory_limit =.*|memory_limit = $|i» /etc/php5/php.ini sed -i «s|;*upload_max_filesize =.*|upload_max_filesize = $|i» /etc/php5/php.ini sed -i «s|;*max_file_uploads =.*|max_file_uploads = $|i» /etc/php5/php.ini sed -i «s|;*post_max_size =.*|post_max_size = $|i» /etc/php5/php.ini sed -i «s|;*cgi.fix_pathinfo=.*|cgi.fix_pathinfo= $|i» /etc/php5/php.ini

To add PHP support to Nginx we should modify Nginx configuration file:

In our configuration we have line: «fastcgi_pass 127.0.0.1:9000»
It should be corresponing to the line «listen = 127.0.0.1:9000» in PHP configuration file /etc/php5/php-fpm.conf

Timezone

For configuring Timezone you may use tzdata package which can be installed by running:

TIMEZONE=»Europe/Helsinki» cp /usr/share/zoneinfo/$ /etc/localtime echo «$» > /etc/timezone sed -i «s|;*date.timezone =.*|date.timezone = $|i» /etc/php5/php.ini

Sample PHP page

Starting Nginx with PHP5

Nginx should be restarted because we have changed it’s configuration. Restart it by running:

rc-service nginx restart

After the installation PHP is not running. Start it by running:

rc-service php-fpm start

Runlevel

Normally you want to start the web server when the system is launching. This is done by adding Nginx and PHP to the needed runlevel.

rc-update add nginx default rc-update add php-fpm default

Now they should start automatically when you boot your machine next time. To test that run:

To make sure that Nginx and PHP are started run command:

ps aux | grep ‘nginx\|php-fpm’

You should get something like this:

Testing Nginx with PHP

This section is assuming that nginx is running and sample html page «/www/phpinfo.php» is created. Launch a web browser and point it to

where X.X.X.X is IP address of your web server

If everything was set up correctly, you should see information about your web server.

Troubleshooting

If PHP is not started check php-fpm log file

Make sure that configuration files do not contain errors

vi /etc/php5/php-fpm.conf vi /etc/php5/php.ini

PHP7 Installation

PHP packages is available in the Alpine Linux repositories. To install php7 with modules run:

apk add php7-fpm php7-mcrypt php7-soap php7-openssl php7-gmp php7-pdo_odbc php7-json php7-dom php7-pdo php7-zip php7-mysqli php7-sqlite3 php7-apcu php7-pdo_pgsql php7-bcmath php7-gd php7-odbc php7-pdo_mysql php7-pdo_sqlite php7-gettext php7-xmlreader php7-xmlrpc php7-bz2 php7-iconv php7-pdo_dblib php7-curl php7-ctype

Perhaps you do not need all these PHP modules. Install modules according to your needs.

Configuration of PHP7

Defining ENV variables which will be used in configuration. You can do this e.g. in /etc/profile.d/php7.sh.

PHP_FPM_USER=»www» PHP_FPM_GROUP=»www» PHP_FPM_LISTEN_MODE=»0660″ PHP_MEMORY_LIMIT=»512M» PHP_MAX_UPLOAD=»50M» PHP_MAX_FILE_UPLOAD=»200″ PHP_MAX_POST=»100M» PHP_DISPLAY_ERRORS=»On» PHP_DISPLAY_STARTUP_ERRORS=»On» PHP_ERROR_REPORTING=»E_COMPILE_ERROR\|E_RECOVERABLE_ERROR\|E_ERROR\|E_CORE_ERROR» PHP_CGI_FIX_PATHINFO=0

Modify variables according to your needs.

Modifying configuration file www.conf

sed -i «s|;listen.owner\s*=\s*nobody|listen.owner = $|g» /etc/php7/php-fpm.d/www.conf sed -i «s|;listen.group\s*=\s*nobody|listen.group = $|g» /etc/php7/php-fpm.d/www.conf sed -i «s|;listen.mode\s*=\s*0660|listen.mode = $|g» /etc/php7/php-fpm.d/www.conf sed -i «s|user\s*=\s*nobody|user = $|g» /etc/php7/php-fpm.d/www.conf sed -i «s|group\s*=\s*nobody|group = $|g» /etc/php7/php-fpm.d/www.conf sed -i «s|;log_level\s*=\s*notice|log_level = notice|g» /etc/php7/php-fpm.d/www.conf #uncommenting line

Modifying configuration file php.ini

sed -i «s|display_errors\s*=\s*Off|display_errors = $|i» /etc/php7/php.ini sed -i «s|display_startup_errors\s*=\s*Off|display_startup_errors = $|i» /etc/php7/php.ini sed -i «s|error_reporting\s*=\s*E_ALL &

E_STRICT|error_reporting = $|i» /etc/php7/php.ini sed -i «s|;*memory_limit =.*|memory_limit = $|i» /etc/php7/php.ini sed -i «s|;*upload_max_filesize =.*|upload_max_filesize = $|i» /etc/php7/php.ini sed -i «s|;*max_file_uploads =.*|max_file_uploads = $|i» /etc/php7/php.ini sed -i «s|;*post_max_size =.*|post_max_size = $|i» /etc/php7/php.ini sed -i «s|;*cgi.fix_pathinfo=.*|cgi.fix_pathinfo= $|i» /etc/php7/php.ini

To add PHP support to Nginx we should modify Nginx configuration file:

In our configuration we have line: «fastcgi_pass 127.0.0.1:9000»
It should be corresponing to the line «listen = 127.0.0.1:9000» in PHP configuration file /etc/php7/php-fpm.d/www.conf

Timezone

For configuring Timezone you may use tzdata package which can be installed by running:

TIMEZONE=»Europe/Helsinki» cp /usr/share/zoneinfo/$ /etc/localtime echo «$» > /etc/timezone sed -i «s|;*date.timezone =.*|date.timezone = $|i» /etc/php7/php.ini

Sample PHP page

Starting Nginx with PHP7

Nginx should be restarted because we have changed it’s configuration. Restart it by running:

rc-service nginx restart

After the installation PHP is not running. Start it by running:

rc-service php-fpm7 start

Runlevel

Normally you want to start the web server when the system is launching. This is done by adding Nginx and PHP to the needed runlevel.

rc-update add nginx default rc-update add php-fpm7 default

Now they should start automatically when you boot your machine next time. To test that run:

To make sure that Nginx and PHP are started run command:

ps aux | grep ‘nginx\|php-fpm’

You should get something like this:

Testing Nginx with PHP

This section is assuming that nginx is running and sample html page «/www/phpinfo.php» is created. Launch a web browser and point it to

where X.X.X.X is IP address of your web server

If everything was set up correctly, you should see information about your web server.

Troubleshooting

If PHP is not started check php-fpm log file

Make sure that configuration files do not contain errors

Источник

Alpine newbie developer: full stack web

Contents

Documents series

Previous required What’s next to read
Alpine newbie developer, Alpine newbie desktops must be completed! Alpine newbie developer: work from desktop on remote servers, Alpine_production_deploy, Alpine newbie developer: full stack backend

gitea is a management interface.. this guide will install locally for local management of git, for better installation please refers to Alpine_newbie_developer: gitea wiki page.

Читайте также:  Windows нет корейского языка

Git is the version control system (VCS) software behind gitea perse, so must be installed first. But repositories on server are not same as in clients.. server repositories are bare repositories.

git and gitea Installation

This guide does work either if are or not in main or edge the gitea package:, take note, do not install any more from edge.. so in fact all gitea dependencies must be listed and installed before gitea and edge brand are activated, so the following process will guide and show you how to do that; first gain root privileges and then:

  1. added and update normal repositories
  2. install direct dependences: git, gnupg, make, bash, coreutils and from normal stable repositories
  3. install indirect dependences: manpages, grep, lsof, less, curl, binutils, attr, dialog
  4. alternate edge repositories
  5. install gitea from edge repository
  6. restore normal repository
  7. Start gitea init script!
  8. Make enabled the init script!

Take in consideration that the user gitea was configure during installation.

Configurations

Gitea runs as gitea user, and www-data group, so are compatible with any web deploy in system webservers packages of alpine repositories, but not with any other external installation if does not are same as.

Gitea has two configuration files, the system defaults at /var/lib/gitea/conf/app.ini and modifiable package defaults, at /etc/gitea/app.ini . Original files are in /usr/share/webapps/gitea and are defaults non-modifiable. For specific and better configurations visit Alpine_newbie_developer: gitea wiki page.

Gitea for data database backend for storing configurations.. SQLite are the default. But for others database backends alpine packages of MySQL/MariaDB or PostgreSQL are like normal tarball of each one, admins must know what they want.. there’s no automatic window-like installation here. So first go to MariaDB or PostgreSQL wiki pages and with a user database configure in the /etc/gitea/app.ini and modify the DB_TYPE change from sqlite to postgres or mysql, NAME as the database access where gitea will store the data, USER as the user that will access the database, PASSWORD with the password of the user to access to the database defined. HOST must be with «localhost» value since this wiki assumes local installation. For specific and better configurations visit Alpine_newbie_developer: gitea wiki page.

Gitea can be customized: just take same path from /usr/share/webapps/gitea/ and put in same manner at /var/lib/gitea/custom/ place, by example to customize default landing page, just take a copy of the /usr/share/webapps/gitea/templates/home.tmpl and put modified one as /var/lib/gitea/custom/templates/home.tmpl as well.

Post installation

After install and initialized the daemon, you now can just go to http://localhost:3000 and start the post-installation process, if you dont want to change any configuration.. if not check next sections. A starting page will be show.

The post install page, only are show when try to use the system, away of the starting page, by example if browse the repositories or try to login. You must not forget to setup that installation.

Administrator account must be configured before push «install gitea», the button at the end of the post-configuration page when you first visit the installation. Provide and username for admin user, take note «admin» are a reserved word so choose another name. after provide passowrd you will continue the installation.

Geany IDE

Sublime text

Documents series

Previous required What’s next to read
Alpine newbie developer, Alpine newbie desktops must be completed! Alpine newbie developer: work from desktop on remote servers, Alpine_production_deploy, Alpine newbie developer: full stack backend

Alpine is minimalist so not all PHP packages are needed in most cases, in development environment we used most, but for PHP at production LAMP please take a look at the Production LAMP system: Lighttpd + PHP + MySQL wiki page.

PHP Installation

Since version v3.5, PHP 7 is available along with PHP 5.6 coexisting together, until version v3.9 where the latter was removed. So for Alpine 3.5+m we will assume PHP7, if you need PHP5.6 still could use it, that will be cover in the special Production LAMP system: Lighttpd + PHP5 + MySQL wiki page for older Alpine systems and some PHP specific software.

  1. Install core packages of PHP
  2. Install databases access packages of PHP, take into consideration the previous ODBC configurations
  3. Install extra packages of PHP

PHP Global Configuration

  1. Use fix.pathinfo
  2. Set safe mode to be off
  3. Don’t expose PHP code if something fails
  4. Set memory limit for execution to 256Mb (most servers are minimal of 1Gb of RAM)
  5. So then set upload size to 56Mb as maximum.
  6. Set then POST max size to 128Mb based on the upload max size limit.
  7. Turn on the URL open method
  8. Set default charset to UTF-8 for more compatibility
  9. Increase the execution time and the input time for.

PHP-FPM Configuration

The PHP-FPM defined a master process with some pool of process for each service resuests, by default there’s only one pool of processes, the www pool process.

  1. Create directory for php socket and pid files, MUST BE EQUAL to openrc init script defined!
  2. Set into configuration file the socket path, MUST BE EQUAL to openrc init script defined!
  3. Set into configuration file the pid file path, MUST BE EQUAL to openrc nit script defined!
  4. enable the mod_alias at the config file, due need of a specific path for cgi files into security
  5. be sure and disable the fastcgi-php module by cgi only
  6. and then enable the fastcgi-php-fpm specific module then
  7. write a much much better approach of the php handler in the local server using the socket
  8. configure the php to use also the socket too for direct connection locally
  9. restart the service to see changes at the browser
Читайте также:  Windows check if application is 64 bit

For testing open a browser and go to http:// /info.php and you will see only the minimal info due in production there’s no need for too much information to crackers. The «webserveripaddres» are the ip address of your setup/server machine.

After that, all the files with php will be proceses faster than used a host based, also under the /var/www/localhost/cgi-bin directory will be showed as http://localhost/cgi-bin/ path.

Documents series

Previous required What’s next to read
Alpine newbie developer, Alpine newbie desktops must be completed! Alpine newbie developer: work from desktop on remote servers, Alpine_production_deploy, Alpine newbie developer: full stack backend

NodeJS and NPM

Installation

Documents series

Previous required What’s next to read
Alpine newbie developer, Alpine newbie desktops must be completed! Alpine newbie developer: work from desktop on remote servers, Alpine_production_deploy, Alpine newbie developer: full stack backend

Databases

Due web developer always uses Mysql, here only will cover Mysql/MariaDB and ODBC, for PostgreSQL please take a look to the Alpine newbie developer: full stack backend wiki page.

MySQL

Alpine Linux has dummy counterparts packages for those that are not close to that change from mysql to mariadb naming packages.

Installation

Take in consideration that the user mysql was created during instalation of packages, in the initialization section two users will be created in database init: root and mysql , and in that point only if are in their respective system accounts, will be able to connect to the database service.

That will install the most used ones.. mariadb-cient and mariadb-server with respective documents and manpages for developing, rest of packages are brief described in the MariaDB Alpine wiki page.

Initialization

The datadir are located to /var/lib/mysql must be owned by the mysql user and group. You can modify this behavior but must edit the service file at /etc/init.d directory. Also, you need to set datadir= under section [mysqld] at the config file.

  1. Initialize the main mysql database, and the data dir as standardized to /var/lib/mysql by the rc script
  2. Then initialize the service, root account and socket connection are enabled without password at this point
  3. Setup the root account by asignes a proper password, this are purely paranoid. due next step already do that!
  4. Setup and init the installation by running the mysql_secure_installation
  5. Setup permissions for manage others users and databases
  6. Run the mysql_secure_installation script and answer the questions (see section below)
  1. Enter current password for root (enter for none): must be provided due we already set previously. correct respond are OK, successfully used password, moving on.
  2. Switch to unix_socket authentication [Y/n] this are not the case and must be disabled, so answer NO, and response will be . skipping.
  3. Change the root password? [Y/n] Just press «n» only if you provided a good password, otherwise just change it!
  4. Remove anonymous users? [Y/n] In any case, production system must remove it, so answer Y and proper respond mus be . Success! .
  5. Disallow root login remotely? [Y/n] For sure answer Y and proper respond mus be . Success! .
  6. Remove test database and access to it? [Y/n] Should be removed, so answer Y and proper respond mus be . Success! .
  7. Reload privilege tables now? [Y/n] Answer Y and proper respond mus be . Success! .

After aswered all the questions.. restart the service with rc-service mariadb restart

Configuration

Newer system Alpine packages can set in independent files in any case those commands always works and where are not apply just will ignore the output, for more info about that watch the MariaDB Configuration files section of the MariaDB wiki page.

  • On older Alpine system must set config files for MAX ALLOWED PACKETS to minimun proper amount
  • Set default charset to UTF8MB4
  • Added the service to start process but not at boot process due needs networking started.
  • Restart the service to apply changes.

Upgrading

On upgrade cases: If are unable to run any mysql command after an upgrade, it’s because MySQL cannot start try run MySQL in safemode with mysqld_safe —datadir=/var/lib/mysql/ command and then run the mysql_upgrade -u root -p script. For more information watch the MariaDB upgrading section of the MariaDB wiki page.

  1. keep the old database (mysql sheme) structure of the engine daemon, currently this are not more the case, today this not make sense anymore
  2. upgrade the MariaDB/MySQL packages, of course with must be done if the upgrade process to mayor alpine version does not!
  3. run the mysql_upgrade -u root -p script, providing the password or root, (from the new package version) against the old still-running database (mysql sheme). This will produce some error messages; however, the upgrade will succeed.
  4. Restart the service

If are unable to run mysql_upgrade because MySQL cannot start try run MySQL in safemode with mysqld_safe —datadir=/var/lib/mysql/ command and then run the mysql_upgrade -u root -p script.

Источник

Оцените статью