php及phpMyAdmin安装与配置
实验环境:CentOS 7
所需包:apr-1.6.5.tar.bz2、apr-util-1.6.1.tar.bz2、libmcrypt-2.5.6.tar.gz、php-5.5.38.tar.gz、phpMyAdmin-4.6.4-all-languages.tar.gz
概要:PHP即“超文本预处理器”,是一种通用开源脚本语言。PHP是在服务器端执行的脚本语言,与C语言类似,是常用的网站编程语言。PHP独特的语法混合了C、Java、Perl以及 PHP 自创的语法。利于学习,使用广泛,主要适用于Web开发领域。
php的安装与配置
安装httpd和php
[root@host01 ~]# yum groupinstall "Development Tools" -y[root@host01 ~]# yum install pcre-devel openssl-devel -y
安装APR
[root@host01 ~]# wget http://mirrors.hust.edu.cn/apache/apr/apr-1.6.5.tar.bz2
apr-1.6.5.tar.bz2[root@host01 ~]# tar xf apr-1.6.5.tar.bz2[root@host01 ~]# cd apr-1.6.5[root@host01 apr-1.6.5]# ./configure --prefix=/usr/local/apr[root@host01 apr-1.6.5]# make && make install[root@host01 apr-1.6.5]# cd ..
安装APR-util
[root@host01 ~]# wget http://mirrors.hust.edu.cn/apache/apr/apr-util-1.6.1.tar.bz2
apr-util-1.6.1.tar.bz2[root@host01 ~]# yum install expat-devel -y[root@host01 ~]# tar xf apr-util-1.6.1.tar.bz2[root@host01 ~]# cd apr-util-1.6.1[root@host01 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr[root@host01 apr-util-1.6.1]# make && make install[root@host01 apr-util-1.6.1]# cd ..
安装httpd并启动测试
[root@host01 ~]# wget http://mirrors.hust.edu.cn/apache/httpd/httpd-2.4.38.tar.bz2[root@host01 ~]# tar xf httpd-2.4.38.tar.bz2[root@host01 ~]# mv apr-1.6.5 httpd-2.4.38/srclib/apr[root@host01 ~]# mv apr-util-1.6.1 httpd-2.4.38/srclib/apr-util[root@host01 ~]# cd httpd-2.4.38
命令配置httpd:
1 | [root@host01 httpd-2.4.38]# ./configure --prefix=/usr/local/apache \ |
[root@host01 httpd-2.4.38]# make && make install[root@host01 httpd-2.4.38]# cd ..
打开httpd配置文件[root@host01 ~]# vi /etc/httpd/httpd.conf
添加内容:ServerName 192.168.100.128:80
启动apache:[root@host01 ~]# /usr/local/apache/bin/apachectl start
启动成功有如下提示:
httpd (pid 42830) already running
注:如若启动失败,可能是端口号冲突导致
解决办法:修改端口,ps -aux|grep nginx查看pid并kill掉
- 安装netstat
yum install net-tools.x86_64 -y- 查看占用80端口的进程
netstat -antp |grep :80- 查看nginx的pid
ps -A |grep nginx- 杀死nginx的所有进程
kill -9 进程号
浏览器输入IP地址访问httpd测试(如若失败请关闭防火墙和SElinux再行测试)
[root@host01 ~]# cp /usr/local/apache/bin/apachectl /etc/init.d/httpd[root@host01 ~]# chmod 700 /etc/init.d/httpd[root@host01 ~]# vi /etc/init.d/httpd
添加如下内容:
1 | #!/bin/sh |
将httpd设置为开机自启动:[root@host01 ~]# chkconfig --add httpd[root@host01 ~]# chkconfig --level 2345 httpd on
配置httpd服务
使用vi新建httpd脚本文件:[root@host01 ~]# vi /etc/profile.d/httpd.sh
1 | #!/bin/bash |
[root@host01 ~]# . /etc/profile.d/httpd.sh
安装php
[root@host01 ~]# yum install libxml2-devel bzip2-devel -y[root@host01~]#wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.6.tar.gz
libmcrypt-2.5.6.tar.gz[root@host01 ~]# tar xf libmcrypt-2.5.6.tar.gz[root@host01 ~]# cd libmcrypt-2.5.6[root@host01 libmcrypt-2.5.6]# ./configure[root@host01 libmcrypt-2.5.6]# make;make install[root@host01 libmcrypt-2.5.6]# cd ..[root@host01 ~]# wget http://am1.php.net/distributions/php-5.5.38.tar.gz
php-5.5.38.tar.gz[root@host01 ~]# tar xf php-5.5.38.tar.gz[root@host01 ~]# cd php-5.5.38
配置php:
1 | [root@host01 php-5.5.38]# ./configure --prefix=/usr/local/php \ |
[root@host01 php-5.5.38]# make && make install[root@host01 php-5.5.38]# yum install –y php-fpm
警告⚠:下列原始文件
php-fpm错误,请直接替换新文件到/etc/init.d/目录下:
点我下载php-fpm[root@host01 php-5.5.38]# cp ./sapi/fpm/init.d.php-fpm.in /etc/init.d/php-fpm[root@host01 php-5.5.38]# chmod +x /etc/init.d/php-fpm[root@host01 php-5.5.38]# chkconfig --add php-fpm[root@host01 php-5.5.38]# chkconfig php-fpm on[root@host01 php-5.5.38]# cd /usr/local/php/etc[root@host01 etc]# cp php-fpm.conf.default php-fpm.conf[root@host01 etc]# service php-fpm start
注:
输出结果 Starting php-fpm done则表示启动成功
配置httpd,使其支持php
[root@host01 etc]# cd /etc/httpd/[root@host01 httpd]# vi httpd.conf
添加如下内容:
1 | AddType application/x-httpd-php .php |
验证php的支持
重启apache和httpd:[root@host01 httpd]# /usr/local/apache/bin/apachectl restart[root@host01 httpd]# service httpd restart[root@host01 httpd]# cd /usr/local/apache/htdocs[root@host01 htdocs]# vi index.php
添加以下内容:
1 | <?php |
浏览器访问192.168.100.128/index.php测试php:
phpMyAdmin安装与配置
概要:phpMyAdmin,一款数据库管理工具,需在php基础上安装配置
下载phpMyAdmin并连接MySQL
[root@host01 ~]# cd /usr/local/apache/htdocs[root@host01htdocs]#wget https://files.phpmyadmin.net/phpMyAdmin/4.6.4/phpMyAdmin-4.6.4-all-languages.tar.gz
phpMyAdmin-4.6.4-all-languages.tar.gz[root@host01 htdocs]# tar xf phpMyAdmin-4.6.4-all-languages.tar.gz[root@host01 htdocs]# ln -sv phpMyAdmin-4.6.4-all-languages phpmyadmin
浏览器访问phpMyAdmin首页:
http://IP地址/phpmyadmin/
修改phpMyAdmin的root密码
[root@host01 ~]# cd /usr/local/apache/htdocs/phpmyadmin/libraries[root@host01 libraries]# vi config.default.php
修改如下内容:
第519行: $cfg[‘Servers’][$i][‘AllowNoPassword’] = true;
注:vim显示行数命令(命令模式下):set number
关闭行数显示:set nonumber
vim快速跳到指定行数命令(命令模式下):go 519
配置后即可从web界面用root用户无密码登录管理界面


再次编辑config.default.php:[root@host01 libraries]# vi config.default.php
修改如下内容:
第251行: $cfg[‘Servers’][$i][‘password’] = ‘123456’;
退出web界面,再使用 root/123456 重新登录,本地mysql数据库已经可以被phpMyAdmin正常显示了

