#######安装php依赖
[root@localhost ~]# yum -y install "libtool*"
[root@localhost ~]#yum install -y mysql-devel
[root@localhost ~]#yum install -y freetype-devel
#报错: configure: error: freetype-config not found.
#######php的安装与配置
[root@localhost ~]# cd /usr/local/src/php-7.1.2
[root@localhost php-7.1.2]# ./configure --prefix=/usr/local/php/ --with-config-file-path=/usr/local/php/etc/ --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql/ --with-libxml-dir=/usr/local/libxml2/ --with-jpeg-dir=/usr/local/jpeg/ --with-png-dir=/usr/local/libpng/ --with-freetype-dir=/usr/local/freetype/ --with-gd=/usr/local/gd2/ --with-mcrypt=/usr/local/libmcrypt/ --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-soap --enable-mbstring=all --enable-sockets --with-pdo-mysql=/usr/local/mysql --enable-fpm
报错以及解决方案
- configure: error: wrong mysql library version or lib not found. Check config.log for more information.
将--with-mysqli后面的路径删掉重新执行configure
- configure: error: PDO_MYSQL configure failed, MySQL 4.1 needed. Please check config.log for more information.
将--with-pdo-mysql后面的路径全部删掉重新configure
- 致命错误:X11/xpm.h:没有那个文件或目录 # include <X11/xpm.h>
yum install libXpm-devel
安装libxpm
rpm -ql libXpm-devel
查找它的安装位置
然后在PHP的./configure配置中添加:
--with-xpm-dir=/usr/lib
生成php.ini
cp /lamp/php-5.4.25/php.ini-production /usr/local/php/etc/php.ini
#######测试lamp环境是否搭建成功
shell>vim /usr/local/apache2/etc/httpd.conf
编辑http.conf
- 存在下面这句话说明php已经正确安装成功
LoadModule php7_module modules/libphp7.so - 修改访问权限
<Directory />
AllowOverride none
Require all denied
</Directory>
改为:
<Directory />
AllowOverride none
Require all denied
Require all granted
</Directory>
- 底行模式下/htdocs修改为www目录(你自己的目录)
DocumentRoot "/usr/local/apache2//htdocs" 修改为:
DocumentRoot "/home/www"
<Directory "/usr/local/apache2//htdocs"> 修改为:
<Directory "/home/www"> - 底行模式下/dir_module 添加默认主页index.php
DirectoryIndex index.html index.php - 添加php的模块解析 ,在文档的最底部
AddType application/x-httpd-php .php .phtml .phps
(注意大小写)
mkdir /home/www
cd /home/www
vim index.php
/usr/local/apache2/bin/apachectl stop
/usr/local/apache2/bin/apachectl start
<?php
phpinfo();
?>
然后再本机地址栏输入192.168.3.6,就可以看到php的信息
如若出现
Forbidden
You don't have permission to access / on this server.
则查看/home/www的权限,修改权限
chmod 755 -R /home/www
检查httpd.conf文件是否上述第二条是否修改
vim mysql_test.php
<?php
header("content-type:text/html;charset=utf-8");
$mysqli = new mysqli("localhost","root","root","test");
if($mysqli->connect_errno){
die ("ERROR:".$mysqli->connect_error);
}
$mysqli->set_charset("utf8");
$sql = <<<EOF
CREATE TABLE IF NOT EXISTS user(
id TINYINT UNSIGNED AUTO_INCREMENT KEY,
username VARCHAR(20) NOT NULL
)
EOF;
if(!$mysqli->query($sql)){
echo "创建user表失败,错误信息:".$mysqli->errno.":".$mysqli->error;
}else{
echo "创建user表成功";
}
#######安装mencache
[root@localhost www]# cd /usr/local/src/memcache-3.0.8
[root@localhost memcache-3.0.8]# /usr/local/php/bin/phpize
Configuring for:
PHP Api Version: 20160303
Zend Module Api No: 20160303
Zend Extension Api No: 320160303
[root@localhost memcache-3.0.8]# ./configure --with-php-config=/usr/local/php/bin/php-config && make && make install
安装失败,网上查找发现php7.0跟memcache不兼容还没有解决
另找办法
穷尽一切办法之后发现了 Github的pecl-memcache分支版本
本地下载或者wget命令下载
https://github.com/websupport-sk/pecl-memcache/archive/php7.zip
下载以后解压进入目录
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
安装成功!
编译安装mcrypt
[root@localhost src]# cd php-7.1.2/ext/mcrypt/
[root@localhost mcrypt]# /usr/local/php/bin/phpize
Configuring for:
PHP Api Version: 20160303
Zend Module Api No: 20160303
Zend Extension Api No: 320160303
[root@localhost mcrypt]# ./configure --with-php-config=/usr/local/php/bin/php-config --with-mcrypt=/usr/local/libmcrypt/ && make && make install
提示
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20160303/
复制目录/usr/local/php/lib/php/extensions/no-debug-zts-20160303/
#######修改php配置
[root@localhost mcrypt]# vim /usr/local/php/etc/php.ini
底行模式/extention_dir
; extension_dir = "./" 去掉注释修改为
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-zts-20160303/"
底下另起一行添加
extension="memcache.so";
extension="mcrypt.so";
#######安装memcached
安装依赖包
[root@localhost src]# yum -y install "libevent*"
编译安装
[root@localhost src]# cd memcached-1.4.35
[root@localhost memcached-1.4.35]# ./configure --prefix=/usr/local/memcache
[root@localhost memcached-1.4.35]# make && make install
启动memcache
[root@localhost memcached-1.4.35]# useradd memcache
[root@localhost memcached-1.4.35]# /usr/local/memcache/bin/memcached -umemcache &
#######安装phpmyadmin
[root@localhost memcached-1.4.35]# cd ..
[root@localhost src]# cp -r phpMyAdmin-4.6.6-all-languages /home/www/phpmyadmin
[root@localhost src]# cd /home/www/
[root@localhost www]# ll
总用量 16
-rwxr-xr-x. 1 root root 18 3月 12 17:49 index.php
-rw-r--r--. 1 root root 484 3月 12 18:19 mysql_test.php
drwxr-xr-x. 12 root root 4096 3月 12 19:39 phpmyadmin
[root@localhost www]# cd phpmyadmin/
[root@localhost phpmyadmin]# cp config.sample.inc.php config.inc.php
/* Authentication type /
$cfg['Servers'][$i]['auth_type'] = 'http';
/ Server parameters */
cookie,不大安全,此处修改为http
phpmyadmin提示错误:phpmyadmin基本功能 已禁用等等,致命JS错误等,将phpmyadmin/sql/creat_tables.sql在mysql中执行,建立phpmyadmin的数据库可以解决(旁边有绿色连接点击即可)
好啦, 可以重启一下Apache服务 查看phpinfo是否已经载入插件 ,亦或者是进入浏览器访问phpmyadmin
完结
附加常用功能
- 开启端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --zone=public --add-port=80/tcp --permanent - 设置开机自启动
vim/etc/rc.local
/usr/local/apache/bin/apachectl start
/usr/local/mysql/bin/mysql_safe --user=root &
/usr/local/memcache/bin/memcached -umemcache &
赋予rc.local执行权限
chmod 755 /etc/rc.local - 写入path变量1
vi /etc/profile
# 在profile文件末尾增加两行
PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
export PATH
# 使PATH搜索路径立即生效:
source /etc/profile - 我们不需要修改环境变量也可以实现直接调用安装目录下的程序,比如/usr/local/php7/bin/php
我们可以直接给系统的bin目录下创建一个上面的软连接就可以实现
ln -s /usr/local/php/bin/php /usr/bin/php
类似我们可以定义Apache ln -s /usr/local/apache2/bin/apachectl /usr/bin/httpd
在每次我们重启Apache服务时就可以直接 httpd restart