LAMP环境搭建与配置 --2020初学者(更新中)

LAMP架构

Linux+Apache(httpd)+MySQL+PHP
三个角色可以在一起,也可以分开(httpd和PHP要在一起)
LAMP环境搭建与配置 --2020初学者(更新中)

Apache和php模块是一个整体、
apache通过php模块和mysql进行访问(动态请求),
apache访问静态文件(静态请求)

mysql是关系型数据库
mariadb为mysql的一个分支
版本:community社区版本、Enterprise企业版、GA(Generally Available)指通用版本等

安装mysql

[[email protected] ~]#cd /usr/local/src
[[email protected] src]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz --下载MySQL包
[[email protected] src]# tar -zxvf mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz --解压
[[email protected] src]# mv mysql-5.6.43-linux-glibc2.12-x86_64 /usr/local/mysql --把解压好的文件移动到创建的/usr/local/mysql目录下
[[email protected] src]# cd /usr/local/mysql/
[[email protected] mysql]# useradd -s /sbin/nologin mysql --创建mysql用户
[[email protected] mysql]# mkdir -p /data/mysql ; chown -R mysql:mysql /data/mysql --创建并给予权限
[[email protected] mysql]# ls -la /data/mysql -查看权限
total 0
drwxr-xr-x. 2 mysql mysql 6 Aug 5 22:04 .
drwxr-xr-x. 3 root root 19 Aug 5 22:04 …
[[email protected] mysql]# yum install -y perl-Module-Install --安装perl环境
[[email protected] mysql]# yum list | grep perl --查看安装的perl的包
[[email protected] mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql --执行脚本
[[email protected] mysql]# cp support-files/my-default.cnf /etc/my.cnf --复制文件
[[email protected] mysql]# vim /etc/my.cnf --编辑配置文件,修改成如下所示
#These are commonly set, remove the # and set as required.
basedir = /usr/local/mysql
datadir = /data/mysql
port = 3306
server_id = 10
socket = /tmp/mysql.sock
[[email protected] mysql]# cp support-files/mysql.server /etc/init.d/mysqld --复制文件
[[email protected] mysql]# vim /etc/init.d/mysqld --修改脚本
basedir=/usr/local/mysql
datadir=/data/mysql
[[email protected] mysql]# chkconfig --add mysqld
[[email protected] mysql]# chkconfig mysqld on --设置开机自启
[[email protected] mysql]# service mysqld start --启动
[[email protected] mysql]# ps -ef |grep mysqld --查看进程
[[email protected] mysql]# netstat -ltunp | grep 3306 --查看端口

安装Apache

Apache是一个基金会的名字,httpd才是我们要安装的包,早期他的名字就叫apache
下载包:
[[email protected] src]# wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.43.tar.gz
[[email protected] src]# wget http://mirrors.hust.edu.cn/apache/apr/apr-1.6.5.tar.gz
[[email protected] src]# wget http://mirrors.hust.edu.cn/apache/apr/apr-util-1.6.1.tar.gz
解压:
[[email protected] src]# tar -zxvf apr-1.6.5.tar.gz
[[email protected] src]# tar -zxvf apr-util-1.6.1.tar.gz
[[email protected] src]# tar -zxvf httpd-2.4.43.tar.gz
1、 安装apr
[[email protected] src]# cd apr-1.6.5
[[email protected] apr-1.6.5]# yum install -y gcc --安装gcc包
[[email protected] apr-1.6.5]# yum install -y libtool*
[[email protected] apr-1.6.5]# ./configure --prefix=/usr/local/apr --执行脚本
[[email protected] apr-1.6.5]# make && make install --安装make
2、安装util-apr
[[email protected] apr-1.6.5]# cd …/apr-util-1.6.1
[[email protected] apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/
[[email protected] apr-util-1.6.1]# yum install -y expat-devel
[[email protected] apr-util-1.6.5]# make && make install --安装make
3、 安装httpd
[[email protected] apr-util-1.6.1]# cd …/httpd-2.4.43
[[email protected] httpd-2.4.43]# yum install -y pcre-devel 安装pcre包
[[email protected] httpd-2.4.43]# cd …
[[email protected] src]# cp -r apr-1.6.5 httpd-2.4.43/srclib/apr
[[email protected] src]# cp -r apr-util-1.6.1 httpd-2.4.43/srclib/apr-util
[[email protected] src]# cd httpd-2.4.43
[[email protected] httpd-2.4.43]# ./configure --prefix=/usr/local/apache2.4 --enable-so --with-pcre --with-included-apr --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
[[email protected] httpd-2.4.43]# make -j4 && make install

安装PHP

[[email protected] local]# cd /usr/local/src/
[[email protected] src]# wget http://cn2.php.net/distributions/php-5.6.30.tar.gz
先安装一些包防止报错
#yum install -y libxml2-devel
#yum install -y openssl openssl-devel
#yum install -y bzip2 bzip2-devel
#yum install -y libpng libpng-devel
#yum install -y freetype freetype-devel
#yum install -y epel-release
#yum install -y libmcrypt-devel
#yum install -y sqlite-devel
#yum install -y oniguruma oniguruma-devel
[[email protected] src]# cd /usr/local/src/php-5.6.30
[[email protected] php-5.6.30]# ./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-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --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 [[email protected] php-7.4.9]# make -j4 && make install
[[email protected] php-5.6.30]# /usr/local/apache2.4/bin/httpd -M --查看是否安装成功
[[email protected] php-5.6.30]# cp php.ini-production /usr/local/php/etc/php.ini --拷贝配置文件