安装lnmp环境:
环境是CentOS7 最小化安装,安装时选择了Development tools等几个开发工具(具体记不住了)
nginx-1.8.1 mysql-5.7.11 php-5.5.33
要求:
MYSQL和NGINX 的数据文件,日志文件放在/data下
安装目录也需要改成 /data/webserver
一、下载安装包和配置安装依赖环境
设置防火墙开放端口80 3306
# firewall-cmd --z --add-port=80/tcp --permanent
# firewall-cmd --z --add-port=3306/tcp --permanent
# firewall-cmd --reload
配置selinux设置
# vi /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
#SELINUXTYPE=targeted
重启系统
创建安装目录:
#mkdir -p /data/webserver/nginx
#mkdir /data/webserver/mysql
#mkdir /data/webserver/php
#mkdir /data/webserver/src (软件下载目录)
#mkdir /data/mysqldb(mysql数据存放目录)
下载mysql
#wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.11.tar.gz
下载php
#wget http://cn2.php.net/distributions/php-5.5.33.tar.gz
下载 nginx
#wget http://nginx.org/download/nginx-1.8.1.tar.gz
下载cmake(MySQL编译工具)
#wget http://www.cmake.org/files/v2.8/cmake-2.8.8.tar.gz
下载pcre(支持nginx伪静态)
#wget http://sourceforge.net/projects/pcre/files/pcre/8.35/pcre-8.35.tar.gz
下载libmcrypt(PHPlibmcrypt模块)
#wget http://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
下载boost(从MySQL 5.7.5开始Boost库是必需的)
#wget http://downloads.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
#yum -y install make apr* autoconf automake curl-devel gcc gcc-c++ zlib-devel openssl openssl-devel pcre-devel gd kernel keyutils patch perl kernel-headers compat* mpfr cpp glibc libgomp libstdc++-devel ppl cloog-ppl keyutils-libs-devel libcom_err-devel libsepol-devel
libselinux-devel krb5-devel zlib-devel libXpm* freetype libjpeg* libpng* php-common php-gd ncurses* libtool* libxml2 libxml2-devel patch mhash ntp --skip-broken
二、安装mysql
1、解压安装包:
#cd /data/webserver/src
#ls *.tar.gz |xargs -n1 tar zxf
2、安装cmake:
#cd /data/webserver/src/cmake-2.8.8
#./configure
#gmake && gmake install
3、安装mysql:
#cd /data/webserver/src/mysql-5.7.11
#cmake . -DCMAKE_INSTALL_PREFIX=/data/webserver/mysql -DMYSQL_DATADIR=/data/mysqldb -DSYSC -DWITH_BOOST=../boost_1_59_0 -DDOWNLOAD_BOOST=1
#make && make install
4、配置mysql
# groupadd mysql
# useradd -g mysql -s /sbin/nologin mysql
#cp /data/webserver/mysql/support-files/my-default.cnf /etc/my.cnf #拷贝配置文件(注意:/etc目录下面默认有一个my.cnf,直接覆盖即可)
#/data/webserver/mysql/bin/mysqld --initialize --user=mysql --datadir=/data/mysqldb --basedir=/data/webserver/mysql/ --socket=/tmp/mysql.sock#初始化mysql服务器注意会生成mysql密码一串乱码如:q>d,得到密码:A temporary password is generated for root@localhost: q>d,#cp /data/webserver/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld #把Mysql加入系统启动
#chmod 755 /etc/init.d/mysqld #增加执行权限
#chkconfig mysqld on #加入开机启动
#vi /etc/rc.d/init.d/mysqld #编辑
basedir = /data/webserver/mysql #MySQL程序安装路径
datadir = /data/mysqldb #MySQl数据库存放目录
#/etc/init.d/mysqld start #启动
#/data/webserver/mysql/bin/mysql -uroot -p #登陆mysql
>set password=password('zhulong123'); #修改密码
#vi /etc/profile #把mysql服务加入系统环境变量:在最后添加下面这一行
export PATH=$PATH:/data/webserver/mysql/bin
下面这两行把myslq的库文件链接到系统默认的位置,这样你在编译类似PHP等软件时可以不用指定mysql的库文件地址。
#ln -s /data/webserver/mysql/lib/mysql /usr/lib/mysql
#ln -s /data/webserver/mysql/include/mysql /usr/include/mysql
三、安装nginx
1、安装PCRE
#cd /data/webserver/src/pcre-8.35
#./configure --prefix=/data/webserver/pcre
#make && make install
#systemctl enable ntpd.service
#systemctl start ntpd
2、安装nginx
#groupadd www
#useradd -g www www -s /bin/false
#cd /data/webserver/src/nginx-1.8.1
#./configure --prefix=/data/webserver/nginx --without-http_memcached_module --error-log-path=/data/logs/nginx/error.log --http-log-path=/data/logs/nginx/error.log --pid-path=/data/logs/nginx --user=www --group=www --with-http_stub_status_module --with-openssl=/usr/
--with-pcre=/data/webserver/src/pcre-8.35
#make && make install
修改配置文件:
#vi /data/webserver/nginx/conf/nginx.conf
#修改nginx日志文件的目录
user www www;
worker_processes 1;
error_log /data/logs/nginx/error.log;
error_log /data/logs/nginx/error.log notice;
error_log /data/logs/nginx/error.log info;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
3、设置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: /usr/local/nginx/conf/nginx.conf
nginxd=/data/webserver/nginx/sbin/nginx
nginx_c/webserver/nginx/conf/nginx.conf
nginx_pid=/var/run/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 nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /data/logs/nginx/nginx.pid
}
# reload nginx service functions.
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
建立服务文件
# vim /lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/www/lanmps/init.d/nginx start
ExecReload=/www/lanmps/init.d/nginx restart
ExecStop=/www/lanmps/init.d/nginx stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
chmod 775 /etc/rc.d/init.d/nginx
chkconfig nginx on
/etc/rc.d/init.d/nginx restart
service nginx restart
四、安装php
1、安装libmcrypt
#cd /data/webserver/src/libmcrypt-2.5.8
#./configure
#make
#nake install
2、安装PHP
#cd /data/webserver/src/php-5.5.33
#./configure --prefix=/data/webserver/php --with-config-file-path=/data/webserver/php/etc --with-mysql=/data/webserver/mysql --with-mysqli=/data/webserver/mysql/bin/mysql_config --with-mysql-sock=/tmp/mysql.sock --with-gd --with-iconv --with-zlib --enable-xml
--enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip
--enable-soap --with-pear --with-gettext --enable-session --with-mcrypt --with-curl
#make && make install
3、配置php
#cp php.ini-production /data/webserver/php/etc/php.ini #复制php的配置文件
#rm -rf /etc/php.ini
#ln -s /data/webserver/php/etc/php.ini /etc/php.ini
#cp /data/webserver/php/etc/php-fpm.conf.default /data/webserver/php/etc/php-fpm.conf #复制php-fpm的配置文件
#vi /data/webserver/php/etc/php-fpm.conf
user = www #设置php-fpm运行账号为www
group = www #设置php-fpm运行组为www
pid = run/php-fpm.pid #取消前面的分号
#cp /data/webserver/src/php-5.5.33/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 #设置开机启动
#vi /data/webserver/php/etc/php.ini #编辑配置文件
修改为:date.timezone = PRC #设置时区
4、配置nginx支持php
#vi /data/webserver/nginx/conf/nginx.conf #编辑配置文件,需做如下修改
user www www; #首行user去掉注释,修改Nginx运行组为www,www;必须与/usr/local/php5/etc/php-fpm.conf中的user,group配置相同,否则php运行出错
index index.php index.html index.htm; #添加index.php
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
#取消FastCGI server部分location的注释,并要注意fastcgi_param行的参数,改为
$document_root$fastcgi_script_name,或者使用绝对路径
/etc/init.d/nginx restart #重启nginx
五、测试
#cd /data/webserver/nginx/html/ #进入nginx默认网站根目录
#rm -rf /data/webserver/nginx/html/* #删除默认测试页
#vi index.php #编辑
chown www.www /data/webserver/nginx/html/ -R #设置目录所有者
chmod 700 /data/webserver/nginx/html/ -R #设置目录权限
shutdown -r now #重启系统
以上就介绍了CentOS7下nginx-181+mysql-5711+php-5533环境的LNMP源码安装,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
已抢66892个
抢已抢39383个
抢已抢21818个
抢已抢2769个
抢已抢3061个
抢已抢19363个
抢