CentOS 7.4 build LAMP, LAMP: Linux, Apache, MySQL, PHP

CentOS  7.4 build LAMP, LAMP: Linux, Apache, MySQL, PHP.

Contents: Part install MySQL service part IV of Part preparations for the second part of the installation services to build Apache PHP runtime environment Part V LAMP architecture applications

The first part of the preparations for a: Server: Linux system -CentOS 7.4; IP address: 192.168.80.10 CentOS 7.4 under source compiler environment Detailed installation configuration LAMPClient: The WIN7, for example, a test to verify the results, with the server on the same network segment; IP address: 192.168.80.2

Two: download the compressed package http://httpd.apache.org/download.cgi // http plugin package http compression package http://apr.apache.org/download.cgi // http://mirrors.sohu.com / mysql / // mysql archive http://www.php.net/downloads.php // PHP archive https://www.phpmyadmin.net/ // PHPMyAdmin archive CentOS 7.4 under source compiler environment Detailed installation configuration LAMP//apr-1.6.2.tar .gz and apr-util-1.6.0.tar.gz is httpd2.4 later versions require plug-ins must be installed // phpMyAdmin is a language written using PHP, Web application for MySQL database management system, followed by LAMP after the completed structures for verification.

// will be compressed into the system under linux CentOS 7.4 under source compiler environment Detailed installation configuration LAMP

Three: the firewall and selinux closed CentOS 7.4 under source compiler environment Detailed installation configuration LAMP

The second part of the Apache install a service: Installation compilation tools and plug-ins [root @ localhost ~] # yum -y install \

gcc \ gcc-c++ \ make \ pcre-devel \ expat-devel \ perl

二:解压: [root@localhost ~]# tar xf apr-1.6.2.tar.gz [root@localhost ~]# tar xf apr-util-1.6.0.tar.gz [root@localhost ~]# tar xf httpd-2.4.29.tar.bz2 CentOS 7.4 under source compiler environment Detailed installation configuration LAMP  //将插件放入httpd目录下 [root@localhost ~]# mv apr-1.6.2 httpd-2.4.29/srclib/apr [root@localhost ~]# mv apr-util-1.6.0 httpd-2.4.29/srclib/apr-util

三:配置(自定义个性化配置) [root@localhost ~]# cd httpd-2.4.29 //必须进入安装目录下 [root@localhost httpd-2.4.29]# ./configure \

--prefix=/usr/local/httpd \ //指定将httpd程序安装到/usr/local/httpd目录下 --enable-so \ //启用动态加载模块功能 --enable-rewrite \ //启用网页地址重写功能,用于网站优化及目录迁移 --enable-charset-lite \ //启用字符集支持,以便支持使用各种字符集编码的网页 --enable-cgi //启用CGI脚本程序支持,便于扩展网站的应用访问能力

四:编译及安装 [root@localhost httpd-2.4.29]# make && make install

//将httpd服务添加到系统服务 [root@localhost httpd-2.4.29]# cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd [root@localhost httpd-2.4.29]# vi /etc/init.d/httpd 添加以下两行(注意,“#”不能省略): CentOS 7.4 under source compiler environment Detailed installation configuration LAMP  保存退出 [root@localhost httpd-2.4.29]# chkconfig --add httpd //将httpd加入到SERVICE管理器 [root@localhost httpd-2.4.29]# systemctl daemon-reload //重载系统系统管理器

五:编辑httpd主配置文件 [root@localhost httpd-2.4.29]# vi /usr/local/httpd/conf/httpd.conf 修改以下内容: ServerName www.aa.com 保存退出 CentOS 7.4 under source compiler environment Detailed installation configuration LAMP

//优化执行路径(执行程序文件的原路径不在PATH环境变量中,做个软链接使其可以执行) [root@localhost httpd-2.4.29]# ln -s /usr/local/httpd/conf/httpd.conf /etc/ [root@localhost httpd-2.4.29]# ln -s /usr/local/httpd/bin/* /usr/local/bin/

//检查语法错误 [root@localhost httpd-2.4.29]# httpd –t 或者:[root@localhost httpd-2.4.29]# apachectl –t CentOS 7.4 under source compiler environment Detailed installation configuration LAMP  //查看程序版本 CentOS 7.4 under source compiler environment Detailed installation configuration LAMP

六:启动服务 [root@localhost httpd-2.4.29]# systemctl start httpd [root@localhost httpd-2.4.29]# systemctl enable httpd //将httpd设为开机启动 [root@localhost httpd-2.4.29]# netstat -anpt | grep 80 //查看httpd服务运行状态 CentOS 7.4 under source compiler environment Detailed installation configuration LAMP

七:验证 用WIN7客户端访问服务器 浏览器访问:http://192.168.80.10 CentOS 7.4 under source compiler environment Detailed installation configuration LAMP  验证成功 (注意,网页默认显示内容为:/usr/local/httpd/htdocs/index.html) CentOS 7.4 under source compiler environment Detailed installation configuration LAMP

第三部分 安装MySQL服务 一:安装编译工具与插件 [root@localhost ~]# yum -y install \

ncurses \ ncurses-devel \ bison \ cmake

二:建立数据库程序用户 [root@localhost ~]# useradd -s /sbin/nologin mysql

三:解压mysql安装包 [root@localhost ~]# tar xf mysql-boost-5.7.20.tar.gz -C /opt/ CentOS 7.4 under source compiler environment Detailed installation configuration LAMP

四:配置(个性化配置及优化项目) [root@localhost ~]# cd /opt/mysql-5.7.20/ [root@localhost mysql-5.7.20]# cmake \

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ //定义安装目录 -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \ //连接数据库socket路径 -DSYSCONFDIR=/etc \ //指定初始化参数文件目录(my.cnf) -DSYSTEMD_PID_DIR=/usr/local/mysql \ //数据库目录 -DDEFAULT_CHARSET=utf8 \ //指定默认使用的字符集编码 -DDEFAULT_COLLATION=utf8_general_ci \ //指定默认使用的字符集校对规则,utf8_general_ci是适用于UTF-8字符集的通用规则 -DWITH_INNOBASE_STORAGE_ENGINE=1 \ //支持InnoDB引擎 -DWITH_ARCHIVE_STORAGE_ENGINE=1 \  -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \ //安装支持数据库分区 -DMYSQL_DATADIR=/usr/local/mysql/data \ -DWITH_BOOST=boost \ -DWITH_SYSTEMD=1 (注意:如果在CMAKE的过程中有报错,当报错解决后,需要把源码目录中的 CMakeCache.txt文件删除,然后再重新CMAKE,否则错误依旧)

五:编译及安装 [root@localhost mysql-5.7.20]# make [root@localhost mysql-5.7.20]# make install

//对数据库目录进行权限设置 [root@localhost mysql-5.7.20]# chown -R mysql.mysql /usr/local/mysql/

六:编辑mysql主配置文件 [root@localhost mysql-5.7.20]# vi /etc/my.cnf (里面内容全部删除,替换成以下内容) [client] port = 3306  default-character-set=utf8 socket = /usr/local/mysql/mysql.sock

[mysql] port = 3306 default-character-set=utf8 socket = /usr/local/mysql/mysql.sock

[mysqld] user = mysql basedir = /usr/local/mysql datadir = /usr/local/mysql/data port = 3306 character_set_server=utf8 pid-file = /usr/local/mysql/mysqld.pid socket = /usr/local/mysql/mysql.sock server-id = 1

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES

[root@localhost mysql-5.7.20]# chown mysql:mysql /etc/my.cnf

六:设置环境变量 [root@localhost mysql-5.7.20]# echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile //把这两个路径添加到环境变量中,并放到profile文件中使之开机自运行,否则不生效 [root@localhost mysql-5.7.20]# echo 'export PATH' >> /etc/profile //设为全局变量,使它使用环境更广 [root@localhost mysql-5.7.20]# source /etc/profile //立即生效

七:初始化数据库 [root@localhost ~]# cd /usr/local/mysql/ [root@localhost mysql]# bin/mysqld \

--initialize-insecure \ --user=mysql \ --basedir=/usr/local/mysql \ --datadir=/usr/local/mysql/data

八:添加系统服务 [root@localhost mysql]# cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/ [root@localhost mysql]# systemctl daemon-reload

九:开启mysql服务 [root@localhost mysql]# systemctl start mysqld [root@localhost mysql]# netstat -anpt | grep 3306 //查看服务运行状态 CentOS 7.4 under source compiler environment Detailed installation configuration LAMP [root@localhost mysql]# systemctl enable mysqld //设为开机启动

十:访问数据库操作 [root@localhost mysql]# mysqladmin -u root -p password "abc123"  //给root账号设置密码为abc123 注意:提示输入的是原始密码(原始没有密码,直接回车) [root@localhost mysql]# mysql -u root –p //登录数据库 注意:有密码的加“-p”,如果没有密码不用加“-p” CentOS 7.4 under source compiler environment Detailed installation configuration LAMP  CentOS 7.4 under source compiler environment Detailed installation configuration LAMP  //数据库安装配置成功,退出则输入”quit“

第四部分 搭建PHP运行环境 一:安装编工具及插件 [root@localhost ~]# yum -y install \

libjpeg \ libjpeg-devel \ libpng libpng-devel \ freetype freetype-devel \ libxml2 \ libxml2-devel \ zlib zlib-devel \ curl curl-devel \ openssl openssl-devel (注意:如果安装过程出错,修改下面文件,添加一行) vi /usr/local/httpd/bin/apxs  #!/usr/bin/perl –w

二:解压安装包 [root@localhost ~]# tar xjvf php-7.1.10.tar.bz2

三:配置(个性化配置及优化项目) [root@localhost php-7.1.10]# cd php-7.1.10 [root@localhost php-7.1.10]# ./configure \ --prefix=/usr/local/php \ --with-apxs2=/usr/local/httpd/bin/apxs \ --with-mysql-sock=/usr/local/mysql/mysql.sock \ --with-mysqli \ --with-zlib \ --with-curl \ --with-gd \ --with-jpeg-dir \ --with-png-dir \ --with-freetype-dir \ --with-openssl \ --enable-mbstring \ --enable-xml \ --enable-session \ --enable-ftp \ --enable-pdo \ --enable-tokenizer \ --enable-zip

四:编译与安装 [root@localhost php-7.1.10]# make [root@localhost php-7.1.10]# make install

五:编辑配置文件 [root@localhost php-7.1.10]# cp php.ini-development /usr/local/php/lib/php.ini  //创建配置文件 [root@localhost php-7.1.10]# vi /usr/local/php/lib/php.ini //编辑配置文件 mysqli.default_socket = /usr/local/mysql/mysql.sock //将php与mysql关联 date.timezone = Asia/Shanghai //时区设置 [root@localhost php-7.1.10]# /usr/local/php/bin/php –m //验证安装的模块

六:关联php与apache服务 [root@localhost php-7.1.10]# vi /etc/httpd.conf //编辑Apache配置文件,使httpd支持php网页解析 添加以下两行内容: AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps 修改以下内容: DirectoryIndex index.php index.html //此处注意,php文件必须放前面,优先读取 [root@localhost php-7.1.10]# rm -f /usr/local/httpd/htdocs/index.html //删除默认html文件 [root@localhost php-7.1.10]# vi /usr/local/httpd/htdocs/index.php //编辑php测试网页 添加以下内容(php信息) <?php phpinfo(); ?> 保存退出 [root@localhost php-7.1.10]# systemctl stop httpd  [root@localhost php-7.1.10]# systemctl start httpd //重启httpd服务

七:验证

  1. 用win7访问192.168.80.10 (注意:如果访问不了,用netstat检查httpd运行状态) CentOS 7.4 under source compiler environment Detailed installation configuration LAMP

  2. 测试数据库 [root@localhost ~]# mysql -u root –p //登录数据库(输入上面设置的root密码) CREATE DATABASE myadm; //创建数据库myadm GRANT all ON myadm. TO 'myadm'@'%' IDENTIFIED BY 'admin123'; //授权 GRANT all ON myadm. TO 'myadm'@'localhost' IDENTIFIED BY 'admin123'; flush privileges; //刷新权限 CentOS 7.4 under source compiler environment Detailed installation configuration LAMP  //重启mysql服务 [root@localhost ~]# systemctl restart mysqld

//编辑index.php文件(将里面原来内容删除,添加以下内容) <?php $link=mysqli_connect('192.168.80.40','myadm','admin123'); if($link) echo "<h1>Success!!</h1>"; else echo "Fail!!"; ?>

//重启http服务 [root@localhost ~]# systemctl stop httpd [root@localhost ~]# systemctl start httpd

//用win7访问服务器地址192.168.80.10 CentOS 7.4 under source compiler environment Detailed installation configuration LAMP  //验证成功

第五部分 LAMP架构应用 部署phpMyAdmin系统: phpMyAdmin是一个使用PHP语言编写,用来管理MYSQL数据库的Web应用系统 一:安装phpMyadmin [root@localhost ~]# yum install -y unzip (由于我下载的phpMyadmin是zip格式压缩包,所以要安装unzip命令解压) //解压phpMyadmin [root@localhost ~]# unzip phpMyAdmin-4.7.6-all-languages.zip -d /opt/ [root@localhost ~]# cd /opt/ [root@localhost opt]# mv phpMyAdmin-4.7.6-all-languages /usr/local/httpd/htdocs/myadm //将文件移到apache目录下

二:创建phpMyadmin配置文件 [root@localhost opt]# cd /usr/local/httpd/htdocs/myadm/ [root@localhost myadm]# cp config.sample.inc.php config.inc.php

三:编辑配置文件 [root@localhost myadm]# vi config.inc.php $cfg['Servers'][$i]['host'] = '127.0.0.1'; //把localhost 改成IP 保存退出

四:重启apache服务 [root@localhost myadm]# systemctl stop httpd [root@localhost myadm]# systemctl start httpd

Five: Verify access with win7 http://192.168.80.10/myadm CentOS 7.4 under source compiler environment Detailed installation configuration LAMPenter the root account and password CentOS 7.4 under source compiler environment Detailed installation configuration LAMPverification is successful.

This article permanently updated link address : https://www.linuxidc.com/Linux/2018-03/151133.htm

Guess you like

Origin www.cnblogs.com/xiexun/p/11360742.html