Lnmp(mysql分离)(nginx 1.13.6+mysql5.5+php5.3)环境一键搭建
如果对运维课程感兴趣,可以在b站上、csdn或微信视频号 上搜索我的账号: 运维实战课程,可以关注我,学习更多免费的运维实战技术视频
在192.168.37.128服务器上:(mysql只到make install即可)nginx默认站点html
1.上传lnmp的安装包
[root@localhost ~]# mkdir /nginx
rz上传nginx 1.13.6源码包到/nginx /目录下
[root@localhost ~]# ls /nginx/
nginx-1.13.6.tar.gz
[root@localhost ~]# mkdir /mysql
rz上传mysql5.5包和cmake包
[root@localhost ~]# ls /mysql/
cmake-2.8.8.tar.gz mysql-5.5.32.tar.gz
[root@localhost ~]# mkdir /php
rz上传php5.3和各依赖包
[root@localhost ~]# ls /php/
libiconv-1.14.tar.gz libmcrypt-2.5.8.tar.gz mhash-0.9.9.9.tar.gz php-5.3.27.tar.gz
2.开发一键安装lnmp平台脚本
[root@localhost ~]# cat lnmp_install.sh
#!/bin/bash
LANG=en_US.UTF-8
#安装nginx1.13.6(单网站域名,在默认站点目录html中)
rpm -q gcc ||yum -y install gcc
rpm -q gcc-c++ || yum -y install gcc-c++
rpm -q openssl-devel || yum -y install openssl-devel
rpm -q zlib-devel || yum -y install zlib-devel
rpm -q pcre-devel || yum -y install pcre-devel
useradd nginx &> /dev/null
cd /nginx/
tar -zxf nginx-1.13.6.tar.gz
cd nginx-1.13.6
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_ssl_module
make && make install
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx
netstat -anptu |grep :80
#安装mysql5.5(单实例)
cd /mysql
#先安装cmake,并安装最后提示运行gmake方式来安装cmake软件
tar -zxf cmake-2.8.8.tar.gz
cd cmake-2.8.8
./configure
gmake
gmake install
cd ..
yum -y install ncurses-devel #安装mysql依赖包
#用cmake软件包安装mysql5.5
groupadd mysql
useradd mysql -s /sbin/nologin -M -g mysql
tar -zxf mysql-5.5.32.tar.gz
cd mysql-5.5.32
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.5.32 \
-DMYSQL_DATADIR=/usr/local/mysql-5.5.32/data \
-DMYSQL_UNIX_ADDR=/usr/local/mysql-5.5.32/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \
-DENABLED_LOCAL_INFILE=ON \
-DWITHOUT_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FAST_MUTEXES=1 \
-DWITH_ZLIB=bundled \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_READLINE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DWITH_DEBUG=0
make && make install
ln -s /usr/local/mysql-5.5.32/ /usr/local/mysql
#安装php5.3
cd /php/ #先安装php所需的图形lib库
yum -y install zlib libxml libjpeg freetype libpng gd curl zlib-devel libxml2-devel libjpeg-turbo-devel freetype-devel \yum -y install libpng-devel gd-devel curl-devel
yum -y install libxslt* #安装普通的依赖包
yum -y install openldap openldap-devel
cp -frp /usr/lib64/libldap* /usr/lib/
#安装那3个依赖包,编译安装的
tar -zxf mhash-0.9.9.9.tar.gz
tar -zxf libiconv-1.14.tar.gz
tar -zxf libmcrypt-2.5.8.tar.gz
cd mhash-0.9.9.9
./configure
make && make install
cd ..
cd libiconv-1.14
./configure
make && make install
cd ..
cd libmcrypt-2.5.8
./configure
make && make install
cd libltdl/
./configure --enable-ltdl-install
make && make install
ln -s /usr/local/lib/libmhash.* /usr/lib
ln -s /usr/local/lib/libmcrypt* /usr/lib
ln -s /usr/local/lib/libiconv.* /usr/lib
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/
#安装php5.3
cd /php/
tar -zxf php-5.3.27.tar.gz
cd php-5.3.27
./configure \
--prefix=/usr/local/php \
--enable-fpm \
--with-mysql=/usr/local/mysql/ \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--enable-mbstring \
--with-config-file-path=/usr/local/php/etc \
--with-iconv-dir=/usr/local/libiconv/ \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr/ \
--enable-xml \
--disable-rpath \
--enable-discard-path \
--enable-safe-mode \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--with-curlwrappers \
--enable-mbregex \
--enable-fastcgi \
--enable-force-cgi-redirect \
--enable-mbstring \
--with-mcrypt \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-ldap \
--with-ldap-sasl \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--enable-short-tags \
--enable-zend-multibyte \
--enable-static \
--with-xsl \
--with-fpm-user=nginx \
--with-fpm-group=nginx
make ZEND_EXTRA_LIBS='-liconv' #编译时,支持编码转换的扩展库
make install
cp php.ini-production /usr/local/php/etc/php.ini #拷贝php配置文件
echo "/usr/local/mysql/lib" >> /etc/ld.so.conf #将mysql的lib库文件目录加入到ldconfig
ldconfig
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf #拷贝fast-cgi动态网页配置文件
#修改fast-cgi配置文件,配置动态网页参数
sed -i '25s#;pid = run/php-fpm.pid#pid = run/php-fpm.pid#g' php-fpm.conf
sed -i '32s#;error_log = log/php-fpm.log#error_log = log/php-fpm.log#g' php-fpm.conf
sed -i '50s#;log_level = notice#log_level = notice#g' php-fpm.conf
sed -i '89s#;daemonize = yes#daemonize = yes#g' php-fpm.conf
cd /php/php-5.3.27/sapi/fpm/
cp init.d.php-fpm /etc/init.d/php-fpm #拷贝启动动态网页的fast-cgi服务脚本
chmod +x /etc/init.d/php-fpm
/etc/init.d/php-fpm start
#修改nginx配置文件,调用fast-cgi动态网页
sed -i '45s#index index.html index.htm#index index.php index.html index.htm#g' /usr/local/nginx/conf/nginx.conf
sed -i '65s#\#location#location#g' /usr/local/nginx/conf/nginx.conf
sed -i '66s#\###g' /usr/local/nginx/conf/nginx.conf
sed -i '67s#\###g' /usr/local/nginx/conf/nginx.conf
sed -i '68s#\###g' /usr/local/nginx/conf/nginx.conf
sed -i '69s#\# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name# fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name#g' /usr/local/nginx/conf/nginx.conf
sed -i '70s#\###g' /usr/local/nginx/conf/nginx.conf
sed -i '71s#\###g' /usr/local/nginx/conf/nginx.conf
echo "<?php phpinfo(); ?>" > /usr/local/nginx/html/index.php
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s stop
/usr/local/nginx/sbin/nginx
/etc/init.d/php-fpm restart
/etc/init.d/mysqld restart
netstat -anptu |grep 80
netstat -anptu |grep 3306
netstat -anptu |grep 9000
wq
3.服务器建立测试连接mysql程序的代码,测试php是否能连接mysql
[root@localhost ~]# cat /usr/local/nginx/html/linkdb.php
<?php
$linkdb=mysql_connect("192.168.37.129","test1","test1"); #mysqL数据库的IP,用户名和密码
if($linkdb){
echo "db ok";
}else{
echo "db no";
}
?>
wq
在192.168.37.128服务器上安装mysql5.5.32
1.上传mysql包
[root@localhost ~]# mkdir /mysql
rz上传mysql5.5包和cmake包
[root@localhost ~]# ls /mysql/
cmake-2.8.8.tar.gz mysql-5.5.32.tar.gz
2.开发安装mysql的脚本
[root@localhost ~]# cat install_mysql
#!/bin/bash
LANG=en_US.UTF-8
#安装编译工具
rpm -q gcc ||yum -y install gcc
rpm -q gcc-c++ || yum -y install gcc-c++
#安装mysql5.5(单实例)
cd /mysql
#先安装cmake,并安装最后提示运行gmake方式来安装cmake软件
tar -zxf cmake-2.8.8.tar.gz
cd cmake-2.8.8
./configure
gmake
gmake install
cd ..
yum -y install ncurses-devel #安装mysql依赖包
#用cmake软件包安装mysql5.5
groupadd mysql
useradd mysql -s /sbin/nologin -M -g mysql
tar -zxf mysql-5.5.32.tar.gz
cd mysql-5.5.32
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.5.32 \
-DMYSQL_DATADIR=/usr/local/mysql-5.5.32/data \
-DMYSQL_UNIX_ADDR=/usr/local/mysql-5.5.32/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \
-DENABLED_LOCAL_INFILE=ON \
-DWITHOUT_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FAST_MUTEXES=1 \
-DWITH_ZLIB=bundled \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_READLINE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DWITH_DEBUG=0
make && make install
ln -s /usr/local/mysql-5.5.32/ /usr/local/mysql
cd ..
\cp -f mysql-5.5.32/support-files/my-small.cnf /etc/my.cnf #拷贝配置文件
echo 'export PATH=/usr/local/mysql/bin:$PATH' >> /etc/profile #配置环境变量
source /etc/profile
chown -R mysql.mysql /usr/local/mysql/data/ #授权数据目录和初始化mysql5.5
chmod -R 1777 /tmp/ #1是粘贴位,授权是防止/tmp权限有问题
cd /usr/local/mysql/scripts/
./mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/ --user=mysql
\cp -f /mysql/mysql-5.5.32/support-files/mysql.server /etc/init.d/mysqld #拷贝启动脚本
chmod +x /etc/init.d/mysqld
/etc/init.d/mysqld start
netstat -anptu |grep 3306
/usr/local/mysql/bin/mysqladmin -u root password '123' #为mysql增加密码,不是修改,初始没密码
chkconfig mysqld on
wq
3.创建一个测试库,供php程序连接mysql
[root@localhost ~]# mysql -uroot -p123
mysql> create database test1; #创建一个库,供php连接mysql
mysql> grant all on test1.* to test1@"%" identified by "test1"; #授权一个用户,供php连接mysql
mysql> flush privileges;
mysql> quit
[root@localhost scripts]# /etc/init.d/mysqld stop
[root@localhost scripts]# /etc/init.d/mysqld start
widows客户端访问服务器页面:
1)能解析php
2)php能够连接mysql
如果对运维课程感兴趣,可以在b站上、csdn或微信视频号 上搜索我的账号: 运维实战课程,可以关注我,学习更多免费的运维实战技术视频
标签:1.13,nginx,mysql5.5,Lnmp,--,usr,mysql,php,local From: https://blog.csdn.net/qq_34953582/article/details/143028156