https://wiki.archlinux.org/api.php?action=feedcontributions&user=Niklasni1&feedformat=atomArchWiki - User contributions [en]2024-03-28T16:42:44ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=PHP&diff=296072PHP2014-02-03T20:07:02Z<p>Niklasni1: /* Installation */</p>
<hr />
<div>[[Category:Programming language]]<br />
[[de:PHP]]<br />
[[es:PHP]]<br />
[[sr:PHP]]<br />
[http://www.php.net/ PHP] is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.<br />
<br />
== Installation ==<br />
[[pacman|Install]] the {{Pkg|php}} package from the [[Official Repositories|official repositories]].<br />
<br />
Note that to run PHP scripts as plain CGI, you need the {{Pkg|php-cgi}} package.<br />
<br />
== Setup ==<br />
While PHP can be run standalone, it is typically used with http servers such as apache, nginx and lighttpd.<br />
* '''apache''': to setup PHP, Apache and MySQL, commonly known as LAMP, see [[LAMP]]<br />
* '''lighttpd''': see [[lighttpd]]<br />
* '''nginx''': see [[nginx]]<br />
<br />
== Configuration ==<br />
The main PHP confiuration file is well-documented and located at {{ic|/etc/php/php.ini}}.<br />
<br />
== Extensions ==<br />
<br />
A number of commonly used PHP extensions can also be found in the official repository:<br />
# pacman -Ss php-<br />
<br />
===gd===<br />
For {{Pkg|php-gd}} uncomment the line<br />
extension=gd.so<br />
<br />
===imagemagick===<br />
For {{Pkg|imagemagick}} run {{ic|# pecl install imagick}} and add<br />
extension=imagick.so<br />
<br />
=== pthreads extension ===<br />
If you wish to have POSIX multi-threading you will need the pthreads extension. to install the pthreads (http://pecl.php.net/package/pthreads) extension using {{ic|pecl}} you are required to use a compiled version of PHP with the the thread safety support flag {{ic|--enable-maintainer-zts}}. currently the most clean way to do this would be to rebuild the original package with the flag.<br />
<br />
instruction can be found on the [[PHP pthreads extension|PHP pthreads extension]] page.<br />
<br />
== Zend Core + Apache ==<br />
Zend Core is the official PHP distribution provided by [http://www.zend.com zend.com]. It includes an installer/updater, zend optimizer, oracle support, and necessary libraries. However, it lacks support for postgresql, firebird, and odbc.<br />
* Install {{Pkg|mod_fcgid}}, a FastCGI module for Apache (the official one sucks).<br />
* Install Zend Core (official PHP distribution)<br />
** Uninstall the {{Pkg|php}} package.<br />
** Download and install zend core from [http://www.zend.com/products/zend_core] ; '''don't''' install the bundle apache or tell it to setup your web server. It always installs to {{ic|/usr/local/Zend/Core}} due to hard-coded path.<br />
** Create a script {{ic|/usr/local/bin/zendcore}} and create symlinks to ''php'', ''php-cgi'', ''pear'', ''phpize'' under ''/usr/local/bin''<br>{{ic|1=#!/bin/bash <br>export LD_LIBRARY_PATH="/usr/local/Zend/Core/lib"<br>exec /usr/local/Zend/Core/bin/`basename $0` "$@"}}<br />
* Setup Apache:<br />
** In {{ic|/etc/httpd/conf/httpd.conf}}, add<br>{{ic|LoadModule fcgid_module lib/apache/mod_fcgid.so<br><Directory /srv/http><br>AddHandler fcgid-script .php<br>FCGIWrapper /usr/local/bin/php-cgi .php<br>Options ExecCGI<br>Allow from all<br></Directory><br>SocketPath /tmp/fcgidsock<br>SharememPath /tmp/fcgidshm}}<br />
** Remember to change the Directory path<br />
* Disable Zend Optimizer (so you can use cache):<br />
** Edit {{ic|/etc/php.ini}}, uncomment the following line near the end of file:<br>{{ic|<nowiki>zend_extension_manager.optimizer="/usr/local/Zend/Core/lib/zend/optimizer"</nowiki>}}<br />
{{Out of date|Use APCu/OPcache https://www.archlinux.org/news/php-55-available-in-the-extra-repository/}}<br />
* Install APC (Alternative PHP Cache):<br />
** Run {{ic|pear install pecl.php.net/apc}} as superuser.<br />
** Edit {{ic|/etc/php.ini}}, add the line after ''"; Zend Core extensions..."'' (line 1205):<br>{{ic|<nowiki>extension=apc.so</nowiki>}}<br />
* Update Zend Core and/or install other components<br />
** Just run {{ic|/usr/local/Zend/Core/setup}}<br />
<br />
== Development tools ==<br />
<br />
=== Komodo ===<br />
Good integration for PHP+HTML+JavaScript. Lacks code formatting and unicode support in doc comments.<br />
<br />
[http://www.activestate.com/products/komodo_ide/ Komodo IDE] | [http://www.activestate.com/products/komodo_edit/ Komodo Edit (free)]<br />
<br />
Add custom encodings:<br />
*Edit {{ic|''KOMODO_INSTALL_DIR''/lib/mozilla/components/koEncodingServices.py}}, line 84, add:<br />
('cp950', 'Chinese(CP-950/Big5)', 'CP950', &#39;&#39;, 1,'cp950'),<br />
('cp936', 'Chinese(CP-936/GB2312)', 'CP936', &#39;&#39;, 1,'cp936'),<br />
('GB2312', 'Chinese(GB-2312)', 'GB2312', &#39;&#39;, 1,'GB2312'),<br />
....<br />
The format is (''encoding name in python'', ''description'', ''short description'', BOM, ''is ASCII-superset?'', ''font encoding'')<br />
<br />
=== Netbeans ===<br />
A complete IDE for many languages including PHP. Includes features like debugging, refactoring, code tempalting, autocomplete, XML features, and web design and development functionalities (very good CSS autocomplete functionality and PHP/JavaScript code notifications/tips).<br />
<br />
=== Eclipse PDT ===<br />
[http://www.zend.com/pdt Eclipse PDT] is not very complete at the current stage (v0.7); for instance, it cannot pop-up class list automatically when you type, though you can add custom auto-activation trigger keys.<br />
<br />
You would need other plugins for javascript support and DB query.<br />
<br />
=== Zend Studio ===<br />
[http://www.zend.com/products/studio/ Zend Studio] is the official PHP IDE, based on eclipse. The IDE has autocomplete, advanced code formatting, WYSIWYG html editor, refactoring, and all the eclipse features such as db access and version control integration and whatever you can get from other eclipse plugins.<br />
<br />
=== Aptana Studio ===<br />
A good IDE for programming in PHP and web development. The current version (3.2.2) does not have a PHP debugger.<br />
<br />
=== Zend Code Analyzer ===<br />
A PHP code analyzer from Zend Studio. The program is indispensable for any serious PHP coding.<br />
<br />
==== Installation ====<br />
* Download and install Zend Studio Neon<br />
* In the installation dir, run {{ic|find . -name "ZendCodeAnalyzer}} to get the path.<br />
* Copy ZendCodeAnalyzer to {{ic|/usr/local/bin/zca}}<br />
* Now you can remove zend studio; you won't need a key or anything.<br />
<br />
==== Vim Integration ====<br />
Add the following lines into your {{ic|.vimrc}}:<br />
autocmd FileType php setlocal makeprg=zca\ %<.php<br />
autocmd FileType php setlocal errorformat=%f(line\ %l):\ %m<br />
<br />
==== Eclipse Integration ====<br />
''Error Link'' plugin:<br />
* Symlink ''zca'' to ''build.zca'' (so Error Link can recognize it)<br />
* Install [http://sunshade.sourceforge.net/ Sunshade] plugin suite;<br />
* Preference -> Sunshade -> Error Link -> Add: ''{{ic|^(.*\.php)\(line (\d+)\): ()(.*)}}''<br />
* Run -> External Tools -> Open External Tools Dialog -> Select "Program" -> Clicn on "New":<br>Name: Zend Code Analyzer<br>Location: ''/usr/local/bin/build.zca''<br>Working Directory: ''${container_loc}''<br>Arguments: ''--recursive ${resource_name}''<br />
<br />
==== Komodo Integration ====<br />
Toolbox -> Add -> New Command:<br />
* Command: ''zca --recursive %F''<br />
* Run in: Command Output Tab<br />
* Parse output with: ''{{ic|^(?P<file>.+?)\(line (?P<line>\d+)\): (?P<content>.*)$}}''<br />
* Select ''Show parsed output as a list''<br />
<br />
== Troubleshooting ==<br />
=== PHP Fatal error: Class 'ZipArchive' not found ===<br />
Ensure the zip extension is enabled.<br />
{{hc|$ grep zip /etc/php/php.ini|2=<br />
extension=zip.so}}<br />
<br />
=== /etc/php/php.ini not parsed ===<br />
If your php.ini isn't parsed, the ini file is named after the sapi it's using.<br />
for instance if you're using uwsgi the file would be called /etc/php/php-uwsgi.ini<br />
or if you're using cli it's /etc/php/php-cli.ini</div>Niklasni1