Linux下安裝PHP7.1並做關聯APACHE處理


1.復制php壓縮包到/usr/local/src

2.解壓

tar -zxvf php-7.1.2.tar.gz

3.編譯安裝(請先安裝apache和mysql)

./configure --prefix=/usr/local/php7 \
 --with-apxs2=/usr/local/apache2/bin/apxs \
 --with-curl \
 --with-freetype-dir \
 --with-gd \
 --with-gettext \
 --with-iconv-dir \
 --with-kerberos \
 --with-libdir=lib64 \
 --with-libxml-dir \
 --with-mysqli \
 --with-openssl \
 --with-pcre-regex \
 --with-pdo-mysql \
 --with-pdo-sqlite \
 --with-pear \
 --with-png-dir \
 --with-xmlrpc \
 --with-xsl \
 --with-zlib \
 --enable-fpm \
 --enable-bcmath \
 --enable-libxml \
 --enable-inline-optimization \
 --enable-gd-native-ttf \
 --enable-mbregex \
 --enable-mbstring \
 --enable-opcache \
 --enable-pcntl \
 --enable-shmop \
 --enable-soap \
 --enable-sockets \
 --enable-sysvsem \
 --enable-xml \
 --enable-zip \
 --enable-maintainer-zts

核心就是配置關聯

--with-apxs2=/usr/local/apache2/bin/apxs

4.如果有編譯錯誤

yum安裝

yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel  pcre-devel openssl openssl-devel curl-devel libxslt-devel

5.make && make install

make && make install

如果有殘留make clean一下

make clean
make
make install
[root@localhost php-7.1.2]# make install
Installing PHP SAPI module:       apache2handler
/usr/local/apache2/build/instdso.sh SH_LIBTOOL='/usr/local/apr/build-1/libtool' libphp7.la /usr/local/apache2/modules
/usr/local/apr/build-1/libtool --mode=install install libphp7.la /usr/local/apache2/modules/
libtool: install: install .libs/libphp7.so /usr/local/apache2/modules/libphp7.so
libtool: install: install .libs/libphp7.lai /usr/local/apache2/modules/libphp7.la
chmod 755 /usr/local/apache2/modules/libphp7.so
[activating module `php7' in /etc/httpd/httpd.conf]
Installing shared extensions:     /usr/local/php7/lib/php/extensions/no-debug-zts-20160303/
Installing PHP CLI binary:        /usr/local/php7/bin/
Installing PHP CLI man page:      /usr/local/php7/php/man/man1/
Installing phpdbg binary:         /usr/local/php7/bin/
Installing phpdbg man page:       /usr/local/php7/php/man/man1/
Installing PHP CGI binary:        /usr/local/php7/bin/
Installing PHP CGI man page:      /usr/local/php7/php/man/man1/
Installing build environment:     /usr/local/php7/lib/php/build/
Installing header files:           /usr/local/php7/include/php/
Installing helper programs:       /usr/local/php7/bin/
  program: phpize
  program: php-config
Installing man pages:             /usr/local/php7/php/man/man1/
  page: phpize.1
  page: php-config.1
Installing PEAR environment:      /usr/local/php7/lib/php/
[PEAR] Archive_Tar    - already installed: 1.4.0
[PEAR] Console_Getopt - already installed: 1.4.1
[PEAR] Structures_Graph- already installed: 1.1.1
[PEAR] XML_Util       - already installed: 1.3.0
[PEAR] PEAR           - already installed: 1.10.1
Wrote PEAR system config file at: /usr/local/php7/etc/pear.conf
You may want to add: /usr/local/php7/lib/php to your php.ini include_path
/opt/php-7.1.2/build/shtool install -c ext/phar/phar.phar /usr/local/php7/bin
ln -s -f phar.phar /usr/local/php7/bin/phar
Installing PDO headers:           /usr/local/php7/include/php/ext/pdo/

6.apache與php的關聯

PHP安裝成功后會在apache的modules目錄下生成一個libphp.so動態庫文件,在apache的配置文件httpd.conf里自動增加一行。

vi /etc/httpd/httpd.conf
LoadModule php7_module        modules/libphp7.so  

在Apache的配置文件httpd.conf的<IfModule mime_module></IfModule>塊里增加一行

AddType application/x-httpd-php .php  

配置index.php為默認執行的文件

<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>

7.重啟apache

可能會出現 Could not reliably determine the server's fully qualified domain name
解決方案:

用記事本打開 httpd.conf

將里面的 #ServerName localhost:80 注釋去掉即可。

再執行 httpd

然后可以通過瀏覽器訪問 http://localhost:80 ,如果頁面顯示 “It works!” ,即表示apache已安裝並啟動成功。

8.查看phpinfo()

這些都是php支持mysql的模塊,不需要跟具體的mysql關聯。

9.寫代碼查看sql連接

$conn=mysqli_connect("127.0.0.1","root","123456");
if($conn){
	echo"ok";
}else{
	echo"error";    
}

附上yum一些指令,避免yum的mysql的干擾!

查詢yum的安裝包

    yum list installed 

查看具體的包信息

    yum info mysql

移除mysql

    yum remove mysql-libs.x86_64

不會影響到自己編譯的mysql


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM