PHP is a server-side programming language that runs on the server and follows the steps of request processing, script loading, interpretation and execution, and sending responses. Server configuration includes: Apache: using the php.ini configuration file and the mod_php module. Nginx: Use the php-fpm process manager and nginx.conf configuration file.
PHP operating principle and server configuration guide
PHP operating principle
PHP It is a server-side programming language, meaning it runs on the server rather than on the client (such as the user's browser). It follows the following steps:
Server configuration
In order to run PHP efficiently on the server, the web server needs to be configured correctly. The following are the key configuration items:
Apache
Nginx
Practical case
Install Apache and PHP
Run the following command on Ubuntu:
sudo apt update sudo apt install apache2 php php-mysql
Create PHP script
<?php echo "Hello, world!"; ?>
Save the PHP script in the web root directory:
sudo vi /var/www/html/hello.php
Access in the browser PHP script:
http://localhost/hello.php
The output is "Hello, world!".
Adjust php.ini settings
Adjust php.ini settings using the following command:
sudo vi /etc/php/7.4/apache2/php.ini
Add or adjust the desired settings, for example:
max_execution_time = 300
Restart Apache
After applying the changes, restart Apache for the new settings to take effect:
sudo systemctl restart apache2
The above is the detailed content of PHP operating principle and server configuration. For more information, please follow other related articles on the PHP Chinese website!