PHP is a popular server-side scripting language that is widely used in web development and system programming due to its ease of use and high performance. In some cases, you need to install PHP from source and manually start the PHP compiler to complete programming and web application deployment. This article will introduce the process of installing PHP from source code and how to start it.
1. Source code installation of PHP
1. Preparation:
Before installing PHP, you need to install the compiler and some related development libraries. You can execute the following command to install these tools:
$ sudo yum install gcc $ sudo yum install libxml2-devel $ sudo yum install openssl-devel $ sudo yum install bzip2-devel $ sudo yum install libcurl-devel $ sudo yum install libjpeg-devel $ sudo yum install libpng-devel $ sudo yum install freetype-devel $ sudo yum install libxslt-devel
2. Download the PHP source code
Download the latest stable version of PHP and extract it to a directory. You can use the following command to complete:
$ wget https://www.php.net/distributions/php-x.x.x.tar.gz $ tar xfz php-x.x.x.tar.gz
3. Compile and install PHP
Next, you need to enter the PHP source code directory and execute the ./configure
command to configure PHP . Verify that the compilation options match the server configuration. Execute the following command:
$ cd php-x.x.x $ ./configure --with-apxs2=/usr/local/apache2/bin/apxs --prefix=/usr/local/php --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --with-zlib --with-zlib-dir --enable-mbstring --enable-zip
--with-apxs2
option specifies the APXS interface of the Apache server, which is used to communicate PHP with Apache. The --prefix
option specifies the PHP installation directory, the --with-mysql
option specifies the MySQL driver used, the --with-openssl
option enables SSL Support, --with-zlib
option turns on zlib library support, --enable-mbstring
option enables multi-byte support, --enable-zip
option Enable zip library support.
After the configuration is completed, execute the make
and make install
commands to compile and install. Execute the following command:
$ make $ sudo make install
2. Start PHP
After the installation is completed, you need to ensure that PHP is accurately installed in the specified directory. Execute the following command:
$ which php /usr/local/php/bin/php
If the output shows /usr/local/php/bin/php
, it means that PHP has been correctly installed in the specified directory.
Next, you need to integrate PHP with the Apache server. Edit Apache's configuration file httpd.conf
and add the following content:
LoadModule php5_module /usr/local/php/lib/php/modules/libphp5.so AddType application/x-httpd-php .php .html
LoadModule
instruction to load the PHP module, and use the AddType
instruction to add the PHP script Compatible with Apache. After changing the configuration file, you need to restart the Apache server and execute the following command:
$ sudo /usr/local/apache2/bin/apachectl restart
At this point, PHP has been successfully installed and started, and can be tested through the browser or command line. If everything goes well, PHP will output the corresponding results.
Summary
Installing PHP from source may require longer time and patience, but it can provide finer control and flexibility for more advanced needs. The main steps to install PHP include preparation, downloading source code, compiling and installing PHP, and integrating PHP with the Apache server. Once the installation is complete, you can test whether PHP starts successfully via a browser or command line.
The above is the detailed content of How to start php installation from source code. For more information, please follow other related articles on the PHP Chinese website!