CentOS7.4下LAMP环境搭建
2018-12-03 17:20:09   来源:https://blog.csdn.net/weixin_42383409/article/details/84072143   评论:0 点击:

LAMP是Linux Apache MySQL PHP的简写,即把Apache、MySQL以及PHP安装在Linux系统上,组成一个环境来运行PHP的脚本语言,通常是网站。一、安装MySQL1.下载软件包使用免编译二进制包:#cd /usr/local/src/#wge...
LAMP是Linux Apache MySQL PHP的简写,即把Apache、MySQL以及PHP安装在Linux系统上,组成一个环境来运行PHP的脚本语言,通常是网站。
一、安装MySQL
1.下载软件包
使用免编译二进制包:
#cd /usr/local/src/
#wget http://mirrors.163.com/mysql/Downloads/MySQL-5.6/mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz
2.初始化
#tar zxvf mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz
#[ -d /usr/local/mysql ] && mv /usr/local/mysql /usr/local/mysql_old
//此条命令的意思是,如果/usr/local/mysql目录存在,就会执行后边的mv命令,把存在的目录/usr/local/mysql改名为/usr/local/mysql_old
#mv mysql-5.6.39-linux-glibc2.12-x86_64 /usr/local/mysql
#useradd -s /sbin/nologin mysql //建立mysql用户,因为启动mysql需要该用户
#cd /usr/local/mysql
#mkdir -p /data/mysql
#chown -R mysql:mysql /data/mysql //更改权限,避免后边操作出错
#./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
//–user表示定义数据库以哪个用户的身份在运行,–datadir表示定义数据库的安装目录(建议放到大空间的分区上)。
报错:FATAL ERROR:please install the following Perl modules before executing .scripts/mysql_install_db:Data::Dumper,这是因为缺少包perl-Module-Install,使用命令yum install -y perl-Module-Install安装
报错:error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory,使用yum install -y libaio* 安装
3.配置mysql
#cp support-files/my-default.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? y
修改配置文件/etc/my.cnf,如下:
 
[mysqld]
 
innodb_buffer_pool_size = 128M
 
 
log_bin = linux
 
 
basedir = /usr/local/mysql
datadir = /data/mysql
port = 3306
server_id = 128
socket = /tmp/mysql.sock
1
2
3
4
5
6
7
8
9
10
11
12
13
前边的#号去掉
 
然后复制启动脚本文件并修改,如下:
#cp support-files/mysql.server /etc/init.d/mysqld
#chmod 755 /etc/init.d/mysqld
#vim /etc/init.d/mysqld
修改datadir=/data/mysql
设定开机启动并启动mysql
#chkconfig --add mysqld
#chkconfig mysqld on
#service mysqld start
 
#ps aux |grep mysqld //结果大于2行
#netstat -lnp |grep 3306
tcp6 0 0 :::3306 ::😗 LISTEN 15855/mysqld
mysql 安装完成
 
二、Apache安装
#cd /usr/local/src
#wget http://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.37.tar.gz
#wget http://mirrors.cnnic.cn/apache/apr/apr-1.6.5.tar.gz
#wget http://mirrors.cnnic.cn/apache/apr/apr-util-1.6.1.tar.gz
#tar zxvf httpd-2.4.37.tar.gz
#tar zxvf apr-1.6.5.tar.gz
#tar zxvf apr-util-1.6.1.tar.gz
 
安装apr和apr-util
#cd /usr/local/src/apr-1.6.5
./configure --prefix=/usr/local/apr
报错:rm:cannot remove ‘libtoolT’:No Such…………
解决方法:vim configure文件,查找 $ RM"$ cfgfile 注释掉,RM=’$ RM’改为RM=’$RM -f’
#make && make install
#cd /usr/local/src/apr-util-1.6.1
#./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
#make && make install
报错:libtool:lik:cannot find the library………………
解决方法:yum install -y expat-devel
 
安装httpd
#cd /usr/local/src/httpd-2.4.37/
 
./configure \
--prefix=/usr/local/apache2.4 \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util \
--enable-so \
--enable-mods-shared=most
1
2
3
4
5
6
为避免make的时候出错:
#yum install -y pcre pcre-devel
#make
报错:make[2]: [htpasswd] 错误 1
make[2]: 离开目录“/usr/local/src/httpd-2.4.27/support”
make[1]: [all-recursive] 错误 1
make[1]: 离开目录“/usr/local/src/httpd-2.4.27/support”
make: *** [all-recursive] 错误 1
解决方法:
#cd /usr/local/src/
#cp -r apr-1.6.2 /usr/local/src/httpd-2.4.27/srclib/apr
#cd apr-1.6.3
#./configure --prefix=/usr/local/apr
#make && make install
#cp -r apr-util-1.6.0 /usr/local/src/httpd-2.4.27/srclib/apr-util
#cd /usr/local/src/apr-util-1.5.4
#./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
#make && make install
#cd /usr/local/src/httpd-2.4.27/
#make
#make install
Apache安装完成
 
三、安装PHP
#cd /usr/local/src
#wget http://cn2.php.net/distributions/php-5.6.32.tar.bz2
#tar jxvf php-5.6.32.tar.bz2
#cd php-5.6.32
#./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/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 --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif
错误1:error: xml2-config not found. Please check your libxml2 installation.
解决方案:yum install -y libxml2-devel
错误2:error: Cannot find OpenSSL’s <evp.h>
解决方案:yum install -y openssl openssl-devel
错误3:error: Please reinstall the BZip2 distribution
解决方案:yum install -y bzip2 bzip2-devel
错误4:error: jpeglib.h not found.
解决方案:yum install -y libjpeg-devel
错误5:error: png.h not found.
解决方案:yum install -y libpng libpng-devel
错误6:error: freetype-config not found.
解决方案:yum install -y freetype freetype-devel
错误7:error: mcrypt.h not found. Please reinstall libmcrypt.
解决方案:yum install -y epel epel-devel
yum install -y libmcrypt-devel
#make && make install
完成PHP安装
#cp php.ini-production /usr/local/php/etc/php.ini //复制配置文件
 
四、配置httpd支持PHP
#vim /usr/local/apache2.4/conf/httpd.conf
搜索ServerName,把#ServerName www.example.com:80前#去掉
AllowOVerride none
Require all denied //denied 修改为granted
 
AddType application/x-gzip .gz .tgz下边添加AddType application/x-httpd-php .php
 
DirectoryIndex index.html 后边添加index.php
 
五、测试LAMP是否成功
#/usr/local/apache2.4/bin/apachectl -t //配置正常会显示 “Syntax OK”
#/usr/local/apache2.4/bin/apachectl start //启动httpd
#netstat -lnp|grep httpd
//显示:tcp6 0 0 :::80 ::😗 LISTEN 24765/httpd 表示Httpd已经启动
 
测试是否正确解析PHP
#vim /usr/local/apache2.4/htdocs/test.php
写入:
 
<?php
       echo "php解析正常";
?>
1
2
3
:wq 保存脚本后测试
#curl localhost/test.php
php解析正常
说明PHP解析正常
 
到此LAMP环境就搭建好了!
--------------------- 
作者:Joseph.C 
来源:CSDN 
原文:https://blog.csdn.net/weixin_42383409/article/details/84072143 
版权声明:本文为博主原创文章,转载请附上博文链接!

相关热词搜索:CentOS7.4 LAMP

上一篇:查看jdk或jre的版本
下一篇:最后一页

分享到: 收藏
评论排行