Linux
系统环境:CentOs 7
Nginx
安装
一.源码安装(未实践)
1)新系统要安装编译工具
$ yum install -y gcc gcc-c++
2)安装gizp依赖
yum install -y zlib-devel
3)安装pcre库
rewrite模块需要 pcre 库
$ cd /usr/local/ `定位到安装位置`
$wget ftp//ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz `下载`
$tar zxvf pcre-8.39.tar.gz `解压安装包`
$cd pcre-8.39
$./configure `配置`
$make&&make install `编译安装`
4)安装ssl库
$ cd /usr/local/
$ wget http://www.openssl.org/source/openssl-1.0.1j.tar.gz
$ tar -zxvf openssl-1.0.1j.tar.gz
$ cd openssl-1.0.1j
$ ./config
$ make && make install
5)安装nginx
$cd /usr/local/
$wget http://nginx.org/download/nginx-1.12.2.tar.gz
$tar zxvf nginx-1.12.2.tar.gz
$./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-http_sub_module --with-http_ssl_module
$ make && make install
6)启动
$ /usr/local/nginx/sbin/nginx
二.yum安装
安装命令
yum install -y nginx
如果无法安装成功要配置Nginx源,再重新执行上述命令
rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
启动命令
nginx
检查配置
nginx -t
重启
nginx -s reload
检查是否安装成功,直接访问主机
http://localhost/
如图
php
源码安装
参考http://php.net/manual/zh/install.unix.nginx.php
下载安装包,上传到服务器
tar -xvzf php-7.2.3.tar.gz
cd php-7.2.3
安装依赖
yum -y install libxml2 libxml2-devel openssl openssl-devel curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel pcre pcre-devel libxslt libxslt-devel bzip2 bzip2-devel
配置,./congihure --help查看配置,执行
./configure --prefix=/usr/local/php --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-zip
编译安装
make
sudo make install
创建配置文件,并复制到正确的位置
cp php.ini-development /usr/local/php/php.ini
cp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf
cp sapi/fpm/php-fpm /usr/local/bin
为了避免恶意脚本注入攻击,修改php.ini配置
cgi.fix_pathinfo=1
改成
cgi.fix_pathinfo=0
启动php-fpm服务
/usr/local/bin/php-fpm
修改nginx配置,使支持php文件
location / {
root html;
index index.php index.html index.htm;
}
下一步配置来保证对于 .php 文件的请求将被传送到后端的 PHP-FPM 模块, 取消默认的 PHP 配置块的注释,并修改为下面的内容
location ~* \.php$ {
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
重启nginx,测试
遇到的坑
1.ERROR: Unable to globalize '/usr/local/NONE/etc/php-fpm.d/*.conf' (ret = 2) from /usr/local/etc/php-fpm.conf at line 125.
ERROR: failed to load configuration file '/usr/local/etc/php-fpm.conf'
ERROR: FPM initialization failed
solution:
Edit /usr/local/etc/php-fpm.conf document introduced * .conf part, change to the correct path include = / usr / local / etc / php-fpm.d / *. Conf
If there is no /usr/local/etc/php-fpm.d directory, create the directory.
2.WARNING: Nothing matches the include pattern '/usr/local/etc/php-fpm.d/*.conf' from /usr/local/etc/php-fpm.conf at line 125.
ERROR:. No pool defined at least one pool section must be specified in config file
ERROR: failed to post process the configuration
ERROR: FPM initialization failed
solution: cp www.conf.default www.conf
MySQL
yum安装
参考 https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/#repo-qg-yum-fresh-install
下载安装包
wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
配置yum源(Adding the MySQL Yum Repository)
sudo rpm -Uvh mysql57-community-release-el7-11.noarch.rpm
安装
sudo yum install mysql-community-server
启动MySQL
sudo systemctl start mysqld.service
查看MySQL状态
sudo systemctl status mysqld.service
查看默认的临时密码
sudo grep 'temporary password' /var/log/mysqld.log
用户登录,修改密码
mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
允许用户远程登录
grant all privileges on *.* to 'user'@'%' identified by 'password' with grant option;