PHP安裝__GongWei1997

GongWei1997發表於2020-11-27

準備安裝包

php-7.1.10.tar.bz2

安裝流程

# yum安裝 解決依賴關係
yum -y install \
libjpeg \
libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
libxml2 \
libxml2-devel \
zlib zlib-devel \
curl curl-devel \
openssl openssl-devel

# 解壓縮
tar -jxvf php-7.1.10.tar.bz2

# 配置編譯環境
 php-7.1.10]# ./configure \
--prefix=/usr/local/php \
--with-apxs2=/usr/local/httpd/bin/apxs \
--with-mysql-sock=/usr/local/mysql/mysql.sock \
--with-mysqli \
--with-zlib \
--with-curl \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-openssl \
--enable-mbstring \
--enable-xml \
--enable-session \
--enable-ftp \
--enable-pdo \
--enable-tokenizer \
--enable-zip

# 編譯安裝
make && make install

cp php.ini-development /usr/local/php/lib/php.ini

# 修改PHP配置檔案
vi /usr/local/php/lib/php.ini
	mysqli.default_socket = /usr/local/mysql/mysql.sock		#搜尋/mysqli.default後,修改
	date.timezone = Asia/Shanghai							#搜尋/date.time後,去除“;”,然後修改(PHP文字里的“;”是註釋的意思)

# 驗證php模組是否安裝成功
/usr/local/php/bin/php -m

# 讓apche支援PHP
vi /etc/httpd.conf   //在合適位置新增
#搜尋/AddType後新增
AddType application/x-httpd-php .php //新增.php應用和功能
AddType application/x-httpd-php-source .phps   //新增.phps應用和功能
#搜尋/DirectoryIndex後在“index.php”前新增“index.php”
 DirectoryIndex index.php index.html //預設主頁,優先使php主頁

vi /usr/local/httpd/htdocs/index.php

<?php
phpinfo();
?>

systemctl restart httpd
netstat -anpt | grep httpd  
systemctl status httpd  //出現active,即正常

# 驗證結果
主機訪問網址:http://20.0.0.14#出現PHP主頁(前面指令碼設定了優先)
http://20.0.0.15/index.html #訪問apache主頁

#進入資料庫
mysql -uroot -pqweasd
create database mydam;  //建立一個叫“mydam”的庫
grant all privileges on mydam.* to 'mydam'@'localhost' identified by 'qweasd';
grant all privileges on mydam.* to 'mydam'@'%' identified by 'qweasd';
flush privileges;
exit

vi /usr/local/httpd/htdocs/index.php 

<?php
$link=mysqli_connect('20.0.0.14','myadm','qweasd');  //用php訪問資料庫
if($link) echo "<h1>OK</h1>";
else echo "NO";
?>

安裝phpMyadmin

unzip phpMyAdmin-4.7.6-all-languages.zip 
mv phpMyAdmin-4.7.6-all-languages /usr/local/httpd/htdocs/myadm
cd /usr/local/httpd/htdocs/myadm
cp config.sample.inc.php config.inc.php
vi config.inc.php
	$cfg['Servers'][$i]['host'] = '20.0.0.14’;//把localhost改成IP
#進入資料庫
mysql -uroot -pqweasd
grant all privileges on *.* to 'root'@'client1' identified tified by '123456';
flush privileges; 
#瀏覽器訪問20.0.0.14/myadm即可

相關文章