安装条件:
事前准备
1.关闭防火墙centos7 使用firewalld
systemctl stop firewalld
2.关闭SELinux
vim /etc/selinux/configurations
SELINUX=enforcing #注释掉
SELINUXTYPE=targeted #注释掉
SELINUX=disabled #增加
:wq #保存退出
setenforce 0 #使配置立即生效
源码包放置位置 /lnmp/
链接:https://pan.baidu.com/s/11M72TTjFDxrRTjqei7Uv3A
提取码:ff6c
源码编译位置 /opt/
装软件
cd /lnmp/src/cmake-2.8.7
tar -zxvf cmake-2.8.7.tar.gz
cd cmake-2.8.7
./configure --prefix=/opt/cmake
make #编译
make install #安装
vim /etc/profile 在path路径中增加cmake执行文件路径
export PATH=$PATH:/opt/cmake/bin
source /etc/profile使配置立即生效
问题:tar (child): lbzip2: Cannot exec: No such file or directory 解决方法
安装bzip2 yum -y install bzip2
cd /lnmp/src/
tar -zxvf pcre-8.39.tar.gz
cd pcre-8.39
./configure
mkdir /opt/pcre #创建安装目录
make && make install
cd /lnmp/src/
tar zxvf gd-2.0.36RC1.tar.gz
cd gd-2.0.36RC1
./configure --enable-m4_pattern_allow --prefix=/opt/gd --with-jpeg=/usr/lib --with-png=/usr/lib --with-xpm=/usr/lib --with-freetype=/usr/lib --with-fontconfig=/usr/lib
make #编译
make install #安装
groupadd mysql #添加mysql组
useradd -g mysql mysql -s /sbin/nologin #创建用户mysql并加入到mysql组,不允许mysql用户直接登录系统
mkdir -p /var/mysql/data #创建MySQL数据库存放目录
chown -R mysql:mysql /var/mysql/data #设置MySQL数据库目录权限
tar -zxvf mysql-5.5.28.tar.gz #解压
cd mysql-5.5.28.tar.gz
编译
cmake -DCMAKE_INSTALL_PREFIX=/opt/mysql -DMYSQL_UNIX_ADDR=/opt/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/var/mysql/data -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306
make
make install
问题1:运行cmake命令是出现CMake Error: The source directory does not appear to contain CMakeLists.txt.的错误,是当前文件夹错了,切换到mysql的源代码文件夹
问题2:[mysql]编译安装报错CMake Error: your C compiler: "CMAKE_C_COMPILE
报错大致都是缺少依赖包,安装这些就差不多了 yum install -y git gcc gcc-c++ ncurses-devel bison
rm CMakeCache.txt
问题3:— Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH)
CMake Error at cmake/readline.cmake:82 (MESSAGE):
Curses library not found. Please install appropriate package,
remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
Call Stack (most recent call first):
cmake/readline.cmake:126 (FIND_CURSES)
cmake/readline.cmake:216 (MYSQL_USE_BUNDLED_LIBEDIT)
CMakeLists.txt:250 (MYSQL_CHECK_READLINE)
— Configuring incomplete, errors occurred!
解决方法:
[root@localhost mysql-5.5.11]# rm CMakeCache.txt
[root@localhost mysql-5.5.11]# yum install ncurses-devel
[root@localhost mysql-5.5.11]# yum install bison
[root@localhost mysql-5.5.11]# make && make install
修my.cnf 文件
cd /opt/mysql
cp ./support-files/my-huge.cnf /etc/my.cnf #拷贝配置文件(注意:如果/etc目录下面默认有一个my.cnf,直接覆盖即可)
vim /etc/my.cnf #编辑配置文件,在 [mysqld] 部分增加
datadir = /var/mysql/data #添加MySQL数据库路径
./scripts/mysql_install_db --user=mysql #生成mysql系统数据库
cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld #把Mysql加入系统启动
chmod 755 /etc/init.d/mysqld #增加执行权限
chkconfig mysqld on #加入开机启动
vim /etc/rc.d/init.d/mysqld #编辑
basedir=/opt/mysql #MySQL程序安装路径
datadir=/var/mysql/data #MySQl数据库存放目录
service mysqld start #启动,可能无法写入pid文件,注意将mysql用户权限加入至/usr/local/mysql
chown -R mysql:mysql /opt/mysql
添加环境变量
vim /etc/profile #把mysql服务加入系统环境变量:在最后添加下面这一行
export PATH=$PATH:/opt/cmake/bin:/opt/mysql/bin
source /etc/profile #使配置立即生效
mkdir /var/lib/mysql #创建目录
ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock #添加软链接
mysql_secure_installation #设置Mysql密码,根据提示按Y 回车输入2次密码
/opt/mysql/bin/mysqladmin -u root -p password "123456" #或者直接修改密码
到此,mysql安装完成!
测试mysql(最后全部装完的)
";
echo "";
echo "编号 姓名 性别 状态 操作 ";
while($row = mysqli_fetch_assoc($obj)){
echo "";
echo ''.$row['id'].' ';
echo ''.$row['name'].' ';
echo ''.$row['sex'].' ';
echo ''.$row['state'].' ';
echo '删除/修改 ';
echo " ";
}
echo "
";
echo "添加";
echo "";
//关闭连接
mysqli_close($conn);
?>
cd /lnmp/src
tar -zxvf nginx-1.11.5.tar.gz
cd /lnmp/src/
tar -zxvf openssl-1.1.0b.tar.gz
cd nginx-1.11.5
./configure --prefix=/opt/nginx --without-http_memcached_module --with-http_stub_status_module --with-openssl=/lnmp/src/openssl-1.1.0b --with-pcre=/lnmp/src/pcre-8.39 --with-http_ssl_module
注意:--with-pcre=/lnmp/src/pcre-8.39指向的是源码包解压的路径,而不是安装的路径,否则会报错
make
make install
/opt/nginx/sbin/nginx #启动nginx
设置开机启动
vi /etc/rc.d/init.d/nginx #编辑启动文件添加下面内容
=======================================================
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
# It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /opt/nginx/conf/nginx.conf
nginxd=/opt/nginx/sbin/nginx
nginx_config=/opt/nginx/conf/nginx.conf
nginx_pid=/opt/nginx/logs/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo "nginx already running...."
exit 1
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginxc daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /opt/nginx/logs/nginx.pid
}
reload() {
echo -n $"Reloading $prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit 1
esac
exit $RETVAL
=======================================================
:wq! #保存退出
chmod 775 /etc/rc.d/init.d/nginx #赋予文件执行权限
chkconfig nginx on #设置开机启动
/etc/rc.d/init.d/nginx restart #重新启动Nginx
service nginx restart
=======================================================
问题:手动重启nginx()
ps -ef|grep nginx 查看nginx进程
强制杀死进程
kill -9 pid
cd /lnmp/src
tar -jxvf php-7.0.7.tar.bz2
cd php-7.0.7
./configure --prefix=/opt/php7 --with-config-file-path=/opt/php7/etc --with-mysqli=/opt/mysql/bin/mysql_config --enable-mysqlnd --with-mysql-sock=/opt/mysql/mysql.sock --with-gd --with-iconv --with-zlib --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --with-curl --with-jpeg-dir --with-freetype-dir --with-pdo-mysql=/opt/mysql/
make #编译,,若遇到make: *** [ext/fileinfo/libmagic/apprentice.lo] 错误 ,这加参数–-disable-fileinfo
make install #安装
cd /lnmp/src/php-7.0.7
cp php.ini-production /opt/php7/etc/php.ini #复制php配置文件到安装目录
rm -rf /etc/php.ini #删除系统自带配置文件
ln -s /opt/php7/etc/php.ini /etc/php.ini #添加软链接
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
cp /opt/php7/etc/php-fpm.conf.default
/opt/php7/etc/php-fpm.conf #拷贝模板文件为php-fpm配置文件
#cp /opt/php7/etc/php-fpm.d/www.conf.default /opt/php7/etc/php-fpm.d/www.conf
#vim /opt/php7/etc/php-fpm.d/www.conf #编辑
#user = www #设置php-fpm运行账号为www
#group = www #设置php-fpm运行组为www
vim /opt/php7/etc/php-fpm.conf
pid = run/php-fpm.pid #取消前面的分号
加入服务并开机启动 ,设置 php-fpm开机启动
cp /lnmp/src/php-7.0.7/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm #拷贝php-fpm到启动目录
chmod +x /etc/rc.d/init.d/php-fpm #添加执行权限
chkconfig php-fpm on #设置开机启动
vim /opt/nginx/conf/nginx.conf
#user www www; #首行user去掉注释,修改Nginx运行组为www www;必须与/opt/php/etc/php-fpm.conf中的user,group配置相同,否则php运行出错
#user www www;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
root html;
index index.php;
##注释去掉 改$document_root
location ~ [^/]\.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
#mkdir -p /data/www
#chown www:www /data/www/ -R #设置目录所有者
#chmod 700 /data/www -R #设置目录权限
参考 https://www.cnblogs.com/zhyunfe/p/6737124.html
##############################defind functions that install lnmp....######################
#######nginx##########################
Install_nginx()
{
yum -y install wget
echo -e "\033[33m Install nginx....\033[0m"
if [ -d /opt/nginx ];then
echo -e "\033[33m Nginx alerady exists in your system......\033[0m"
exit
fi
echo -e "\033[33m Install base environment of nginx......\033[0m"
yum -y install pcre* openssl*
echo -e "\033[33mDownload nginx(1.10.1)....\033[0m"
if [ ! -f /opt/src/nginx-1.10.1.tar.gz ];then
wget http://nginx.org/download/nginx-1.10.1.tar.gz -P /opt/src
fi
cd /opt/src/
tar -zxvf nginx-1.10.1.tar.gz
cd nginx-1.10.1
echo -e "\033[33m Compose nginx......\033[0m"
./configure --prefix=/opt/nginx --conf-path=/opt/conf/nginx/nginx.conf --error-log-path=/opt/logs/nginx/error.log --http-log-path=/opt/logs/nginx/access.log --with-http_stub_status_module --with-http_gzip_static_module --with-http_flv_module --with-http_ssl_module --with-http_realip_module --http-client-body-temp-path=/opt/nginx/client_body_temp --http-fastcgi-temp-path=/opt/nginx/fastcgi_temp --http-proxy-temp-path=/opt/nginx/proxy_temp --http-uwsgi-temp-path=/opt/nginx/uwsgi_temp --http-scgi-temp-path=/opt/nginx/scgi_temp
make
make install
if [ $? -eq "0" ];then
echo -e "\033[32m Nginx is installed successfully......\033[0m"
else
echo -e "\033[31m Something was wrong during installing nginx,please check and try again......\033[0m"
exit
fi
}
######mysql############################
Install_mysql()
{
yum -y install wget
#Removing default rpm packages of mysql if they have been installed....
if [ -f /usr/bin/mysqld_safe ];then
echo -e "\033[33m Remove default mysql-server RPM packages......\033[0m"
yum -y remove mysql-server
fi
if [ -f /usr/bin/mysqldump ];then
echo -e "\033[33m Remove default mysql-client RPM packages......\033[0m"
yum -y remove mysql
fi
#Adding mysql's user and group..
groupadd mysql #添加mysql组
useradd -g mysql mysql -s /sbin/nologin #创建用户mysql并加入到mysql组,不允许mysql用户直接登录系统
if [ ! -d /opt/data/mysql ];then
mkdir -p /opt/data/mysql
fi
echo -e "\033[33m Setting Environment variables......\033[0m"
#Download mysql and install
if [ ! -d /opt/src/mysql-5.6.32/ ];then
if [ ! -f /opt/src/mysql-5.6.32.tar.gz ];then
wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.32.tar.gz -P /opt/src/
fi
cd /opt/src/
tar -zxvf /opt/src/mysql-5.6.32.tar.gz
fi
cd /opt/src/mysql-5.6.32
yum install -y gcc gcc-c++ make automake ncurses-devel
if [ ! -d /opt/src/cmake-3.12.0-rc1/ ];then
if [ ! -f /opt/src/cmake-3.12.0-rc1.tar.gz ];then
wget https://cmake.org/files/v3.12/cmake-3.12.0-rc1.tar.gz -P /opt/src/
fi
cd /opt/src/
tar -zxvf cmake-3.12.0-rc1.tar.gz
cd cmake-3.12.0-rc1
./configure --prefix=/opt/cmake
make
make install
sed -i '$a\export PATH=$PATH:/opt/cmake/bin' /etc/profile
source /etc/profile #使配置立即生效
cd /opt/src/mysql-5.6.32
rm CMakeCache.txt
fi
cmake . -DCMAKE_INSTALL_PREFIX=/opt/mysql/ -DMYSQL_DATADIR=/opt/data/mysql/ -DMYSQL_UNIX_ADDR=/opt/data/mysql/mysql.sock -DWITH_INNOBASE_STORAGE_ENGINE=1 -DMYSQL_TCP_PORT=3306 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_DEBUG=0
if [ "$?" -ne "0" ];then
echo -e 'Configure mysql failure,Please check compile Environment...'
exit 2
fi
make -j 3
if [ "$?" -ne "0" ];then
echo 'Error,please look config.log for more information...'
exit 2
fi
make install
if [ "$?" -eq "0" ];then
echo -e 'Mysql install complete done...'
else
echo -e 'Something wrong between Installation...'
fi
#Initialization mysql..
echo -e 'Initialization mysql...'
cd /opt/src/mysql-5.6.32
cp support-files/my-default.cnf /opt/data/mysql/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
sed -i -e '46s/basedir=/basedir=\/opt\/mysql\//' -e '47s/datadir=/datadir=\/opt\/data\/mysql\//' /etc/init.d/mysqld
chmod a+x /etc/init.d/mysqld
chkconfig --add mysqld
sed -i -e "s#@HOSTNAME@#hostname#" ./scripts/mysql_install_db.sh
sh ./scripts/mysql_install_db.sh --user=mysql --basedir=/opt/mysql/ --datadir=/opt/data/mysql/ > /dev/null 2>&1
chown -R mysql:mysql /opt/mysql/
chown -R mysql:mysql /opt/data/mysql/
#Start mysql...
ulimit -s unlimited
service mysqld start
}
#######php###########################################################
Install_php()
{
yum -y install wget
if [ ! -f /opt/src/php-5.6.36.tar.gz ];then
echo -e "\033[33m Download php-5.6.10.tar.bz......\033[0m"
wget 192.168.0.85/lnmp/php-5.6.36.tar.gz -P /opt/src
cd /opt/src
else
cd /opt/src
fi
echo -e "\033[33m Complising and installing php-5.6.36 ......\033[0m"
tar -zxvf php-5.6.36.tar.gz
cd php-5.6.36
yum -y install epel-release #扩展包更新包
yum update #更新yum源
yum -y install freetype-devel libpng libpng-devel php-mcrypt libmcrypt-devel libjpeg-turbo-devel.x86_64 libxml2 libxml2-devel curl curl-devel
#./configure --prefix=/opt/php --with-config-file-path=/opt/php/etc --with-mcrypt=/usr/include --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-xml --enable-inline-optimization --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-curl --with-jpeg-dir --with-freetype-dir --enable-opcache
./configure --prefix=/opt/php --with-config-file-path=/opt/php/etc --with-mysqli=/opt/mysql/bin/mysql_config --enable-mysqlnd --with-mysql-sock=/opt/mysql/mysql.sock --with-gd --with-iconv --with-zlib --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --with-curl --with-jpeg-dir --with-freetype-dir --with-pdo-mysql=/opt/mysql/
if [ "$?" -ne "0" ];then
echo -e "\033[31m Php install faild....Please check and try again....\033[0m"
exit
fi
make && make install
cp php.ini-production /opt/php/etc/php.ini
rm -rf /etc/php.ini
ln -s /opt/php/etc/php.ini /etc/php.ini
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
cp /opt/php/etc/php-fpm.conf.default /opt/php/etc/php-fpm.conf
cp /opt/php/etc/php-fpm.d/www.conf.default /opt/php/etc/php-fpm.d/www.conf
echo "zend_extension=/opt/php/lib/php/extensions/no-debug-non-zts-20151012/opcache.so" >> /opt/php/etc/php.ini
chmod 775 /etc/init.d/php-fpm
echo -e "\033[33m Starting php-frm service......\033[0m"
/etc/init.d/php-fpm start
if [ $? -eq "0" ];then
echo -e "\032[33m PHP installed and started successfully......\033[0m"
else
echo -e "\033[31m PHP installed successfully,but start failed,please check the configuration of php......\033[0m"
fi
}
###############################Main program######################################
mkdir -p /opt/{conf,src,data}
read -p "Which part of lnmp you want to install?(nginx|mysql|php|all):" softwar
case ${softwar} in
nginx)
Install_nginx
;;
mysql)
Install_mysql
;;
php)
Install_php
;;
all)
if [ -d /opt/nginx ];then
echo -e "\033[33m Nginx was already installed in your system...\033[0m"
else
Install_nginx
fi
if [ -d /opt/mysql ];then
echo -e "\033[33m Mysql was already installed in your system...\033[0m"
else
Install_mysql
fi
if [ -d /opt/php ];then
echo -e "\033[33m PHP was already installed in your system...\033[0m"
else
Install_php
sed -i '$a\export PATH=$PATH:/opt/cmake/bin:/opt/php/bin:/opt/mysql/bin' /etc/profile
source /etc/profile #使配置立即生效
fi
;;
*)
echo -e "\033[33m Sorry,please input a right choice\033[0m"
esac