最新消息:觉得本站不错的话 记得收藏哦 博客内某些功能仅供测试 讨论群:135931704 快养不起小站了 各位有闲钱就打赏下把

Centos7+Mysql/MariaDB+sendMail+Nginx+PHP 环境搭建一条龙

LINX ajiang-tuzi 1214浏览 0评论

安装sendmail

[root@localhost ~]# yum install -y sendmail
[root@localhost ~]# yum -y sendmail-cf
[root@localhost ~]# vi /etc/mail/sendmail.mc
[root@localhost ~]# m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
[root@localhost ~]# echo "test" | sendmail 1050653098@qq.com
[root@localhost ~]# vim /etc/hostname
[root@localhost ~]# hostname service1.com
[root@localhost ~]# hostname 
service1.com
[root@localhost ~]# echo "test" | sendmail 1050653098@qq.com
[root@localhost ~]# mailq
/var/spool/mqueue is empty
		Total requests: 0
您在 /var/spool/mail/root 中有邮件

参考
CentOS安装sendmail及设置 排错 等等。。。。
send mail 拒收 或被列入垃圾箱问题

安装mysql mariadb

[root@localhost ~]# yum install mysql mysql-service
[root@localhost ~]# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
[root@localhost ~]# yum -y install mariadb*
[root@localhost mysql]# systemctl start mariadb.service
[root@localhost mysql]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.44-MariaDB MariaDB Server

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 

参考
Centos7 安装MySql Mariadb

安装mysql mysql

liunx 下 或centos7 下安装 MySQL-5.6

安装PHP

[root@localhost mysql]# rpm -Uvh http://ftp.iij.ad.jp/pub/linux/fedora/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
//备用地址 ftp://fr2.rpmfind.net/linux/centos/7.2.1511/extras/x86_64/Packages/epel-release-7-5.noarch.rpm
[root@localhost mysql]# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
[root@localhost mysql]# yum list --enablerepo=remi --enablerepo=remi-php56 | grep php
[root@localhost mysql]# yum install --enablerepo=remi --enablerepo=remi-php56 php php-opcache php-pecl-apcu php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-pecl-xhprof php-pdo php-pear php-fpm php-cli php-xml php-bcmath php-process php-gd php-common
[root@localhost mysql]# php -v
PHP 5.6.17 (cli) (built: Jan  6 2016 18:56:36) 
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
    with Xdebug v2.3.3, Copyright (c) 2002-2015, by Derick Rethans

PHP 与MYSQL 链接

[root@localhost mysql]# find / -name my.cnf
/etc/my.cnf
[root@localhost mysql]# vim /etc/my.cnf
[VIMCONTENT]
socket=/var/lib/mysql/mysql.sock
[root@localhost mysql]# vim /etc/php.ini
[VIMCONTENT]
; http://php.net/mysql.default-socket
mysql.default_socket =/var/lib/mysql/mysql.sock
[root@localhost mysql]# systemctl restart  php-fpm.service

[root@localhost home]# cd /home

测试 PHP 和mysql 的链接

[root@localhost home]# vim db.php
<?php
mysql_connect('localhost','root','');
mysql_select_db('mysql');
$q=mysql_query("select * from user where user='root' limit 1");
$r=mysql_fetch_assoc($q);
print_r($r);
?>
[root@localhost home]# php db.php
Array
(
    [Host] => localhost
    [User] => root
    [Password] => 
    [Select_priv] => Y
    .................
)

参考与引用
systemctl跟 ip 命令用法

安装NGINX

[root@localhost home]# yum -y install zlib zlib-devel openssl openssl-devel pcre-devel
[root@localhost home]# wget http://nginx.org/download/nginx-1.9.2.tar.gz
[root@localhost home]# tar -zxvf nginx-1.9.2.tar.gz
[root@localhost home]# cd nginx-1.9.2
[root@localhost nginx-1.9.2]# ./configure --help
//添加权限
[root@localhost init.d]# /usr/sbin/groupadd -f nginx
[root@localhost init.d]# /usr/sbin/useradd -g nginx nginx
[root@localhost nginx-1.9.2]# ./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 --with-http_spdy_module --with-cc-opt='-O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'; 
[root@localhost nginx-1.9.2]# make && make install
[root@localhost nginx-1.9.2]# nginx -v
nginx version: nginx/1.9.2

添加 nginx 控制脚本

[root@localhost nginx]# cd /home
[root@localhost home]# vim nginx
[root@localhost home]# mv nginx /etc/init.d/ && cd etc/init.d/ 
[root@localhost init.d]# chkconfig --add nginx
[root@localhost init.d]# chkconfig --list nginx

注意:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。 
      如果您想列出 systemd 服务,请执行 'systemctl list-unit-files'。
      欲查看对特定 target 启用的服务请执行
      'systemctl list-dependencies [target]'。

nginx          	0:关	1:关	2:关	3:关	4:关	5:关	6:关

[root@localhost init.d]#  chmod a+x /etc/init.d/nginx
[root@localhost init.d]# service nginx restart
Restarting nginx (via systemctl):                          [  确定  ]
测试
[root@localhost html]# cd /etc/nginx/html
[root@localhost html]# ls
50x.html  index.html
[root@localhost html]# vim info.html
//浏览器输出
This is  tets page
page from weicot.com

参考与引用
Centos 或 Linux 下安装NGINX 及管理脚本
Linux 下防火墙 Iptables 或 Firewalle 常用命令

NGINX 与 PHP

开放80端口
[root@localhost init.d]# systemctl start firewalld
[root@localhost init.d]# systemctl status  firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since 六 2016-01-16 14:22:21 CST; 1h 57min ago
   ..........................................................
[root@localhost init.d]# firewall-cmd --zone=dmz --add-port=80/tcp
success
[root@localhost init.d]# firewall-cmd --zone=dmz --list-ports
80/tcp
//进入到 nginx 目录
[root@localhost nginx]# cd /etc/nginx/
[root@localhost nginx]# vim nginx.conf
//nginx 配置 请查看代码一
[root@localhost nginx]# systemctl restart nginx.service

PHP 与sendMail 绑定

[root@localhost nginx]# vim /etc/php.ini
; http://php.net/sendmail-path
sendmail_path = /usr/sbin/sendmail -t -i -f root@weicotservice.com
[root@localhost nginx]# systemctl restart php-fpm.service

展示下作品

本来想搭建分布式的 不过这么晚 下次吧
xxxxx
我nginx 的配置 nginx.conf

user  nginx;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # 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;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

转载请注明:(●--●) Hello.My Weicot » Centos7+Mysql/MariaDB+sendMail+Nginx+PHP 环境搭建一条龙

发表我的评论
取消评论
*
表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址