Home  >  Article  >  Backend Development  >  How to compile and install php in centos6.8

How to compile and install php in centos6.8

藏色散人
藏色散人Original
2022-12-15 09:21:314783browse

How to compile and install php in centos6.8: 1. Install dependencies through the "yum -y install" command; 2. Copy the configuration file; 3. Add environment variables; 4. Execute "source /etc/profile" Command; 5. Add auto-start, and then restart the php service.

How to compile and install php in centos6.8

The operating environment of this tutorial: Windows10 system, centos6.8&&php7.1.5 version, Dell G3 computer.

How to compile and install php in centos6.8?

centOS6.8, centOS7 compile and install PHP:

I installed PHP 7 times on centOS, and I concluded that both centOS6.8 and centOS7 can be used Use the method to compile and install PHP. It’s like a long-term illness that makes a good doctor. Don’t worry if you can’t install it at first. You’ll gain experience after installing it a few times.

Installation dependencies:

yum -y install gd-devel zlib-devel libjpeg-devel libpng-devel libiconv-devel freetype-devel libxml2 libxml2-devel openssl openssl-devel curl-devel libxslt-devel libmcrypt-devel mhash mcrypt

Unable to install automatically online Searching for manual installation tutorials, in fact, there is basically nothing wrong.

Enter the local directory: cd /usr/local

Download PHP7.1.5: wget http://am1. php.net/distributions/php-7.1.5.tar.gz

Decompression: tar zxvf php-7.1.5.tar.gz

Enter the decompression directory :cd php-7.1.5

编译:./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-fpm-user=www --with-fpm-group=www --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-jis-conv --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-opcache --with-libmbfl --with-onig --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pdo-mysql --enable-mysqlnd-compression-support --with-pear --enable-maintainer-zts --enable-session --with-gettext

The installation directory is /usr/local/php

After the compilation is completed, you will see: Thank you for using PHP.

Then execute the installation command:

make
make install

Then copy the configuration file (currently still in the php7.1.5 folder, do not use the mv command, these configuration files can still be used in the future and do not delete them):

cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp php.ini-development /usr/local/php/lib/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm(这个很重要)

Add environment variables:

echo 'export PATH=/usr/local/php/bin:/usr/local/php/sbin:$PATH'>> /etc/profile

Load environment variables: source /etc/profile (My habit is to execute this command first after starting the virtual machine, which will avoid a lot of trouble)

Execute At this point, run php -v to see the installed version of PHP

Add auto-start:

chkconfig --add php-fpm
chkconfig php-fpm on
chkconfig --list php-fpm

Add permissions: chmod 755 /etc/init.d/php-fpm

Start PHP:/etc/init.d/php-fpm start

View PHP service status:/etc/init.d/php-fpm status

Stop PHP service :/etc/init.d/php-fpm stop

Restart the php service:/etc/init.d/php-fpm restart

The configuration file of php is /usr/local/php /lib/php.ini can be referenced here if you install extensions in the future.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to compile and install php in centos6.8. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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