Difference between revisions of "PHP"
Rootadminacc (talk | contribs) |
Rootadminacc (talk | contribs) |
||
Line 273: | Line 273: | ||
↓ ↓ | ↓ ↓ | ||
Websites & Domains tab > click your domain > under Web Scripting and Statistics change PHP Support from Apache Module to Fast CGI Application</pre> | Websites & Domains tab > click your domain > under Web Scripting and Statistics change PHP Support from Apache Module to Fast CGI Application</pre> | ||
Plain text: | |||
- ← Hosting Services - Domains > Open in Control Panel for your domain<br> | - ← Hosting Services - Domains > Open in Control Panel for your domain<br> |
Revision as of 08:40, 23 April 2013
Additional PHP modules/extensions
- apc - Used for caching. Check in /opt/psa/admin/conf/php.ini and php -m . There should also be extension="apc.so" in another php.ini file too. For CentOS.
- libgd2 - Guide if GD Library is too old (due to bundled version with PHP5)
- php5-curl
- PHP5-gd - GD Image Libary
- php5-mcrypt - File Encryption tool, Windows guide. If you get the error Connection reset by peer: mod_fcgid: error reading data from FastCGI server after installing this, do:
cp -f /usr/local/psa/suexec/psa-suexec /usr/sbin/suexec ; chown root:apache /usr/sbin/suexec ; chmod 4510 /usr/sbin/suexec
For CentOS, do this and then do:
yum install -y mcrypt.x86_64 libmcrypt.x86_64 libmcrypt-devel.x86_64 php-mcrypt.x86_64
- Zend Optimizer , to check it's installed run php -i | grep Zend . See the downloads page here. You may need Guard or Guard Loader for higher versions of PHP. Check your current PHP version by doing php -v . To install it on a Plesk server see the following threads: 1 and 2
Check if module is installed
On Unix systems do:
php -i | grep modulename
command line ZIP via exec()
phpinfo.php should show disable_functions is set to no value if disable_functions is blank in all php.ini files.
Alternatively you may need to use suPHP.
cPanel PHP Configuration
You can change how PHP is configured. As root, simply execute: /usr/local/cpanel/bin/rebuild_phpconf --help
Downgrade PHP 5.3 to 5.2
CentOS 6
Ubuntu 10.04
Gathering PHP Information - PHP Info Page
Create a phpinfo.php inside /var/www/vhosts/domain.com/httpdocs to gather server information, loaded configuration file and PHP values using the below code and then go to yourdomain.com/phpinfo.php:
<?php phpinfo(); ?>
The local file will not be picked up as it reads it from the php.ini file so set the domain PHP support to Fast CGI Application and once set in that configuration file (cgi/php.ini) it will be the Master value. If the domain is set to be an Apache module edit the apache2/php.ini file.
Refresh the file in your browser when you have changed a value/variable.
Basic PHP page
<html> <head> <title>PHP Test</title> </head> <body> <?php echo '<p>Hello World</p>'; ?> </body> </html>
Error Reporting/Logging
In /etc/php.ini go to ~ line 518 and see next to error_reporting and it's options:
Set to the value E_ALL | E_STRICT instead of E_ALL & ~E_NOTICE potentially.
Redirect
<? Header( "HTTP/1.1 301 Moved Permanently" ); Header( "Location: http://www.new-url.com" ); ?>
If you have a Plesk server with version 11 on it, the web server EngineX uses the masks REMOTE_ADDR variable (which you should use instead of REMOTE_HOST which is for host names). Disable your .htaccess and create a PHP script with:
<?php $ip = $_SERVER["REMOTE_ADDR"]; $real_ip = $_SERVER["HTTP_X_REAL_IP"]; echo "IP: " .$ip; echo "Real IP: " .$real_ip; ?>
What you will see is that IP reports as the IP of the server whereas the second line returns the real remote IP of the user connecting to the site. You should try changing the REMOTE_HOST to HTTP:HTTP_X_REAL_IP
failed to open stream: Too many open files
To fix this try and set the ulimit in the Apache configuration, otherwise it will get overridden by the default value.
ulimit -n ulimit -Sn ulimit -Hn
To set do:
ulimit -n value
Joomla
mod_fcgid: HTTP request length exceeds MaxRequestLen
If you get the following error in a Plesk server in /var/www/vhosts/domain.co.uk/statistics/logs/error_log
mod_fcgid: HTTP request length 131388 (so far) exceeds MaxRequestLen (131072)
It normally means you need to edit /etc/httpd/conf.d/fcgid.conf and in between the <IfModule> and </IfModule> tags place:
FcgidMaxRequestLen 134217728
Pear
CentOS:
yum install php-pear.noarch
Ubuntu (one of these):
apt-get install php-pear
apt-get install psa-pear
PHP.ini
Windows location if using Plesk: C:\Program Files (x86)\Parallels\Plesk\Additional\PleskPHP5/php.ini
safe_mode and open_basedir (set to off) can be changed within these php.ini files:
vim /etc/php5/apache2/php.ini vim /etc/php5/cgi/php.ini vim /etc/php5/cli/php.ini /var/www/vhosts/domain.com/etc/php.ini
Turning off magic_quotes_gpc
magic_quotes_gpc (deprecated in PHP 5.3)
Then add the below entry inside vhost.conf under the var/www/vhosts/domain.com/conf directory excluding what you do not need:
<Directory /var/www/vhosts/DOMAIN.COM/httpdocs> php_admin_flag engine on php_admin_flag safe_mode off //turns safe mode off php_admin_value open_basedir //set none to turn off //the following to turn on /var/www/vhosts/DOMAIN.COM/ </Directory>
You can also edit this file /opt/psa/admin/conf/php.ini (Ubuntu) or /usr/local/psa/admin/conf/php.ini (CentOS) and add/edit safe_mode = Off open_basedir = none (or Off) and run:
/usr/local/psa/admin/bin/httpdmng --reconfigure-all /etc/init.d/apache2 restart
The above command creates an include file in the same directory.
safe_mode
<Directory /var/www/vhosts/DOMAIN.COM/httpdocs> php_admin_flag safe_mode off </Directory>
Safe mode and line errors
Disable Safe Mode on Plesk 10 for Webfusion
open_basedir
<Directory /var/www/vhosts/DOMAIN.COM/httpdocs> php_admin_value open_basedir none </Directory>
Subdomains do not have conf folders by default, so it can be set in /var/www/vhosts/domain/subdomains/conf/vhost.conf as /var/www/vhosts/domain/subdomain , locally in a .htaccess file or globally on the server in php.ini if it is running as Apache.
Timezone
Within the three php.ini files if you search for /timezone you will need to un-comment the values for timezone, latitude and longitude and enter only the timezone within "quotes". The most common request if for the following values:
[Date] ; Defines the default timezone used by the date functions ; http://php.net/date.timezone date.timezone = "Europe/London" ; http://php.net/date.default-latitude date.default_latitude = 51.500181 ; http://php.net/date.default-longitude date.default_longitude = 0.12619
You may need to add it to the domain specific PHP file in /var/www/vhosts/domain.com/etc/php.ini or /usr/local/psa/admin/conf/php.ini
Fail to download/export SQL Database (memory_limit)
When trying to download a copy of SQL database with Error 6 (net::ERR_FILE_NOT_FOUND) or unable to "find" a file this may be due to the setting memory_limit in the Plesk php.ini file.
1. Open your Plesk php.ini (placed at /usr/local/psa/admin/conf/php.ini)
2. Find memory_limit and change to: memory_limit = 128M/x2/4/8 for example
3. Stop and start psa services
/etc/init.d/psa stopall /etc/init.d/psa startall /etc/init.d/sw-cp-server restart
Exporting large database in phpMyAdmin or see here
PHP Upload Files Failure/Increasing memory values
Fatal error: Call to undefined function curl_init()
If you are using Plesk and the curl.dll (not the actual file name) extension is enabled in php.ini check the wordpress applications in the site for a different PHP config to the main site. Reset the settings for the site and they may go back into sync.
Timeout
Set max_execution_time in php.ini. By default this is 60 seconds on most servers.
Also see this.
If you get:
mod_fcgid: stderr: PHP Notice: session_start(): ps_files_cleanup_dir: opendir(/var/lib/php/session) failed: Permission denied (13) in /var/www/vhosts/domain.co.uk/httpdocs/filepath.php on line X, referer: domain.co.uk/filepath
Set php.ini to have this:
session.save_path = "/tmp"
Include file
PHP Warning: Module
If you get something like the below message when doing php -v :
PHP Warning: Module 'json' already loaded in Unknown on line 0
PHP Warning: Module 'mbstring' already loaded in Unknown on line 0
The modules have likely been defined twice in the server configuration by adding them manually to the PHP.ini file which is unnecessary. Remove the extra config which should get rid of the warning.
PHP Configuration in Plesk
The user:group of website files depends on what the PHP Support for a site is set as.
If it is set as Fast CGI Application, the user:group for everything below the Document Root (normally httpdocs) is ftpuser:psacln (with psaserv owning httpdocs).
If it is set as Apache Module, you want www-data:www-data
The PHP Support can be set in:
← Hosting Services - Domains > Open in Control Panel for your domain ↓ Hosting Services - Subscriptions > Manage Hosting/Open in Control Panel for your domain ↓ ↓ ↓ ↓ Websites & Domains tab > click your domain > under Web Scripting and Statistics change PHP Support from Apache Module to Fast CGI Application
Plain text:
- ← Hosting Services - Domains > Open in Control Panel for your domain
↓ - Hosting Services - Subscriptions > Manage Hosting/Open in Control Panel for your domain
↓ ↓
Websites & Domains tab > click your domain > under Web Scripting and Statistics change PHP Support from Apache Module to Fast CGI Application
PHP Configuration in WHM
Use Software > EasyApache (Apache Update)
Apache: Mod FCGID
PHP: Fastcgi
For Magento the following requirements are needed:
- PDO_MySQL
- simplexml
- mcrypt
- hash
- GD
- DOM
- iconv
- SOAP (if Webservices API is to be used)
The web based version of EasyApache is notoriously temperamental, it may freeze on you. This is usually due to the memory load on the server. By using an SSH console, you can complete the process in a much more efficient manner.
/scripts/easyapache
to launch the process. Follow the instructions on screen, remembering that it can sometimes take a while to build an entirely new version of php, and good luck.
Complete these instructions to set up all the required extensions, however when it came to one payment gateway, you may still need to set up curl and curlssl – two libraries needed for POSTing data securely over HTTP and SSL. Remember to activate these at the time you do your original build, as it’ll save a great deal of hassle later on.
Alternatively run: /usr/local/cpanel/bin/rebuild_phpconf
PHP Mail Test
Or the following:
<?php $to = "[email protected]"; $subject = "Hi!"; $body = "Hi,\n\nHow are you?"; if (mail($to, $subject, $body)) { echo("Message successfully sent!"); } else { echo("Message delivery failed..."); } ?>
PHP Page downloading
If when you view a .php file it tries to download and you do not want it to, do the following via SSH:
a2enmod php5 /etc/init.d/apache2 restart
And if you use Plesk go here and tick PHP Support. a2dismod may be needed as well.
Alternate guides:
You may need to do:
apt-get install php5-cgi libapache2-mod-fcgid libapache2-mod-php5
PHP My Admin
How to access in Plesk
You may need to allow pop-ups.
In Plesk 10 go to either:
- Server Management - Tools & Settings > Applications & Databases - Database Servers > click Webadmin icon
- Server Management - Tools & Utilities > Resources - Database Servers > same as above.
- Server tab, Resources - Database Servers > same as above.
This access for MySQL is server level so you can see all MySQL databases.
For individual domains you go to:
- Hosting Services - Domains > Open in Control panel > Websites & Domains > Databases > click the database you want to manage then Webadmin icon.
- Hosting Services - Subscriptions > Manage Hosting > Websites & Domains > Databases > same as above.
The root user cannot access phpMyAdmin
import.php: Missing parameter: import_type
import.php: Missing parameter: import_type
1077 Error
When you upload a file into phpMyAdmin and it shows a 1077 error, you are likely uploading the wrong file type. It needs to be as follows:
"File may be compressed (gzip, zip) or uncompressed. A compressed file's name must end in .[format].[compression]. Example: .sql.zip"
If you right click the .sql file and zip it and then try it should work as long as it is below 2GB.
Cannot start session
phpMyAdmin - Error Cannot start session without errors, please check errors given in your PHP and/or webserver log file and configure your PHP installation properly.
- Make a PHP Info page to see which php.ini it loads
- Check /var/log/sw-cp-server/error_log , /var/log/apache2/error.log or /var/www/vhosts/site11.pro1.ictgateshead.org/statistics/logs/error_log
- Put session.save_handler = files and session.save_path = /tmp in all PHP.ini files and restart Apache.
- Ensure tmp has root:root user:group . It may try to save session files to /var/lib/php5 and ensure the following folders have the right permissions: /usr/local/psa/tmp + aps /usr/local/psa/admin/sessions + logs + bin/modules
- find /opt/psa -user admins -print | xargs chown root -- to correct ownership # chmod 4110 /opt/psa/admin/sbin/wrapper -- to set correct permissions of wrapper for Plesk
- Also: http://kb.parallels.com/en/111857
Or when installing Joomla for example on a Plesk server, you may get:
mod_fcgid: stderr: PHP Warning: session_write_close(): open(/var/lib/php/session/sess_adkb8rfaum29um5g8d57i6v5q3, O_RDWR) failed: Permission denied (13) in /var/www/vhosts/domain.co.uk/httpdocs/libraries/joomla/session/session.php on line 676, referer: http://IPaddress/installation/index.php
vim /var/www/vhosts/domain.co.uk/etc/php.ini session.save_path = /tmp #session.save_path = "/var/lib/php/session" /etc/init.d/httpd or /etc/init.d/apache2 restart
This above Joomla Plesk one happens because /var/lib/php/session needs a different user:group and/or permissions.
Export issue
The error normally shown is "can’t find the file at https://xx.xx.xx.xx:8443/domains/databases/phpMyAdmin/export.php"
vim /usr/local/psa/admin/conf/php.ini
Find the line containing memory_limit. Increase this to 256M, 512M or 1024M.
/etc/init.d/sw-cp-server restart /etc/init.d/psa stopall /etc/init.d/psa startall
Accessing a manual install
If you have installed phpMyAdmin in another location, see these links:
http://help.slamdot.com/idx/0/081/How-do-I-access-phpMyAdmin
http://learnwebtutorials.com/access-mysql-database-phpmyadmin
Rare error:
export.php: Missing parameter: whatDocumentation export.php: Missing parameter: export_typeDocumentation
In file <Plesk_dir>\admin\htdocs\domains\databases\phpMyAdmin\libraries\session.inc.php
uncomment line: //@ini_set('session.use_trans_sid', true); to @ini_set('session.use_trans_sid', true);
Restart Plesk.
soap
php-soap
vim /etc/yum.repos.d/atomic.repo enabled = 0 yum install php-soap php -m | grep soap
suPHP
register_globals
If you get the following error on your website:
FATAL ERROR: register_globals is disabled in php.ini, please enable it!
Setup a PHP Info page and see which php.ini PHP is loading from. Then go into SSH and edit the Loaded Configuration File by finding the entry using:
/register_globals
Set it to on or off. Then exit the file and run:
/etc/init.d/apache2 restart
Upgrade PHP
Work in progress.
Ubuntu 8.04 to PHP 5.2.8
Ubuntu 8.04 to PHP 5.2.9
CentOS 5.5 to PHP 5.3.3
CentOS 6.2 to PHP 5.4