How to start php installation from source code

WBOY
Release: 2023-05-06 11:11:07
Original
2143 people have browsed it

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
Copy after login

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
Copy after login

3. Compile and install PHP

Next, you need to enter the PHP source code directory and execute the./configurecommand 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
Copy after login

--with-apxs2option specifies the APXS interface of the Apache server, which is used to communicate PHP with Apache. The--prefixoption specifies the PHP installation directory, the--with-mysqloption specifies the MySQL driver used, the--with-openssloption enables SSL Support,--with-zliboption turns on zlib library support,--enable-mbstringoption enables multi-byte support,--enable-zipoption Enable zip library support.

After the configuration is completed, execute themakeandmake installcommands to compile and install. Execute the following command:

$ make $ sudo make install
Copy after login

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
Copy after login

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 filehttpd.confand add the following content:

LoadModule php5_module /usr/local/php/lib/php/modules/libphp5.so AddType application/x-httpd-php .php .html
Copy after login

LoadModuleinstruction to load the PHP module, and use theAddTypeinstruction 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
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!