CentOS7下nginx-181+mysql-5711+php-5533环境的LNMP源码安装
安装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教程有兴趣的朋友有所帮助。

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

热门话题

确认 Nginx 是否启动的方法:1. 使用命令行:systemctl status nginx(Linux/Unix)、netstat -ano | findstr 80(Windows);2. 检查端口 80 是否开放;3. 查看系统日志中 Nginx 启动消息;4. 使用第三方工具,如 Nagios、Zabbix、Icinga。

在云服务器上配置 Nginx 域名的方法:创建 A 记录,指向云服务器的公共 IP 地址。在 Nginx 配置文件中添加虚拟主机块,指定侦听端口、域名和网站根目录。重启 Nginx 以应用更改。访问域名测试配置。其他注意事项:安装 SSL 证书启用 HTTPS、确保防火墙允许 80 端口流量、等待 DNS 解析生效。

启动 Nginx 服务器需要按照不同操作系统采取不同的步骤:Linux/Unix 系统:安装 Nginx 软件包(例如使用 apt-get 或 yum)。使用 systemctl 启动 Nginx 服务(例如 sudo systemctl start nginx)。Windows 系统:下载并安装 Windows 二进制文件。使用 nginx.exe 可执行文件启动 Nginx(例如 nginx.exe -c conf\nginx.conf)。无论使用哪种操作系统,您都可以通过访问服务器 IP

在 Linux 中启动 Nginx 的步骤:检查 Nginx 是否已安装。使用 systemctl start nginx 启动 Nginx 服务。使用 systemctl enable nginx 启用在系统启动时自动启动 Nginx。使用 systemctl status nginx 验证启动是否成功。在 Web 浏览器中访问 http://localhost 查看默认欢迎页面。

可以查询 Nginx 版本的方法有:使用 nginx -v 命令;查看 nginx.conf 文件中的 version 指令;打开 Nginx 错误页,查看页面的标题。

在 Linux 中,使用以下命令检查 Nginx 是否已启动:systemctl status nginx根据命令输出进行判断:如果显示 "Active: active (running)",则 Nginx 已启动。如果显示 "Active: inactive (dead)",则 Nginx 已停止。

如何在 Windows 中配置 Nginx?安装 Nginx 并创建虚拟主机配置。修改主配置文件并包含虚拟主机配置。启动或重新加载 Nginx。测试配置并查看网站。选择性启用 SSL 并配置 SSL 证书。选择性设置防火墙允许 80 和 443 端口流量。

要让 Nginx 运行 Apache,需要:1. 安装 Nginx 和 Apache;2. 配置 Nginx 代理;3. 启动 Nginx 和 Apache;4. 测试配置,确保访问域名后能看到 Apache 内容。另外,需要注意端口号匹配、虚拟主机配置和 SSL/TLS 设置等其他事项。
