LAMP(apache2.2/2.4Mysql5.6PHP5.6)LNMPphpMyAdmin源码安装详细步骤及配置
Posted 三花猫SanHuaMao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LAMP(apache2.2/2.4Mysql5.6PHP5.6)LNMPphpMyAdmin源码安装详细步骤及配置相关的知识,希望对你有一定的参考价值。
一、安装前准备
1、安装gcc、gcc-c++编译器
yum -y install gcc gcc-c++ cmake
2、查看防火墙状态,将80、3306端口加入
service iptables status
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT &&
/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT &&
/etc/rc.d/init.d/iptables save
二、安装httpd2.2或httpd2.4
1、安装apr
cd /usr/local/src/lamp &&
tar zxvf /usr/local/src/lamp/apr-1.6.3.tar.gz &&
cd /usr/local/src/lamp/apr-1.6.3 &&
./configure --prefix=/usr/local/apr && make && make install
2、安装apr-util
yum install expat-devel &&
cd /usr/local/src/lamp &&
tar zxvf /usr/local/src/lamp/apr-util-1.5.2.tar.gz &&
cd /usr/local/src/lamp/apr-util-1.5.2 &&
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config && make && make install
3、安装pcre
yum -y install pcre-devel &&
cd /usr/local/src/lamp &&
unzip -o /usr/local/src/lamp/pcre-8.35.zip &&
cd /usr/local/src/lamp/pcre-8.35 &&
./configure --prefix=/usr/local/pcre && make && make install
(一)安装httpd2.2
cd /usr/local/src/lamp &&
tar zxvf /usr/local/src/lamp/httpd-2.2.34.tar.gz &&
cd /usr/local/src/lamp/httpd-2.2.34 &&
./configure --prefix=/usr/local/httpd/ \
--sysconfdir=/etc/httpd/ \
--with-include-apr \
--disable-userdir \
--enable-so \
--enable-defate=shared \
--enable-expires-shared \
--enable-rewrite=shared \
--enable-static-support \
--with-apr=/usr/local/apr/ \
--with-apr-util=/usr/local/apr-util/bin \
--with-ssl \
--with-z &&
make && make install
(二)安装httpd2.4
cd /usr/local/src/lamp &&
tar zxvf /usr/local/src/lamp/httpd-2.4.29.tar.gz &&
cd /usr/local/src/lamp/httpd-2.4.29 &&
./configure --prefix=/usr/local/httpd \
--enable-mods-shared=all \
--enable-deflate \
--enable-speling \
--enable-cache \
--enable-file-cache \
--enable-disk-cache \
--enable-mem-cache \
--enable-so \
--enable-expires=shared \
--enable-rewrite=shared \
--enable-static-support \
--sysconfdir=/etc/httpd \
--with-apr=/usr/local/apr/ \
--with-apr-util=/usr/local/apr-util/ \
--with-pcre=/usr/local/pcre \
--disable-userdir &&
make && make install
4、配置Apache httpd.conf
# 打开配置文件
vim /etc/httpd/httpd.conf
# 修改
#ServerName www.example.com:80 改 ServerName locahost:80
5、配置Apache开机启动
cd /usr/local/httpd/bin &&
cp ./apachect1 /etc/init.d/httpd
修改/etc/init.d/httpd脚本,在开始处#!/bin/bash之后的行后插入
#chkconfig:345 85 15
#description:Start and stop the Apache HTTP Server
# 增加服务
chkconfig --add httpd &&
chkconfig --level 2345 httpd on
测试apache是否安装成功:启动apache
/usr/local/httpd/bin/apachetcl start 或 service httpd start
三、安装mysql
1、安装cmake
cd /usr/local/src/lamp &&
tar -zxvf /usr/local/src/lamp/cmake-3.10.2.tar.gz &&
cd /usr/local/src/lamp/cmake-3.10.2 &&
./configure && make && make install
或直接用yum
yum install -y cmake
2、安装ncurses-devel
yum install -y ncurses-devel
3、创建所需data目录
cd /usr/local/src/ &&
mkdir -p /data/mysql
4、创建mysql用户和mysql组
groupadd mysql
useradd -g mysql mysql
5、cmake编译安装
cd /usr/local/src/lamp &&
tar -zxvf /usr/local/src/lamp/mysql-5.6.35.tar.gz &&
cd /usr/local/src/lamp/mysql-5.6.35 &&
rm -rf CMakeCache.txt &&
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci &&
make && make install
6、拷备配置文件及启动文件到指定目录下
cp /etc/my.cnf /etc/my.cnf.bak &&
rm -rf /etc/my.cnf &&
cd /usr/local/mysql &&
cp support-files/my-default.cnf /etc/my.cnf &&
cp support-files/mysql.server /etc/init.d/mysqld
然后将目录'/usr/local/mysql'的所有者改为mysql:
chown -R mysql:mysql /usr/local/mysql
这时算是已经安装完成了,但是mysql中是没有数据的(即使系统自带的数据都没有),这时需要执行自带脚本,初始化mysql数据:
/usr/local/mysql/scripts/mysql_install_db \
--basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
执行完成后,你会发现/usr/local/mysql/data 目录下多了一些文件,这些就是mysql的数据文件了,然后启动mysql,这时要注意,我们上面指定配置文件位于'/etc'目录下,但
是我们为了方便,想把mysql配置文件放到'/usr/local/mysql/',这时我们需要把'/etc/my.conf'更改一下名称:
mv /etc/my.cnf /etc/my.cnf.bak
这时mysql 在'/etc'目录下找不到,就会到'$basedir'下去找,也就是'/usr/local/mysql/'目录,此时mysql的安装工作算是完了,下面就要启动了,你会发现使用使用:
/usr/local/mysql/bin/mysql start
无法启动,报错为:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
之前笔者怎么弄都不行,即使建立'/var/lib/mysql/mysql.sock' 后来终于知道,原来不是怎么启动的,而是:
/usr/local/mysql/support-files/mysql.server start
然后,测试下:
/usr/local/mysql/bin/mysql -u root
show databases;
更改登录密码:
mysql -u root
use mysql;
update user set password=PASSWORD("这里输入root用户密码") where User='root';
flush privileges;
7、安装phpmyadmin
cd /usr/local/src/lamp &&
tar -zxvf /usr/local/src/lamp/phpMyAdmin-4.7.0-all-languages.tar.gz &&
mv phpMyAdmin-4.7.0-all-languages /usr/local/httpd/htdocs/phpmyadmin &&
cd /usr/local/httpd/htdocs/phpmyadmin &&
cp config.sample.inc.php config.inc.php
编辑config.inc.php
$cfg['blowfish_secret']=''; //这里不可为空 随便填一串字符
$cfg['Servers'][$i]['host'] = 'localhost'; // MySQL hostname or IP address
$cfg['Servers'][$i]['port'] = ''; // MySQL port - leave blank for default port
$cfg['Servers'][$i]['user'] = 'root'; // 填写 MySQL 访问 phpMyAdmin 使用的 MySQL 用户名,默认为 root。
$cfg['Servers'][$i]['password'] = ''; // 填写对应上述 MySQL 用户名的密码
重启httpd和mysql服务
service httpd restart
/usr/local/mysql/support-files/mysql.server restart
访问phpmyadmin
在浏览器输入http://服务器ip/phpmyadmin
四、编译安装PHP
在安装PHP之前,应先安装PHP需要的最新版本库文件,例如libxml2、libmcrypt以及GD2库等文件。安装GD2库是为了让PHP5支 持GIF、PNG和JPEG图片格式,所以在安装GD2库之前还要先安装最新的zlib、libpng、freetype和jpegsrc等库文件。而且中间还会穿插安装一些软件,读者可以按照本节提供的顺序安装。
1、安装libxml2
cd /usr/local/src/lamp &&
tar -zxvf /usr/local/src/lamp/libxml2-2.6.32.tar.gz &&
cd /usr/local/src/lamp/libxml2-2.6.32 &&
./configure --prefix=/usr/local/libxml2 &&
make && make install
2、安装libmcrypt
cd /usr/local/src/lamp &&
tar -zxvf /usr/local/src/lamp/libmcrypt-2.5.7.tar.gz &&
cd /usr/local/src/lamp/libmcrypt-2.5.7 &&
./configure --prefix=/usr/local/libmcrypt &&
make && make install
3、安装zlib
cd /usr/local/src/lamp &&
tar -zxvf /usr/local/src/lamp/zlib-1.2.8.tar.gz &&
cd /usr/local/src/lamp/zlib-1.2.8 &&
./configure &&
make && make install
4、安装libpng
cd /usr/local/src/lamp &&
tar -zxvf /usr/local/src/lamp/libpng-1.6.20.tar.gz &&
cd /usr/local/src/lamp/libpng-1.6.20 &&
./configure --prefix=/usr/local/libpng &&
make && make install
5、安装jpeg
安装GD2库前所需的jpeg库文件,需要自己手动创建安装需要的目录,它们在安装时不能自动创建。命令行如下:
mkdir /usr/local/jpeg6 &&
mkdir /usr/local/jpeg6/bin &&
mkdir /usr/local/jpeg6/lib &&
mkdir /usr/local/jpeg6/include &&
mkdir -p /usr/local/jpeg6/man/man1 &&
cd /usr/local/src/lamp &&
tar -zxvf /usr/local/src/lamp/jpegsrc.v6b.tar.gz &&
cd /usr/local/src/lamp/jpeg-6b &&
./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static &&
make && make install
6、安装freetype
cd /usr/local/src/lamp &&
tar zxvf /usr/local/src/lamp/freetype-2.5.4.tar.gz &&
cd /usr/local/src/lamp/freetype-2.5.4 &&
./configure --prefix=/usr/local/freetype &&
make && make install
7、安装autoconf
cd /usr/local/src/lamp &&
tar zxvf /usr/local/src/lamp/autoconf-2.50.tar.gz &&
cd /usr/local/src/lamp/autoconf-2.50 &&
./configure && make && make install
如果报错提示缺少perl,则安装perl
cd /usr/local/src/lamp &&
tar zxvf perl-5.26.1.tar.gz &&
cd /usr/local/src/lamp/perl-5.26.1 &&
./Configure && make && make install
8、安装GD库
cd /usr/local/src/lamp &&
tar xjvf /usr/local/src/lamp/libgd-2.1.0.tar.bz2 &&
cd /usr/local/src/lamp/libgd-2.1.0 &&
./configure --prefix=/usr/local/gd --with-jpeg=/usr/local/jpep6/ --with-freetype=/usr/local/freetype --with-png=/usr/local/libpng &&
make && make install
9、安装curl
cd /usr/local/src/lamp &&
tar zxvf /usr/local/src/lamp/curl-7.40.0.tar.gz &&
cd /usr/local/src/lamp/curl-7.40.0 &&
./configure --prefix=/usr/local/curl &&
make && make install
10、安装libiconv
cd /usr/local/src/lamp &&
tar zxvf /usr/local/src/lamp/libiconv-1.14.tar.gz &&
cd /usr/local/src/lamp/libiconv-1.14 &&
./configure --prefix=/usr/local/libiconv &&
make && make install
11、安装mhash
cd /usr/local/src/lamp &&
tar zxvf /usr/local/src/lamp/mhash-0.9.9.9.tar.gz &&
cd /usr/local/src/lamp/mhash-0.9.9.9 &&
./configure --prefix=/usr/local/libiconv &&
make && make install
12、安装openssl
cd /usr/local/src/lamp &&
tar zxvf /usr/local/src/lamp/openssl-1.1.0g.tar.gz &&
cd /usr/local/src/lamp/openssl-1.1.0g &&
./config &&
make && make install
13、安装基础扩展关系库
yum install libjpeg-devel libpng-devel freetype-devel perl-devel curl-devel libxml2-devel -y
安装php
cd /usr/local/src/lamp &&
tar -zxvf /usr/local/src/lamp/php-5.6.4.tar.gz &&
cd /usr/local/src/lamp/php-5.6.4 &&
./configure --prefix=/usr/local/php/ \
--with-config-file-path=/usr/local/php/etc/ \
--with-apxs2=/usr/local/httpd/bin/apxs \
--enable-fpm \
--with-zlib \
--with-libxml-dir \
--enable-sockets \
--with-curl \
--with-jpeg-dir \
--with-png-dir \
--with-gd \
--with-iconv-dir=/usr/local/libiconv \
--with-freetype-dir= \
--enable-gd-native-ttf \
--with-xmlrpc \
--with-mhash \
--with-mcrypt=/usr/local/libmcrypt/ \
--with-pear \
--enable-mbstring \
--enable-sysvshm \
--enable-zip \
--with-mysql=/usr/local/mysql/ \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-mysql-sock \
--with-pdo-mysql \
--disable-fileinfo &&
make && make install
编辑PHP配置文件
复制配置文件
cp /usr/local/src/lamp/php-5.6.4/php.ini-production /usr/local/php/etc/php.ini
#编辑配置文件
vim /usr/local/php/etc/php.ini
将php扩展前面的;去掉
设置PHP支持Apache配置文件
vim /etc/httpd/httpd.conf
# 添加php支持。
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
# 添加默认索引页面index.php,再找到“DirectoryIndex”,在index.html后面加上“ index.php”
DirectoryIndex index.html index.php
# 不显示目录结构,找到“Options Indexes FollowSymLinks”,修改为【可省略】
Options FollowSymLinks
# 开启Apache支持伪静态,找到“AllowOverride None”,修改为【可省略】
AllowOverride All
# 保存httpd.conf配置,然后再执行以下两行命令【可省略】
chown -R nobody. /usr/local/httpd/htdocs/
chmod -R 777 /usr/local/httpd/htdocs/
service httpd restart
未完...
以上是关于LAMP(apache2.2/2.4Mysql5.6PHP5.6)LNMPphpMyAdmin源码安装详细步骤及配置的主要内容,如果未能解决你的问题,请参考以下文章
年终福利,PHP7+Apache2.4+MySQL5.6 源码编译安装,环境配置,搭建你自己的LAMP环境
编译安装LAMP环境:httpd-2.4+mysql5.6+php5.5
九周第四次课(2月26日) 11.1 LAMP架构介绍 11.2 MySQLMariaDB介绍 11.3/11.4/11.5 MySQL安装 扩展 mysql5.5源码编译安装
LAMP环境搭建(centos6.9+apache2.4+mysql5.7+php7.1)