CentOS7--如何搭建LAMP服务环境?

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u011466469/article/details/78308794
1、MySQL高版本5.7及以上安装在CentOS7x64位系统,安装过程在笔记里找;这里不再赘述;

2、安装A(Apache-Httpd),下载地址: http://mirrors.hust.edu.cn/apache/httpd/httpd-2.4.23.tar.gz
在编译安装Apache(httpd-2.4.3)时分别出现了apr not found、APR-util not found、pcre-config for libpcre not found的问题,下面就httpd-2.4.3的这些问题解决来实际操作一把。
http://apr.apache.org/download.cgi  下载apr-1.4.5.tar.gz、apr-util-1.3.12.tar.gz
https://sourceforge.net/projects/pcre/files  下载pcre-8.31.zip 或者 pcre2-10.22.tar.gz

1.解决apr not found问题
[root@localhost bin]# tar -zxf apr-1.5.2.tar.gz
[root@localhost apr-1.5.2]# ./configure --prefix=/usr/local/apr
[root@localhost apr-1.5.2]# make && make install
[root@localhost apr-1.5.2]# make install
2.解决APR-util not found问题
[root@localhost bin]# tar -zxf apr-util-1.5.4.tar.gz
[root@localhost apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util -with-apr=/usr/local/apr/
[root@localhost apr-util-1.5.4]# make && make install
[root@localhost apr-util-1.5.4]# make install
在安装apr-util时,缺少/opt/apr-util-1.5.4/xml/expat/libexpat.la文件 
在当前目录 执行命令:yum search libexpat 即可解决;

3、解决pcre-config for libpcre not found问题
[root@localhost ~]# unzip pcre-8.10.zip [root@localhost ~]# cd pcre-8.10 [root@localhost pcre-8.10]# ./configure --prefix=/usr/local/pcre [root@localhost pcre-8.10]# make && make install
先将支持Apache-httpd的几个程序安装完,之后在安装Apache【反正安装没坏处】
解压Apache:tar -zxvf Apache-httpd-2.4.24.tar.gz
  • md5sum httpd-2.4.23.tar.gz
  • tar zvxf httpd-2.4.23.tar.gz 
  • cd httpd-2.4.23
  • ./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre --enable-modules=all --enable-rewrite  --enable-ssl --with-ssl --enable-cgid --enable-cgi
  • make && make install
  • apr是为上层的应用程序提供一个可以跨越多操作系统平台使用的底层支持接口库
2.4.23Apche之后的编译版本命令有所不同:
(除了指定Apache的安装目录外,还要安装apr、apr-util、pcre,并指定参数)make && make install
因为httpd默认端口:80,已经给tomcat使用了,所以要去安装目录/usr/local/apache/conf/httpd.conf
vim它,修改它的listen:80,变成8082
启动:/usr/local/apache/bin/apachectl start 报错:AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. 
Set the 'ServerName' directive globally to suppress this message
vim httpd.conf 配置文件,增加一行:ServerName  localhost[先配置虚拟机ip]:8081
防火墙开启端口8081,windows可远程访问apachehttpd服务
iptables -I INPUT -p tcp --dport 80 -j ACCEPT
CentOS7防火墙设置:firewall-cmd --zone=public --add-port=8082/tcp --permanent
  防火墙重启: firewall-cmd --reload
•停止Apache:/usr/local/apache/bin/apachectl stop
•重启Apache:/usr/local/apache/bin/apachectl restart
cp /usr/local/apache/bin/apachectl /etc/init.d/httpd #复制服务到服务列表
如果复制没有权限,使用软链接:ln -s /usr/local/apache/bin/apachectl /etc/init.d/httpd
service httpd start / stop restart 启动httpd
chmod 755 /etc/init.d/httpd  
chkconfig --add httpd 报错:service httpd does not support chkconfig
解决办法:打开vi /etc/rc.d/init.d/httpd 添加(#!/bin/sh下面) 
#chkconfig: 2345 10 90
#description: Activates/Deactivates Apache Web Server

3、安装PHP(下载php-5.5-.38.tar.gz)
  • tar zxf php-5.5.38.tar.gz
  • cd php-5.5.38
  • 编译之前,可以先yum下载安装所需的依赖库:yum install -y gcc gdb strace gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel  openssl openssl-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs patch e2fsprogs-devel krb5-devel libidn libidn-devel openldap-devel nss_ldap openldap-clients openldap-servers libevent-devel libevent uuid-devel uuid mysql-devel libfreetype6-dev 
  • ./configure --prefix=/usr/local/php5.5 --with-apxs2=/usr/local/apache/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-libxml-dir  --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif --disable-ipv6 --with-mcrypt 
  • 编译安装php最后报错(需要下载安装相关依赖包):
  • configure: error: xml2-config not found. Please check your libxml2 installation.
  • 还有第二种解决方法比较方便:编译之前,先处理一下mysql的库,默认查找libmysqlclient_r.so,可是mysql默认为libmysqlclient.so,内容完全一样,做个链接即可
  • # cd /usr/local/mysql/lib/mysql/ 
# ln -s libmysqlclient.so.15.0.0 libmysqlclient_r.so
  • make && make install
  • apxs是一个为Apache HTTP服务器编译和安装扩展模块的工具,用于编译一个或多个源程序或目标代码文件为动态共享对象,使之可以用由mod_so提供的LoadModule指令在运行时加载到Apache服务器中

make: *** [sapi/cli/ PHP ] 错误 1
#make clean  
#make
<?php>
phpinfo();
<?>
浏览器打开测试test.php,环境不能解析php代码,访问出现源代码;
修改vim /usr/local/apache/conf/httpd/conf
找到AddType内容
#添加 MIME映射 ,让apache把PHP文件当成代码文件来执行
AddType application/x-httpd-php .php .phtml
重启apache--httpd服务就好了
[so:warn] [pid 3020:tid 139963331409728] AH01574: module php5_module is already loaded, skipping
apache重装php环境,重复加载php5_module模块,编辑apache/conf/httpd.conf 删除即可;
(20014)Internal error (specific information not available): AH00058: Error retrieving pid file logs/httpd.pid
要删除apache/logs/httpd.pid这个进程文件;

猜你喜欢

转载自blog.csdn.net/u011466469/article/details/78308794