With the development of Internet technology, websites have become more and more complex, and the PHP scripting language has become one of the important technologies for website development. When we need to install a PHP environment on a server, we usually need to use some software packages for installation, of which Apache is a common one. Well, in this article, we will introduce the method of installing PHP from Apache package.
Before we start, we need to understand the concepts of Apache and PHP. Apache is a free open source software and one of the most popular web server software on the server side. PHP is a powerful server-side programming language that allows us to write dynamic web content. Now let's take a look at how to install PHP from the Apache package.
Step 1: Download the Apache file package
First, we need to download the Apache file package from Apache’s official website. In this article, we are using Apache version 2.4.46. After the download is complete, we unzip the file package to the /usr/local/ directory on the server.
$ tar -zxvf httpd-2.4.46.tar.gz -C /usr/local/
After decompression is completed, we can see /usr/local/httpd-2.4.46 There is a configure script in the directory.
Step 2: Install Apache
Before installing Apache, we need to install some dependencies, such as APR and APR-util. We can install it through the following command:
$ yum install -y apr apr-util apr-devel apr-util-devel
After the installation is complete, we can start compiling and installing Apache . Before compiling, we need to use the following command to generate the configure script:
$ ./buildconf
After generating the configure script, we can start configuration:
$ ./ configure --prefix=/usr/local/apache --enable-mods-shared=all --enable-ssl --with-mpm=prefork
The --prefix parameter specifies the installation path of Apache , the --enable-mods-shared=all parameter is used to enable all shared modules, the --enable-ssl parameter is used to enable SSL support, and the --with-mpm=prefork parameter is used to enable Prefork MPM. Prefork MPM is an event processing module of Apache that allows multiple requests to be executed concurrently.
After the configuration is complete, we can use the following command to compile and install Apache:
$ make && make install
Apache After the installation is complete, we can use the following command to start Apache:
$ /usr/local/apache/bin/apachectl start
We can also stop Apache using the following command:
$ /usr/local/apache/bin/apachectl stop
Step 3: Download the PHP file package
Before installing the PHP file package, we need to download the PHP file package from the PHP official website. In this article, we are using PHP version 7.4.11. After the download is complete, we unzip the file package to the /usr/local/ directory on the server.
$ tar -zxvf php-7.4.11.tar.gz -C /usr/local/
After decompression is completed, we can see /usr/local/php-7.4.11 There is a configure script in the directory.
Step 4: Install PHP
Before installing PHP, we also need to install some dependencies, such as OpenSSL, OpenSSL-devel and libxml2-devel. We can install it with the following command:
$ yum install -y openssl openssl-devel libxml2-devel
After the installation is complete, we can start configuring and installing PHP. First, we need to configure it using the following command:
$ ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with- mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-mbstring --with-openssl
Among them, the --prefix parameter specifies the installation path of PHP, and the --with-apxs2 parameter is used for configuration The path of Apache, the --with-mysqli and --with-pdo-mysql parameters are used to configure the path of MySQL, the --enable-mbstring parameter is used to enable multi-byte string support, and the --with-openssl parameter is used to enable OpenSSL support.
After the configuration is complete, we can use the following commands to compile and install PHP:
$ make && make install
PHP After the installation is complete, we need to add the following lines of code Go to Apache's configuration file to enable PHP support:
LoadModule php7_module modules/libphp7.so
AddHandler php7-script php
Include conf/httpd-php.conf
Among them, php7_module is the module name of PHP, libphp7.so is the module file name of PHP, php7-script is the processor name of Apache, and httpd-php.conf is the configuration file of PHP.
Step 5: Test PHP
After installing PHP, we need to test to ensure that PHP has been installed successfully. Before testing, we need to restart the Apache service:
$ /usr/local/apache/bin/apachectl restart
After that, we create a file named info.php and add the following Add the code to the file:
After saving the file, upload the file to Apache's DocumentRoot directory and access the file in the browser:
http://your-ip-address/info.php
If we see the PHP information page, it means that PHP has been installed and run successfully.
Summarize
This article details how to install PHP through Apache file package, including downloading and installing Apache file package, downloading and installing PHP file package, and how to test whether PHP is running normally. These methods will serve as a reference if you need to install PHP on your server in the future.
The above is the detailed content of apache file package to install php. For more information, please follow other related articles on the PHP Chinese website!