前言
先说一下个人喜好,使用Linux本人还是比较喜欢用putty连接。相关软件包一般喜欢从官网下载,所以以下内容如果没有给出下载链接,请从官网下载。因为国内下载平台太多广告和流氓软件了,即使使用谷歌+去广告插件都防不了。
系统环境:
Centos7+Apache2+PHP7.2+Thinkphp5.1
此次演示是在Vmware Works 14下安装Centos 7进行操作。
操作步骤:
1、安装Centos 7 x86_64系统,基本操作,不赘述。
系统安装完成,首先配置IP。本机IP为:10.0.0.2
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.0.154 netmask 255.255.255.0 broadcast 192.168.0.255
inet6 fe80::88e1:1da7:5fb8:5f47 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:1e:d3:7f txqueuelen 1000 (Ethernet)
RX packets 31264 bytes 43648325 (41.6 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 9181 bytes 647466 (632.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens34: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.0.2 netmask 255.255.255.0 broadcast 10.0.0.255
inet6 fe80::c18d:2835:94df:e18a prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:1e:d3:89 txqueuelen 1000 (Ethernet)
RX packets 1222 bytes 115909 (113.1 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 819 bytes 150559 (147.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
2、配置软件安装源。网上很多教程,或者直接使用默认源,系统会自动选择最快镜像。
3、安装相关开发环境。如果在安装系统时选择了安装 Development Tools环境,则可以跳过。(本人安装选择最小安装)
在安装"Development Tools"时可能会提示没有该软件包,可按照网上的方法解决
[root@localhost ~]# yum grouplist
Loaded plugins: fastestmirror
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
* base: mirrors.dgut.edu.cn
* epel: mirrors.ustc.edu.cn
* extras: mirrors.163.com
* updates: mirrors.163.com
* webtatic: us-east.repo.webtatic.com
Available Environment Groups:
Minimal Install
Compute Node
Infrastructure Server
File and Print Server
Cinnamon Desktop
MATE Desktop
Basic Web Server
Virtualization Host
Server with GUI
GNOME Desktop
KDE Plasma Workspaces
Development and Creative Workstation
Available Groups:
Cinnamon
Compatibility Libraries
Console Internet Tools
Development Tools
Educational Software
Electronic Lab
Fedora Packager
General Purpose Desktop
Graphical Administration Tools
Haskell
LXQt Desktop
Legacy UNIX Compatibility
MATE
Milkymist
Scientific Support
Security Tools
Smart Card Support
System Administration Tools
System Management
TurboGears application framework
Xfce
Done
执行完yum grouplist 后,列表中有"Development Tools" 则可以进行安装。
[root@localhost ~]# yum groupinstall "Development Tools"
缺少的软件包也可以在执行下面步骤的时候,提示缺少时在进行安装。
4、安装HTTP服务。个人喜欢Apache2,也就是系统默认的http服务。
[root@localhost ~]#yum install -y httpd
5、安装PHP7.2。此部分为网上资源,也可使用其它方法
1)、添加PHP源,一般为第三方源。官方镜像默认的源安装的php版本会比较低。
[root@localhost ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
2)、查看是否有PHP7.2安装源。
[root@localhost ~]# yum search php72w
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.dgut.edu.cn
* epel: mirrors.ustc.edu.cn
* extras: mirrors.163.com
* updates: mirrors.163.com
* webtatic: us-east.repo.webtatic.com
============================================================================ N/S matched: php72w ============================================================================
mod_php72w.x86_64 : PHP module for the Apache HTTP Server
php72w-bcmath.x86_64 : A module for PHP applications for using the bcmath library
php72w-cli.x86_64 : Command-line interface for PHP
php72w-common.x86_64 : Common files for PHP
php72w-dba.x86_64 : A database abstraction layer module for PHP applications
php72w-devel.x86_64 : Files needed for building PHP extensions
php72w-embedded.x86_64 : PHP library for embedding in applications
php72w-enchant.x86_64 : Enchant spelling extension for PHP applications
php72w-fpm.x86_64 : PHP FastCGI Process Manager
php72w-gd.x86_64 : A module for PHP applications for using the gd graphics library
php72w-imap.x86_64 : A module for PHP applications that use IMAP
php72w-interbase.x86_64 : A module for PHP applications that use Interbase/Firebird databases
php72w-intl.x86_64 : Internationalization extension for PHP applications
php72w-ldap.x86_64 : A module for PHP applications that use LDAP
php72w-mbstring.x86_64 : A module for PHP applications which need multi-byte string handling
php72w-mysql.x86_64 : A module for PHP applications that use MySQL databases
php72w-mysqlnd.x86_64 : A module for PHP applications that use MySQL databases
php72w-odbc.x86_64 : A module for PHP applications that use ODBC databases
php72w-opcache.x86_64 : An opcode cache Zend extension
php72w-pdo.x86_64 : A database access abstraction module for PHP applications
php72w-pdo_dblib.x86_64 : MSSQL database module for PHP
php72w-pear.noarch : PHP Extension and Application Repository framework
php72w-pecl-apcu.x86_64 : APCu - APC User Cache
php72w-pecl-apcu-devel.x86_64 : APCu developer files (header)
php72w-pecl-geoip.x86_64 : Extension to map IP addresses to geographic places
php72w-pecl-igbinary.x86_64 : Replacement for the standard PHP serializer
php72w-pecl-igbinary-devel.x86_64 : Igbinary developer files (header)
php72w-pecl-imagick.x86_64 : Provides a wrapper to the ImageMagick library
php72w-pecl-imagick-devel.x86_64 : Imagick developer files (header)
php72w-pecl-libsodium.x86_64 : Wrapper for the Sodium cryptographic library
php72w-pecl-memcached.x86_64 : Extension to work with the Memcached caching daemon
php72w-pecl-mongodb.x86_64 : PECL package MongoDB driver
php72w-pecl-redis.x86_64 : Extension for communicating with the Redis key-value store
php72w-pecl-xdebug.x86_64 : PECL package for debugging PHP scripts
php72w-pgsql.x86_64 : A PostgreSQL database module for PHP
php72w-phpdbg.x86_64 : Interactive PHP debugger
php72w-process.x86_64 : Modules for PHP script using system process interfaces
php72w-pspell.x86_64 : A module for PHP applications for using pspell interfaces
php72w-recode.x86_64 : A module for PHP applications for using the recode library
php72w-snmp.x86_64 : A module for PHP applications that query SNMP-managed devices
php72w-soap.x86_64 : A module for PHP applications that use the SOAP protocol
php72w-sodium.x86_64 : Wrapper for the Sodium cryptographic library
php72w-tidy.x86_64 : Standard PHP module provides tidy library support
php72w-xml.x86_64 : A module for PHP applications which use XML
php72w-xmlrpc.x86_64 : A module for PHP applications which use the XML-RPC protocol
Name and summary matches only, use "search all" for everything.
[root@localhost ~]#
当显示查询到有php72w等安装包,表示安装源成功,可以安装PHP72
3)、安装php72相关软件
[root@localhost ~]#yum install -y php72w php72w-cli php72w-fpm php72w-common php72w-devel php72w-odbc php72w-pdo php72w-pdo_dblib
4)、启动PHP
[root@localhost ~]# systemctl enable php-fpm.service
[root@localhost ~]# systemctl start php-fpm.service
6、测试HTTP环境
1) 开启http。将http添加到开机启动项。启动http服务。
[root@localhost ~]# systemctl enable httpd
[root@localhost ~]# systemctl start httpd
2) 在http默认文件目录/var/www/html/下创建test.php文件,编辑该文件输入如下内容,保存并退出。
<?php echo phpinfo(); ?>
3) 使用我最爱的谷歌浏器,在地址栏输入:10.0.0.2/test.php
看到如上信息,说明HTTP 和PHP 安装配置成功。
7、查找php-config位置:/usr/bin/php-config 记住这个文件,下一步make编译时需要用到
[root@localhost ~]# whereis php-config
php-config: /usr/bin/php-config /usr/share/man/man1/php-config.1.gz
8、加入微软源。编译生成 pdo_sqlsrv.so,copy到/usr/lib64/php/modules
[root@localhost ~]# curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssqlrelease.repo
[root@localhost ~]# yum install msodbcsql mssql-tools unixODBC-devel
[root@localhost ~]# wget https://pecl.php.net/package/pdo_sqlsrv/5.6.1
[root@localhost ~]# tar -zxvf pdo_sqlsrv-5.6.1.tgz
[root@localhost ~]# cd pdo_sqlsrv-5.6.1
[root@localhost pdo_sqlsrv-5.6.1]# phpize
[root@localhost pdo_sqlsrv-5.6.1]# ./configure --with-php-config=/usr/bin/php-config
[root@localhost pdo_sqlsrv-5.6.1]# ls
acinclude.m4 config.sub Makefile.fragments pdo_parser.lo
aclocal.m4 configure Makefile.global pdo_sqlsrv.la
autom4te.cache configure.ac Makefile.objects pdo_stmt.cpp
build config.w32 missing pdo_stmt.lo
config.guess CREDITS mkinstalldirs pdo_util.cpp
config.h include modules pdo_util.lo
config.h.in install-sh pdo_dbh.cpp php_pdo_sqlsrv.h
config.log libtool pdo_dbh.lo php_pdo_sqlsrv_int.h
config.m4 LICENSE pdo_init.cpp run-tests.php
config.nice ltmain.sh pdo_init.lo shared
config.status Makefile pdo_parser.cpp template.rc
[root@localhost pdo_sqlsrv-5.6.1]# cd modules/
[root@localhost modules]# ls
pdo_sqlsrv.so
[root@localhost modules]# ls /usr/lib64/php/modules/
bz2.so curl.so ftp.so iconv.so pdo_dblib.so pdo_sqlite.so shmop.so sqlite3.so zip.so
calendar.so exif.so gettext.so json.so pdo_mysql.so pdo_sqlsrv.so simplexml.so tokenizer.so
ctype.so fileinfo.so gmp.so mysqli.so pdo.so phar.so sockets.so xml.so
[root@localhost modules]#
9、在/etc/php.d/目录下(在第6步的3小步可以看到.ini文件路径)下创建新文件:pdo_sqlsvr.ini文件,添加如下内容:
; Enable pdo_sqlsrv extension module
extension=pdo_sqlsrv.so
10、重启HTTP,再对10.0.0.2/test.php测试。看到pdo栏里有sqlsrv,有pdo_sqlsrv项即表示添加成功。
11、将准备已入的TP5.1添加到服务器html中,设置好html文件权限即可享用。
说明:tp5.1中的runtime文件权限需设置为777
[root@localhost ~]# chmod 755 -R /var/www/html/
[root@localhost ~]#chmod 777 -R /var/www/html/tp5.1/runtime
其它说明:网上说方法是直接将对应的php_pdo_sqlsrv_72_nts.so和php_sqlsrv_72_nts.so添加到/usr/lib64/php/modules下,再在php.ini文件中添加
extension=php_pdo_sqlsrv_72_nts.so
extension=php_sqlsrv_72_nts.so
本人使用此方法测试未成功!