Home > Article > Backend Development > How to modify PHP root
With the popularity and development of the Internet, more and more people are beginning to get involved in web development and try to build their own websites. Among them, PHP is a very popular web programming language and is widely used in website development. If you want to modify the root directory of PHP, you may encounter some problems. This article will introduce how to modify PHP root so that you can better use PHP for website development.
1. Why should we modify PHP root
First of all, let’s understand what PHP root is. PHP root refers to the default storage location of the PHP interpreter, which is the installation directory of PHP. Normally, the root path of PHP is /usr/local/php or /usr/local/apache2/php, etc. If you need to place the PHP folder in another location, you need to modify the PHP root.
The main reasons for modifying the PHP root are as follows:
The above three situations require modifying the PHP root. Below, let’s take a look at the specific steps.
2. How to modify PHP root
On a shared host, it is generally not possible to directly modify the Web server software or PHP installation directory. However, users can specify the PHP root through the .htaccess file.
First, in the member center or FTP client, find the .htaccess file in the root directory of the website. If it does not exist, please create a new one.
Then, add the following code in the .htaccess file:
AddHandler application/x-httpd-phpxx.php Action application/x-httpd-phpxx /path/to/phpxx.cgi
Replace xx with the PHP version number you want to use, such as php54, php56, etc. Replace /path/to/ with your actual PHP path, such as /home/username/php.
Next, upload PHP to the new directory, and then allow the PHP interpreter to access this directory. Add the following to the .htaccess file:
<IfModule mod_suphp.c> suPHP_ConfigPath /home/username/ </IfModule>
Replace /home/username/ with your actual PHP installation directory. Note that if the mod_suphp module is not installed on your shared hosting, you will need to contact your website administrator for help installing it.
If you have your own server, you can directly modify the PHP root directory.
First, log in to the server in the terminal.
Then, run the following command:
which php
This command will display the path to the PHP executable file currently used by the system.
Next, run the following command:
locate php.ini
This command will return the path to the PHP configuration file php.ini.
Change the values of the following two lines in the php.ini file to the new PHP root path:
; Unix: "/path1:/path2" ;include_path = ".:/usr/share/php"
;http://php.net/tmp-dir ;upload_tmp_dir =
After the modification is completed, restart the web server or PHP-FPM, the new PHP root The directory becomes effective.
3. Notes
There are some things you need to pay attention to when modifying the PHP root directory.
First, after modifying the PHP root, if you need to reference other PHP files, you must use the correct path to reference them, otherwise it will cause an error that the file cannot be found.
Second, when the PHP root is modified, the original PHP files on the server need to be reconfigured. If you are using shared hosting, you may need to restart the web server or PHP-FPM for the new configuration to take effect.
Third, modifying PHP root requires a certain technical level. If you are not a web development professional, please do not modify the server settings at will to avoid security issues.
4. Summary
In website development, PHP is a very important programming language. Therefore, when using PHP for development, if you need to modify the PHP root, you can follow the method provided in this article. However, there are some things you need to pay attention to when modifying PHP root to avoid errors and security issues.
The above is the detailed content of How to modify PHP root. For more information, please follow other related articles on the PHP Chinese website!