Nginx 安装 2php
Apache 安装 3html
Mysql 安装 4mysql
PHP安装 7nginx
[root@nginx2 ~]# yum install gcc-c++ -yc++
安装nginx的时候须要的依赖包,解压便可web
[root@nginx2 software]# tar -xvf openssl-1.1.0g.tar.gz sql
[root@nginx2 software]# tar -xvf pcre-8.41.tar.gz 数据库
[root@nginx2 software]# tar -xvf zlib-1.2.11.tar.gz apache
[root@nginx2 software]# tar -xvf nginx-1.12.2.tar.gz centos
添加用户
[root@nginx2 software]# useradd nginx
[root@nginx2 software]# cd nginx-1.12.2/
配置:
[root@nginx2 nginx-1.12.2]# ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_ssl_module --with-openssl=/software/openssl-1.1.0g --with-pcre=/software/pcre-8.41 --with-zlib=/software/zlib-1.2.11 --with-http_stub_status_module --conf-path=/usr/local/nginx/nginx.conf
编译&安装
[root@nginx2 nginx-1.12.2]# make && make install
测试&启动
[root@nginx2 ~]# cd /usr/local/nginx/sbin/
[root@nginx2 sbin]# ./nginx -t
nginx: the configuration file /usr/local/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/nginx.conf test is successful
[root@nginx2 sbin]# ./nginx
[root@nginx2 sbin]# ps -ef | grep nginx
root 66606 1 0 22:05 ? 00:00:00 nginx: master process ./nginx
nginx 66607 66606 0 22:05 ? 00:00:00 nginx: worker process
root 66617 47667 0 22:05 pts/0 00:00:00 grep --color=auto nginx
[root@nginx2 nginx]# curl 192.168.119.131
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
安装依赖包:
[root@nginx2 software]# yum install libtool -y
其余三个包apr、apr-util、pcre
Apr
[root@nginx2 software]# tar -xvf apr-1.6.3.tar.gz
[root@nginx2 software]# cd apr-1.6.3/
[root@nginx2 apr-1.6.3]# ./configure --prefix=/usr/local/apr/
安装的时候会报错:
rm: cannot remove 'libtoolT': No such file or directory
F1:咱们须要把configure文件,查找 $RM "$cfgfile" 这个地方,用#注释掉
F2:在configure里面 RM='$RM -f' 这里的$RM后面必定有一个空格。 若是后面没有空格,直接链接减号,就依然会报错。把RM='$RM'改成RM='$RM -f'
[root@nginx2 apr-1.6.3]# make && make install
Apr-util
[root@nginx2 software]# yum install expat-devel -y
[root@nginx2 software]# tar -xvf apr-util-1.6.1.tar.gz
[root@nginx2 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util/ --with-apr=/usr/local/apr/ && make && make install
Pcre
[root@nginx2 software]# tar -xvf pcre-8.41.tar.gz
[root@nginx2 software]# cd pcre-8.41/
[root@nginx2 pcre-8.41]# ./configure --prefix=/usr/local/pcre/ --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/
[root@nginx2 pcre-8.41]# make && make install
安装apache
[root@nginx2 software]# tar -xvf httpd-2.4.29.tar.gz
[root@nginx2 software]# cd httpd-2.4.29/
[root@nginx2 httpd-2.4.29]# ./configure --help
[root@nginx2 httpd-2.4.29]# ./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre/
[root@nginx2 httpd-2.4.29]# make && make install
[root@nginx2 httpd-2.4.29]# cd /usr/local/apache2/
先中止nginx ,咱们先测试apache是否安装成功
[root@nginx2 apache2]# /usr/local/nginx/sbin/nginx -s stop
[root@nginx2 apache2]# vi conf/httpd.conf
[...]
ServerName localhost:80
[...]
[root@nginx2 apache2]# ./bin/apachectl start
[root@nginx2 ~]# curl 192.168.119.131
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<title>Index of /</title>
</head>
<body>
<h1>Index of /</h1>
<ul></ul>
</body></html>
[root@nginx2 apache2]# ./bin/apachectl stop
将apache服务脚本加入到initd目录
[root@nginx2 ~]# cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd
接着咱们安装数据库
或者安装mariadb
咱们这里选择安装mysql数据库
安装cmake、ncurses-devel
[root@nginx2 software]# yum install cmake -y
[root@nginx2 software]# yum install ncurses-devel -y
建立用户
[root@nginx2 ~]# useradd -r -U mysql -M -d /usr/local/mysql/data
修改安装目录的全部者和全部组
[root@nginx2 ~]# mkdir /usr/local/mysql
[root@nginx2 ~]# chown -R mysql:mysql /usr/local/mysql
修改数据目录的全部者和全部组
[root@nginx2 ~]# mkdir -p /data/mysql
[root@nginx2 ~]# chown -R mysql:mysql /data/mysql/
解压
[root@nginx2 ~]# cd /software/
[root@nginx2 software]# tar -xvf mysql-5.7.20.tar.gz
[将boost解压出来便可]
[root@nginx2 software]# tar xvf mysql-boost-5.7.20.tar.gz
配置编译参数
[root@nginx2 mysql-5.7.20]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk -DMYSQL_DATADIR=/data/mysql/ -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/software/mysql-5.7.20/boost/
安装
[root@nginx2 mysql-5.7.20]# make && make install
初始化数据库
[root@nginx2 mysql-5.7.20]# cd /usr/local/mysql/bin/
[root@nginx2 bin]# ./mysql_install_db --user=mysql --datadir=/data/mysql/ --basedir=/usr/local/mysql/
复制mysql服务启动配置文件
[root@nginx2 mysql]# cp /etc/my.cnf /etc/my.cnf.bak
[root@nginx2 mysql]# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
cp: overwrite ‘/etc/my.cnf’? y
复制mysql服务启动脚步及加入PATH路径
[root@nginx2 mysql]# vi /etc/profile
[...]
PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
export PATH
[root@nginx2 mysql]# source /etc/profile
修改配置文件
[mysqld]
user=mysql
port=3306
socket=/data/mysql/mysql.sock
datadir=/data/mysql/
basedir=/usr/local/mysql/
explicit_defaults_for_timestamp=true
[client]
socket=/data/myssql/mysql.sock
启动数据库
[root@nginx2 bin]# ./mysqld_safe --user=mysql &
查看数据默认的密码
[root@nginx2 ~]# cat /root/.mysql_secret
# Password set for user 'root@localhost' at 2017-12-04 14:33:58
HkDh1go6#O#=
查看进程
[root@nginx2 ~]# ps -aux | grep mysql
查看端口
[root@nginx2 ~]# netstat -tulnp | grep 3306
查看日志
[root@nginx2 ~]# tail /data/mysql/nginx2.err
登陆数据库
1从命令行登陆MySQL数据库服务器 1、登陆使用默认3306端口的MySQL
[root@nginx2 ~]# mysql -u root -p
2 经过TCP链接管理不一样端口的多个MySQL
[root@nginx2 ~]# mysql -u root -p --protocol=tcp --host=localhost --port=3307
3 经过socket套接字管理不一样端口的多个MySQL
[root@nginx2 ~]# mysql -u root -p --socket=/data/mysql/mysql.sock
4 经过端口和IP管理不一样端口的多个MySQL
[root@nginx2 ~]# mysql -u root -p -P 3306 -h 127.0.0.1
中止mysql
[root@nginx2 ~]# mysqladmin -u root -p shutdown
输入密码
修改mysql数据库root用户密码
[root@nginx2 mysql]# mysql -u root -p
Enter password: (输入老密码,默认密码)
[...]
查看如今的密码策略
mysql> show VARIABLES like "%password%";
对应的官方密码策略表
0 or LOW | Length
1 or MEDIUM | Length;numeric,lowercase/uppercase,and special characters
2 or STRONG | Length;numeric,lowercase/uppercase,and special characters;dictionary file
修改成咱们设定的密码
mysql> set password='Lxl@890826';
设置密码永不过时
[root@nginx2 ]# vi /etc/my.cnf
加入:default_password_lifetime=0
修改密码策略
mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=0;
mysql> set password='redhat';
准备工做:
[root@nginx2 ~]# yum install gd curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel -y
解压,配置
[root@nginx2 software]# tar -xvf php-7.1.12.tar.gz
[root@nginx2 php-7.1.12]# ./configure --prefix=/usr/local/php7.1 --enable-fpm --enable-debug --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-mbstring --with-curl --with-mysqli=/usr/local/mysql/bin/mysql_config
#注意数据库mysqli=后路径
编译,安装
[root@nginx2 php-7.1.12]# make && make install
[...
Build complete.
Don't forget to run 'make test'.
Installing shared extensions: /usr/local/php7.1/lib/php/extensions/debug-non-zts-20160303/
Installing PHP CLI binary: /usr/local/php7.1/bin/
Installing PHP CLI man page: /usr/local/php7.1/php/man/man1/
Installing PHP FPM binary: /usr/local/php7.1/sbin/
Installing PHP FPM defconfig: /usr/local/php7.1/etc/
Installing PHP FPM man page: /usr/local/php7.1/php/man/man8/
Installing PHP FPM status page: /usr/local/php7.1/php/php/fpm/
Installing phpdbg binary: /usr/local/php7.1/bin/
Installing phpdbg man page: /usr/local/php7.1/php/man/man1/
Installing PHP CGI binary: /usr/local/php7.1/bin/
Installing PHP CGI man page: /usr/local/php7.1/php/man/man1/
Installing build environment: /usr/local/php7.1/lib/php/build/
Installing header files: /usr/local/php7.1/include/php/
Installing helper programs: /usr/local/php7.1/bin/
program: phpize
program: php-config
Installing man pages: /usr/local/php7.1/php/man/man1/
page: phpize.1
page: php-config.1
Installing PEAR environment: /usr/local/php7.1/lib/php/
[PEAR] Archive_Tar - installed: 1.4.3
[PEAR] Console_Getopt - installed: 1.4.1
[PEAR] Structures_Graph- installed: 1.1.1
[PEAR] XML_Util - installed: 1.4.2
[PEAR] PEAR - installed: 1.10.5
Wrote PEAR system config file at: /usr/local/php7.1/etc/pear.conf
You may want to add: /usr/local/php7.1/lib/php to your php.ini include_path
/software/php-7.1.12/build/shtool install -c ext/phar/phar.phar /usr/local/php7.1/bin
ln -s -f phar.phar /usr/local/php7.1/bin/phar
Installing PDO headers: /usr/local/php7.1/include/php/ext/pdo/
...]
复制配置文件
[root@nginx2 php-7.1.12]# cp php.ini-production /usr/local/php7.1/lib/php.ini
[root@nginx2 ~]# cp /usr/local/php7.1/etc/php-fpm.conf.default /usr/local/php7.1/etc/php-fpm.conf
复制启动脚本文件
[root@nginx2 ~]# cp /software/php-7.1.12/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@nginx2 ~]# chmod +x /etc/init.d/php-fpm
启动
[root@nginx2 ~]# /etc/init.d/php-fpm start
[root@nginx2 etc]# ps -ef | grep php
root 32511 1 0 23:30 ? 00:00:00 php-fpm: master process (/usr/local/php7.1/etc/php-fpm.conf)
nobody 32512 32511 0 23:30 ? 00:00:00 php-fpm: pool www
nobody 32513 32511 0 23:30 ? 00:00:00 php-fpm: pool www
报错:
[root@nginx ~]# /etc/init.d/php-fpm start
Starting php-fpm [29-Nov-2017 16:43:01] WARNING: Nothing matches the include pattern '/usr/local/php7.1/etc/php-fpm.d/*.conf' from /usr/local/php7.1/etc/php-fpm.conf at line 125.
[29-Nov-2017 16:43:01] ERROR: No pool defined. at least one pool section must be specified in config file
[29-Nov-2017 16:43:01] ERROR: failed to post process the configuration
[29-Nov-2017 16:43:01] ERROR: FPM initialization failed
failed
解决:
[root@nginx php-fpm.d]# pwd
/usr/local/php7.1/etc/php-fpm.d
[root@nginx php-fpm.d]# cp www.conf.default www.conf
若是还有报错多是配置文件php-fpm.conf最后一行,默认是注释的,去掉注释便可。
include=/usr/local/php7.1/etc/php-fpm.d/*.conf
[root@nginx2 ~]# vi /usr/local/nginx/nginx.conf
[root@nginx2 nginx]# cat nginx.conf
worker_processes 4;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name www.doudoua.com localhost;
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location / {
root html/a;
index index.html index.htm;
}
location ~ \.php$ {
root /www/php/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html/a$fastcgi_script_name;
include fastcgi_params;
}
}
}
建立php首页
[root@nginx2 a]# pwd
/usr/local/nginx/html/a
[root@nginx2 a]# vi index.php
<?php
phpinfo();
?>
测试配置文件,重启
[root@nginx2 ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/nginx.conf test is successful
[root@nginx2 ~]# /usr/local/nginx/sbin/nginx -s reload