Configure php with pear

Configure php with pear

PHP is a popular general-purpose scripting language that is especially suited to web development.

PHP Versions¶

Opalstack supports PHP versions 8.1, 8.0, 7.4, 7.3, and 5.6.

Changing PHP Versions for Web Applications¶

The default PHP version for web applications is version 7.4.

To change the PHP version for your application:

  1. Click on Applications in the dashboard sidebar.
  2. Click the Edit icon (a pencil) for your application in the Application list in the lower half of the page. A form will appear.
  3. Select the desired PHP version on the form. If no version is selected then then application is the default value.
  4. Click the green «Update Application» button to save your changes.

Using Different PHP Versions at the Command Line¶

The default PHP version for the command line — that is, what you get when you run » php » — is version 7.3.

To run other PHP versions, the commands are:

Читайте также:  Raspberry pi java oracle

Configuring PHP Settings for Web Applications¶

Settings for PHP applications installed via the Opalstack dashboard can be configured as follows:

  1. Create a file named .user.ini in your application directory. Note the leading dot . character at the beginning of the filename. This dot is required.
  2. Edit your .user.ini file to specify your PHP settings. Each setting should be on an individual line in the format directive = value . You can use any PHP directives that are listed as PHP_INI_ALL or PHP_INI_PERDIR in the «Changeable» column in the official list of INI directives.
  3. Save your .user.ini file. Your changes are effective immediately.

Example: setting the maximum file size for uploads¶

The maximum file size for uploads in our default PHP configuration is 64MB. If your PHP application needs to be able to accept larger uploads, for example 128MB, then create a .user.ini file as described above and include the following lines:

post_max_size = 128M upload_max_filesize = 128M 

Tuning PHP-FPM Settings for Performance¶

Most PHP-FPM applications installed via your Opalstack dashboard include two options for performance tuning:

  • FPM Max Child Threads: this is the maximum number of processes that will run to serve your site.
  • FPM Max Requests: this is the number of requests that each process will serve before restarting.

Our general recommendations for these settings are:

  • If your site is struggling due to heavy traffic, then use a higher value for FPM Max Child Threads. Note that this may result in higher memory usage due to a higher number of simultaneous requests to your site.
  • If your site is using too much memory due to a memory leak then use a lower value for FPM Max Requests. Note that this may result in lower performance due to the overhead of starting new processes to service more requests.

In practice, effective performance tuning may require adjustments to both of these parameters. Opalstack makes no specific recommendations as to how these parameters should be set for a particular application or level of traffic. To figure out the best settings for your site, you will need to monitor your site’s performance and adjust the settings accordingly.

Installing Composer¶

Composer is a dependency manager for PHP that is used for package management in modern PHP web frameworks.

To install Composer in your home directory:

  1. Log into a SSH session as your application’s shell user.
  2. Run the following commands to download and install Composer:
cd ~ mkdir -p ~/bin wget -O composer-setup.php https://getcomposer.org/installer php composer-setup.php --install-dir=$HOME/bin --filename=composer rm composer-setup.php 

Once these steps are completed you can use Composer by running composer or ~/bin/composer at the command line.

Password Protection for PHP+Apache Applications¶

If you need password protection for a PHP+Apache application that does not provide its own authentication then you can use Apache HTTP authentication as an alternative.

Note: this feature is not available for PHP-FPM+Nginx applications. It is only for PHP+Apache and the corresponding symlink app types.

  1. Log into a SSH session as your application’s shell user.
  2. Run the following commands to create the password file. This example will use myuser as the shell user name, myapp as the application name, and webuser as the name of the HTTP authentication user.
cd ~/apps/myapp htpasswd -c .htpasswd webuser 
 Require all denied AuthUserFile /home/myuser/apps/myapp/.htpasswd AuthName MyApp AuthType Basic Require valid-user 

If you need to create additional HTTP authentication users for your application, you can re-run the htpasswd command without the -c flag like so:

htpasswd .htpasswd anotheruser 

PHP exec, passthru, shell_exec, and system¶

The PHP exec , passthru , shell_exec , and system functions are disabled by default on PHP apps installed via our dashboard.

If you’d like to have these function enabled for your PHP application, then please contact us to let us know the shell user and application for which you want them enabled.

Troubleshooting PHP Applications¶

Browser displays a blank page instead of rendered pages¶

  1. View the source of the blank page as it may contain partially-rendered code and/or error messages related to the problem.
  2. Check your application’s error logs in ~/logs/appname as it may contain error messages related to the problem.
  3. If your application has a debug mode of operation then activate it and reload the page. This may allow the application to display diagnostic information and/or error messages related to the problem.

Why is my site serving PHP source instead of my site?¶

If your PHP site is serving its source code instead of rendered HTML then please check the following:

PHP handlers in .htaccess¶

If your app is using a .htaccess file then look for something like the following in that file:

Delete the SetHandler line. If the FilesMatch block doesn’t contain anything else, then delete the entire block.

Save the file and reload the site in your browser.

You can quickly locate .htaccess files that might need your attention with the following command:

grep -R --include=".htaccess" -iE "(Set|Add)Handler.+php" ~/apps 

Wrong application type¶

Check the application type for your application in the app list.

If you chose a static app type instead of a PHP app type when you created your application then contact support to have it changed.

Installing and Using PEAR Packages¶

PEAR (the PHP Extension and Application Repository) is a framework and distribution system for reusable PHP components.

To install PEAR in your home directory:

  1. Log into a SSH session as your application’s shell user.
  2. Execute the following commands to download and launch the PEAR installer:
cd ~ mkdir ~/tmp wget https://pear.php.net/go-pear.phar php go-pear.phar 
Below is a suggested file layout for your new PEAR installation. To change individual locations, type the number in front of the directory. Type 'all' to change all of them or simply press Enter to accept these locations. 1. Installation base ($prefix) : /home/username/pear 2. Temporary directory for processing : /home/username/tmp/pear/install 3. Temporary directory for downloads : /home/username/tmp/pear/install 4. Binaries directory : /home/username/pear/bin 5. PHP code directory ($php_dir) : /home/username/pear/share/pear 6. Documentation directory : /home/username/pear/docs 7. Data directory : /home/username/pear/data 8. User-modifiable configuration files directory : /home/username/pear/cfg 9. Public Web Files directory : /home/username/pear/www 10. System manual pages directory : /home/username/pear/man 11. Tests directory : /home/username/pear/tests 12. Name of configuration file : /home/username/.pearrc 1-12, 'all' or Enter to continue: 
Would you like to alter php.ini ? [Y/n] : 

Once these steps are completed you can install PEAR packages by running ~/pear/bin/pear install packagename the command line, replacing packagename with the name of the PEAR package that you want to install.

Using PEAR packages in your PHP applications¶

After you’ve installed PEAR and have used it to install the packages that you need, you can then configure your applications to use those packages as follows:

  1. Create a .user.ini file in your application directory. See Configuring PHP Settings for details.
  2. Add the following line to the .user.ini file from step 1, replacing username with the name of your application’s shell user:
include_path = .:/home/username/pear/share/pear 

Once these steps are completed your application will be able to locate and use the PHP packages that you’ve installed from PEAR.

© 2023 Opalstack LLC. All rights reserved.

Источник

Configuring your PEAR setup

The default settings suffice for novice users, there is rarely a need to change them when getting started. You can go on with installing packages.

Reading single values is accomplished by using config-get . The following command will show you where all the .php files of your installed pear packages reside.

$ pear config-get php_dir /usr/share/pear

Changing a value is as easy as retrieving it:

$ pear config-set preferred_state beta config-set succeeded

When changing a config setting, it does not immediately get applied to already installed packages. This is especially true when changing variables like data_dir . Use $ pear upgrade —force to reinstall all packages in such cases.

Config options

Variable Name Description Default Value
bin_dir Directory where executables are installed /usr/bin
doc_dir Directory where documentation is installed /usr/lib/php/docs
ext_dir Directory where loadable extensions are installed ./
php_dir Directory where PHP files are installed (like PEAR files) /usr/lib/php
cache_dir PEAR installer cache directory, and used by XMLRPC /tmp/pear/cache
data_dir Directory where data files are installed /usr/lib/php/data
php_bin The PHP CLI or CGI binary for executing scripts /usr/bin/php
test_dir Directory where regression tests are installed /usr/lib/php/tests
cache_ttk Number of seconds that the local cache is used, and not updated (Time To Kill) 3600
preferred_state Preferred package state: stable, beta, alpha, devel, or snapshot stable
umask umask used when creating files (Unix-like systems only) 22
verbose Debug log level: 0-3 where 3 is full debug mode. 1
http_proxy The optional HTTP proxy address (host:port) used when downloading packages
remote_config Remote configuration file, used to mirror a local installation on a remote server through ftp. (PEAR 1.4+)
auto_discover Auto-discover new channels from command line or dependencies 0
default_channel Default channel (PEAR 1.4+) pear.php.net (pecl.php.net if using the pecl command)
preferred_mirror Preferred channel mirror (PEAR 1.4+) pear.php.net (pecl.php.net if using the pecl command)
master_server PEAR server [deprecated in PEAR 1.4+] pear.php.net
password PEAR password (used by maintainers)
sig_bin Signature handling program /sw/bin/gpg
sig_keydir Signature key directory /etc/pearkeys
sig_keyid The key used for signing
sig_type Package signature type (only gpg) gpg
username PEAR username (used by maintainers)

Источник

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