All You Need to Know About php.ini

Description

Most servers with php installed on them come with default settings that are used server wide. However, sometimes a program will require these php settings to be changed and instead of changing the settings for the entire server a person can overwrite the default settings for just a particular location (or domain). This is done by installing a file called php.ini in the directory where the particular php scripts are located.

Determine current php settings

One of the first things you may want to do before installing a php.ini file would be to check to see what the server’s php settings are currently. This can be done by making a simple php script like the one shown. The reasoning for this is to see if there is even a need to overwrite the php settings or if the problem is located elsewhere.
[php]
//phptest.php
<?php
phpinfo();
?>
[/php]

Implementing php.ini

Step 1: Download the example php.ini.
Step 2: Upload the php.ini file to the directory where the php scripts are located. Note: If the file is named php.ini.default please rename it to php.ini.
Step 3: Edit the settings in the php.ini file that you want to change.

Common uses for php.ini

  • Increase post and upload sizes
  • [php]
    ; Maximum size of POST data that PHP will accept.
    post_max_size = 50M

    ; Maximum allowed size for uploaded files.
    upload_max_filesize = 50M
    [/php]
    Note: To change the upload size you must change both the post_max_size and upload_max_filesize sections. The post_max_size will need to be larger than the upload_max_filesize.
    Note: Most servers don’t care what the upload size is as long as you can upload all the content within a limited number of minutes. If it takes longer than what that server allows your connection will time out and the upload will fail.

  • Increase memory available for use
  • [php]
    ;;;;;;;;;;;;;;;;;;;
    ; Resource Limits ;
    ;;;;;;;;;;;;;;;;;;;

    memory_limit = 128M ; Maximum amount of memory a script may consume (16MB)
    [/php]

  • Toggle safe mode on and off
  • [php]
    ; Safe Mode
    ;
    safe_mode = Off
    [/php]

HTTP Error – 404 Not Found

Description

A 404 Not Found means the address cannot find a file or folder on the webhosting server or the server has not found a file matching the given URI.

Troubleshooting to Fix

  • Check the spelling for the file and URL. After the base url all the links are case sensitive according to the casing of the particular files. If a file has an uppercase and you are putting a lower case in the url the webserver will return a 404 – Not Founderror.
  • Check the nameservers and DNS information. If you have recently uploaded files and can’t seem to located them check to make sure the nameservers point to the proper location. This can be done by going to who.is and entering the domain name.
  • Make sure file exists. Another common problem is the url is requesting a file that is simply not there or has been placed in a different location on the server. Check with your webhosting company to verify that the files are in the right folder. Most webhosting platforms will have a public_html directory where all website files should be placed.

HTTP Error – 403 Forbidden

Description

A 403 – Forbidden error means the server no longer grants you permission to view at the files being served for the website. This is usually caused by the webserver blocking the files or an endpoint is being protected by an authentication annotation or authentication middleware.

403 forbidden http error

Troubleshooting to Fix

  • Check the folders’ and files’ permissions. Sometimes after uploading files via ftp or upgrading certain scripts the permissions on the files get changed. Linux permissions should generally be set to either 644 or 755 depending on what the script requires. E.G. If a file permissions is 444, 111, etc – the server will not be able to read and execute the script properly.
    NOTE: if you cannot seem to change the permissions of a file, check the folder’s permissions above it and make sure the permissions are set properly
  • Check the .htaccess file for probable causes. There are a variety of possible causes for a 403 – Forbidden error that can occur in the .htaccess.
    1. The .htaccess might be blocking all IP addresses except a few. The code for that would look something like the following:

      [bash]
      order allow,deny
      allow from 173.254.38.123
      deny from all
      [/bash]

    2. The .htaccess may also be missing a line that says DirectoryIndex. This is particularly less common because the DirectoryIndex line is typically not needed in the .htaccess file.

      [bash]
      DirectoryIndex index.html index.cgi index.php
      [/bash]

    3. Try touching the .htaccess file.

      [bash]
      touch .htaccess
      [/bash]

  • Does the endpoint grant the right permissions. Sometimes the rest service you are requesting will return a 403 http error if the request comes from an unauthorized source. Usually a cookie or some form of an authentication token must be set. If you believe you are authenticated properly then try clearing the cache and cookies. If the problem still occurs when it should not, then check your authentication code. If you’re using angular and express then the middleware that validates your role may have some bad logic. Spring for example uses a PreAuthorize annotation that has logic that determines the user’s ability to access the endpoint.

HTTP Error – 402 Payment Required

Description

Reserved error for future use. The original intention was that this code might be used as part of some form of digital cash or micropayment scheme. This code is not usually used, however, Apple’s MobileMe service generates a 402 error (“httpStatusCode:402” in the Mac OS X Console log) if the MobileMe account is delinquent.

Troubleshooting to Fix

  • Pay Your Bills

HTTP Error – 401 Authorization Required

Description

The website you are trying to access has a password protected page. A 401 – Authorization Required error usually means either you do not have not been given the right username-password combination or the basic authentication failed.
401 authorization required

Troubleshooting to Fix

  • Have you been given a username and password for this location? Usually if you have logged into a website requiring authentication the login will fail if the username or password is incorrect. Depending on the website’s backend architecture you could request a new username and password, which may reset the authentication and fix this problem.
  • Check the configuration files in the .htpasswrds. Apache has the ability to password protect directories and files through a file called .htpasswd. Most hosts will store the username and encrypted password in a separate file. The file with the right user name and password looks like the following:

    [bash]
    test:$apr1$VdWobVHD$9MCDrqDIol/vXv4qTXefG.
    [/bash]

  • Certain REST Services will return this error if you do not have the right authentication token. Often time rest endpoints will have some form of a middleware or annotation that makes an endpoint check for an authentication token. This is usually submitted with every request and stored in a cookie for the website in question. If you have problems try clearing the cache and cookies. Then login again – this should reset the expiration of the cookie and replace it if it was corrupted.

HTTP Error – 400 Bad Request

Description

This error 400 – Bad Request simply means either there is an error in the way you tried to type the website into your browser or your browser and web server where the site is hosted are having problems communicating with each other. Most often 400 – Bad Request is due to a bad Internet connection.

Troubleshooting to Fix

  • Does this happen for other sites? If the problem occurs on multiple sites you are trying to access this indicates that the problem is on your local computer and not with the websites.
  • Are you connected to the Internet? If you tried multiple sites and they all show the same error page, check your Internet connectivity. If you are on a slow or unreliable connection this is a fairly common problem
  • Is your local computer secure? Do you keep all the security updates for the operating system up-to-date as well as keeping a good antivirus and malware scanner current on your computer. Any type of malicious software or security breeches on your computer can cause a wide variety of problems including the 400 – Bad Request error.
  • Have you installed any web based software or games? Online or web based games have great risk involved with them and have been known to cause numerous browser related issues. Try to uninstall the software, and in a worst case scenario you will have to format your computer ans start with a fresh install of the operating system.
  • Have you cleared your browser history recently? Clear your cache and cookies. Sometimes a 400 – Bad Request error can be caused by having corrupt cookies or a cached site that is incompatible with the browser. Take the necessary steps to clear the history, cache, and cookies for your browser and try reloading the website.
  • Does this error come up for the same domain name across multiple browsers? Try using Firefox, Google-Chrome, Safari, and/or Internet Explorer and see if all of them get the same error. If they all get the same error this may be due to your Internet connectivity and you will need to run a traceroute (shown in next step) to further troubleshoot the location of the problem.
  • Can you ping or run a traceroute to the server IP address? Open a command line or terminal and try running the following commands. The traceroute will show ever server you have to go through to get to the website and can show where the problem may be occurring.
    [bash]
    traceroute to zaphinath.com (173.254.38.123), 30 hops max, 40 byte packets
    1 ca-vlan999.fsl.byu.edu (10.8.122.1) 1.722 ms 1.760 ms 1.830 ms
    2 oit_uplink.fsl.byu.edu (192.168.254.5) 0.465 ms 1.007 ms 1.215 ms
    3 dc-3n604e-a-corea.dcs.byu.edu (10.3.11.1) 0.389 ms 0.493 ms 0.420 ms
    4 DC-4N204E-A-K1.dcs.byu.edu (10.33.36.37) 40.686 ms 40.662 ms 40.673 ms
    5 DC-4N219E-B-FUSFW1.dcs.byu.edu (10.33.36.2) 0.380 ms * *
    6 DC-4N221E-C-L1.dcs.byu.edu (10.33.38.1) 0.533 ms 0.537 ms 0.585 ms
    7 * DC-4N241E-F-BFW.dcs.byu.edu (10.33.38.10) 6.411 ms *
    8 dc-3n904e-a-br1.dcs.byu.edu (10.33.32.1) 0.953 ms * *
    9 ge-0-2-0–99.gw02.slkc.eli.net (70.103.246.49) 3.454 ms 3.349 ms 2.984 ms
    10 tg9-1.cr02.slkcutxd.integra.net (209.63.114.249) 4.786 ms 4.405 ms *
    11 tg9-1.ar10.oremutuw.integra.net (209.63.98.210) 6.007 ms * tg9-1.ar10.oremutuw.integra.net (209.63.98.210) 6.695 ms
    12 67.137.124.86 (67.137.124.86) 5.654 ms 6.015 ms 6.382 ms
    13 port1.ar01.prov.bluehost.com (199.58.199.114) 5.276 ms 4.789 ms 7.623 ms
    [/bash]
    This traceroute shows the servers the connection had to go through from fls.byu.edu to the web hosting platform. If your traceroute does not make it to the server you might be able to manually change the DNS settings for your computer, reconnect to the Internet, and access the site. Google’s DNS IP’s are 8.8.8.8 and 8.8.4.4.
  • Have you changed any hardware settings recently? Sometimes changing settings improperly will cause your computer to not be able to connect to the Internet. If you have changed any settings try changing them back and refresh the website you are trying to load.

HTTP Error Codes

Description

While on the internet every person has seen error codes. There are a wide variety of error codes and reasons for them. This article will simply address a list of common HTTP error codes and link to subsequent articles with more details about the error codes, common causes, and how to fix the reason for the error. Sometimes HTTP error codes are called Apache error codes.

List of Codes

Simply click on the link below to learn what the error means and how to go about troubleshooting the error.

Browse To Your New Hosting Platform Without Changing Nameservers

Description

Sometimes people will sign up with a new web hosting service and want to be able to work on the page at their new host while leaving their website active at the old host. Most web hosting companies will provide a temporary URL that will allow you to see your site, however due to the nature of the URL, which is usually http://IP_address/~username, some website material such as WordPress can not be viewed properly. This is because these website programs require the actual URL to function properly and be viewed correctly rather than simply an IP address. There is a way, however that you can make your local computer think that the domain name is pointed at your new web host so that you can view it just the way everyone else will once the domain’s nameservers are changed to point to the new server. This method will work much better than a temporary URL.

Server IP Address

You will need the IP address of the server where your website is hosted. You can either contact your webhost provider or go to www.site24x7.com/find-ip-address-of-web-site.html to find what that IP address is.

The Hosts File

In order to change the location your local computer will look for any given domain name is in a file called hosts. This tutorial will first show what changes are needed to make to the hosts file to accomplish our goal and then show exactly how to edit the hosts file for either a Linux based system or Windows. Once the file is open near the end just add the IP address of the new server and domain name you want your computer to think is at that server.
[bash]
127.0.0.1 localhost
#Add IP address and domain name after the localhost line.
173.254.38.123 zaphinath.com
173.254.38.123 www.zaphinath.com
[/bash]
Now anytime I want to go to zaphinath.com my browser will send me to 173.254.38.123 as the IP address of this site.

Mac or Linux

  • Edit /etc/hosts and add the ip address of the server you want to edit the site for and the domain name you want to use to access.
  • Note 1: you will need sudo privileges to edit this file.
  • Note 2: you can use any plain text editor you like to open the file /etc/hosts.

Windows

  • Step 1: Open your Windows start menu, search for the notepad application and then right click the notepad icon.
  • Step 2: Choose “Run as administrator” and then, while using notepad, browse to folder (/windows/system32/drivers/etc) that contains the hosts file.
  • Note 1: If the file doesn’t allow you to edit it, or whenever you save the hosts file it saves as a text file instead; you will need to right click and check the preferences for the file to make sure the read-only option is turned off.

How To Update a Joomla Password Through MySQL

Description

Joomla is a very popular CMS that most webhosts will provide for their customers. This tutorial is designed to be a nice, simple, easy to use visual aid to help reset Joomla passwords through the Cpanel via phpMyAdmin. Since most webhost companies do not support the changing of third party software data, this howto guide should help reseting a Joomla user password.

phpMyAdmin

Step 1: Find the Right Database

Browse to the right directory for your Joomla instaliation and Open configuration.php in any text editor. We do this so we can find the right database name associated with the Joomla installation for which you are trying to reset the password.
[bash]
public $dbtype = ‘mysqli’;
public $host = ‘localhost’;
public $user = ‘username_jml1’;
public $password = ‘SecretPassword’;
public $db = ‘username_jml1’;
public $dbprefix = ‘jml_’;
[/bash]

Step 2: Open phpMyAdmin

  • Log into the CPanel and select phpMyAdmin.
  • Select the appropriate database on the top left of the screen. The database naming schema for most hosts is username_. This is why we want to find the right database to use from step one. For the example we are using username_jml and phpMyAdmin will just show it as _jml. Select _jml
  • There will now be a list of tables in the database. Click jml_users.



Step 3: Edit the User Information

  • Click edit for the user you wish to edit.
  • Now all the information for that user should be showing and all you have to do is change the password.
  • Select MD5 for the password encryption type. MD5 is what Joomla will use by default.
  • Click GO in the bottom left corner of the user section and now the new password should be saved. You can now go to http://yourdomain.com/administrator and log in with the new credentials.

How To Update a WordPress Password Through MySQL

Description

There are plenty of tutorials on how to update a password (password required when you to to http://yourdomain.com/wp-admin) for a WordPress installation through phpMyAdmin, but there are not many that will do it for those who want to be a little bit more robust and try it through a command line. This tutorial is going to show both. First the easy way through phpMyAdmin and then all through command line.

phpMyAdmin

Step 1: Find the Right Database

Log into your cpanel and determine the appropriate database for your WordPress. Browse to the directory where the your WordPress is installed and look for a file called wp-config.php. Open the wp-config.php and look for the lines that look like the following:
[bash]
// ** MySQL settings – You can get this info from your web host ** //
/** The name of the database for WordPress */
define(‘DB_NAME’, ‘username_wrd2’);

/** MySQL database username */
define(‘DB_USER’, ‘username_wrd2’);

/** MySQL database password */
define(‘DB_PASSWORD’, ‘database_user_password’);

/** MySQL hostname */
define(‘DB_HOST’, ‘localhost’);
[/bash]
This shows us that the database name (DB_NAME) is username_wrd2.

Step 2: Open phpMyAdmin.

  • Log into the CPanel and select phpMyAdmin.
  • Select the appropriate database on the top left of the screen. The database naming schema for most hosts is username_. This is why we want to find the right database to use from step one. For the example we are using username_wrd2 and phpMyAdmin will just show it as _wrd2. Select _wrd2
  • There will now be a list of tables in the database. Click wrd2_users.



Step 3: Edit the User Information

Once you click the wp_users link there will be a list of all the users associated with your WordPress. Find the row with the user you want to change the password.

  • Click edit for the user for whom you want to change the password.

  • Now all the information for that user should be showing and all you have to do is change the password.
  • Select MD5 for the password encryption type. MD5 is what WoordPress will use by default.
  • Click GO in the bottom left corner of the user section and now the new password should be saved. You can now go to http://yourdomain.com/wp-admin and log in with the new credentials.

Command Line

Step 1: Connect to the right database.

The wp-config.php file contains the right database, username, and password that are needed in order to log into mysql.
[bash]
mysql -u <username> -h <host> -p
Enter password:
[/bash]

Then from the wp-config.php file we know the database that we want to connect to and thus implement the following command.
[bash]
mysql>use <database>;
[/bash]

Step 2: Show current users and update password for right user.

[bash wraplines=”0″]
mysql> SELECT * FROM wp_users;
+—-+————–+————————————+—————+—————————–+————————-+———————+———————-+————-+————–+
| ID | user_login | user_pass | user_nicename | user_email | user_url | user_registered | user_activation_key | user_status | display_name |
+—-+————–+————————————+—————+—————————–+————————-+———————+———————-+————-+————–+
| 1 | admin | 1fab43ee6db8eeb65a2bd8f5ed354500a5 | admin | youremail@domain.com | http://www.yourdomain.com | 2010-01-11 23:15:05 | Daa5960a123FF55e594be | 0 | John Doe |

+—-+————–+————————————+—————+—————————–+————————-+———————+———————-+————-+————–+
[/bash]
Then all you need to do to update the password in mysql is the following command. Note however, you can choose whatever kind of encryption you would like. For this example I am encoding in an md5sum.
[bash]
mysql>UPDATE wp_users set user_pass=MD5("YourNewPassword") WHERE user_login = "username";
SELECT * FROM wp_users;
[/bash]