PHP
From Gentoo Linux Wiki
PHP
Contents |
[edit] What is PHP?
PHP is a widely-used general-purpose scripting language, originally designed for producing dynamic web pages. It is for server-side scripting, but can be used from a command line interface or in standalone graphical applications.
[edit] Subpages
[edit] Installation
Before you begin, check your USE flags. Depending on what you will be doing, you can add some of the following USE flags to /etc/portage/package.use for dev-lang/php:
- apache2 -- Apache Support (required)
- mysql -- MySQL database support (required)
- suhosin -- PHP Security Module (HIGHLY recommended) [1]
- ssl -- Secure Sockets Layer (for encrypted connections)
- gd -- GD Image rendering library (if you want to thumbnail images)
- jpeg -- JPEG image support
- truetype -- Truetype Font
Look at the gentoo-portage listing for dev-lang/php5 if you want to see what other USE flags are available.
When you have set all of these up to your liking, do:
emerge --ask --verbose dev-lang/php
[edit] Configure
PHP's configuration is mainly stored in the php.ini. To find out its path, you can use
| Command: Show configuration file names |
# php --ini Configuration File (php.ini) Path: /etc/php/cli-php5 Loaded Configuration File: /etc/php/cli-php5/php.ini Scan for additional .ini files in: /etc/php/cli-php5/ext-active Additional .ini files parsed: /etc/php/cli-php5/ext-active/ssh2.ini |
[edit] SMTP
This section deals with the following scenario: You have a Gentoo installation running on a dynamic IP and you want the /usr/sbin/sendmail command to use a SMTP-server. This can be used with gmx.net, web.de and probably any public email provider (if you have an account there), as msmtp can take care of authentication and encryption. This tutorial doesn't set your machine up as a SMTP server (port 25) that can be used by other machines. But it will let you send emails trough PHP's mail()-function or mutt. This solution - compared to setting up other email solutions - is very simple, quick (not dirty) and primitive.
What this HOWTO sets up works as follows:
- e.g. Apache's mod_php wants to send an email.
- /usr/sbin/sendmail is called by apache
- msmtp will send the mail to your preferred SMTP. (Taking care of authentication and/or encryption)
See Msmtp for notes on the installation of msmtp.
The .msmtprc files in your user's home directories will use /usr/sbin/sendmail. To get it working with mod_php you have to set it up in apache's home directory.
cat /etc/passwd | grep apache apache:x:81:81:added by portage for apache:/var/www:/bin/false
shows us that /var/www is apache's home directory.
Now check that only the apache-server can read your password:
chown apache:nobody .msmtprc chmod 600 .msmtprc
Now you have to search for your php.ini and tell it the path to your new "sendmail" command, msmtp (/usr/local/bin on my computer):
| File: somewhere in php.ini |
[mail function] ; For Win32 only. ;SMTP = localhost ;smtp_port = 25 ; For Win32 only. ;sendmail_from = me@example.com ; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). ; sendmail_path = "/usr/sbin/sendmail -t -i" sendmail_path = "/usr/bin/msmtp -t" |
Any error-output by PHP's mail() command will be found /var/log/apache/error_log (even when it was triggered by SSL)
Mails send from PHP-applications like mediawiki should now be delivered as if you would have send them with your email-program.
[edit] Troubleshooting
If msmtp is complaining that it can't find the configuration files then just explicitly add the path to your php.ini file, like this.
| File: somewhere in php.ini |
[mail function] ;sendmail_path = "/usr/bin/msmtp -t" sendmail_path = "/usr/bin/msmtp --file=/path/to/your/.msmtprc -t" |
[edit] PHP-GTK
Currently PHP-GTK is a masked package. To unmask it, enter the following command
echo "dev-php5/php-gtk ~x86" >> /etc/portage/package.keywords
Now you can install it using:
emerge -av php-gtk
PHP-GTK supports the following USE parameters:
glade This will allow you to use Glade for designing your GUIs spell Spell checking debug Compile in debug mode doc Include documents examples Include examples extra Include extra stuff html GtkHTML support libsexy Include libsexy mozembed Use the Gecko engine in your applications scintilla Support for editor-like input fields with syntax highlighting
[edit] External Links
[edit] PEAR
Installing PEAR (the PHP Extension and Application Repository) for use with PHP 5 is is relatively simple.
Add the USE flags PEAR requires PHP be compiled with.
| File: /etc/portage/package.use |
dev-lang/php cli pcre xml zlib |
Re-emerge PHP, for the new useflags to take effect
| Code: emerge php |
emerge -av dev-lang/php |
With the preparation completed, all that remains is to install PEAR itself.
| Code: emerge PEAR-PEAR |
emerge -av dev-php/PEAR-PEAR |
That's it! PEAR should now be installed, and ready for use.
[edit] Notes
- Using hardenedphp seems to be a problem. -- Po0ky
- When used with apache2 with threads support enabled: it is possible you are unable to open any php webpage.
- Merging PEAR might fail.
