安装NGINX:
安装编译需要依赖的文件
yum install gcc gcc-c++ openssl openssl-devel cyrus-sasl-md5
NGINX 下载地址:
wget http://nginx.org/download/nginx-1.12.0.tar.gz
解压到当前目录:
tar -zxvf nginx-1.12.0.tar.gz
进入到解压后的安装目录
cd nginx-1.12.0
首次配置nginx
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-pcre=../pcre-8.39 --with-zlib=../zlib-1.2.8
非首次配置nginx
./configure --prefix=/usr/local/nginx --with-http_ssl_module
编译及安装
make && make install
重置编译路径时,先执行
make clean
启动nginx
/usr/local/nginx/sbin/nginx
查看nginx 是否启动成功
ps -ef | grep nginx
加入到开机运行
vim /etc/rc.local
添加如下代码
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf &
加入到环境变量
vim /etc/profile
最后一行加入
export PATH="$PATH:/usr/local/nginx/sbin:"
更新生效修改的内容:
source /etc/profile
补充:
如果是阿里云服务器,输入ip地址后nginx无法访问成功,请先建立http的安全组。
安装PHP
安装编译所需的扩展包
yum install gcc gcc-c++ libxml2 libxml2-devel autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel
安装curl
yum -y install curl-devel
本文的PHP下载地址:
wget http://cn2.php.net/distributions/php-7.2.0.tar.gz
解压到当前目录
tar -zxvf php-7.2.0.tar.gz
进入到解压后的安装目录
cd php-7.2.0
配置PHP
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php --enable-mbstring --enable-ftp --with-gd --with-jpeg-dir=/usr --with-png-dir=/usr --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pear --enable-sockets --with-freetype-dir=/usr --with-zlib --with-libxml-dir=/usr --with-xmlrpc --enable-zip --enable-fpm --enable-xml --enable-sockets --with-gd --with-zlib --with-iconv --enable-zip --with-freetype-dir=/usr/lib/ --enable-soap --enable-pcntl --enable-cli --with-curl --with-openssl
编译安装
make && make install
进入PHP的安装目录拷贝一份配置文件
cd /usr/local/php/etc
cp php-fpm.conf.default php-fpm.conf
vim php-fpm.conf
去掉前面的#
pid = run/php-fpm.pid
启动PHP-FPM
/usr/local/php/sbin/php-fpm
查看进程是否启动
ps -ef | grep php
配置nginx解析PHP
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
重启Nginx 服务器
/usr/local/nginx/sbin/nginx -s reload
nginx+php-fpm配置后访问php页面显示空白的解决方法 :
vi /etc/nginx/fastcgi_params
在文件的最后增加两行
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
重启一下服务
service php5-fpm reload service nginx reload
安装Mysql:
下载安装Mysql:
wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
rpm -ivh mysql57-community-release-el7-8.noarch.rpm
yum -y install mysql-server
MySQL第一次登陆会随机生成一个随机登陆密码,查看方式如下:
grep "password" /var/log/mysqld.log
登陆成功后,可以手动修改登陆密码
方式一:alter user 'root'@'localhost' identified by '123456';
方式二:update mysql.user set authentication_string=password('root') where user='root';
刷新权限:
flush privileges
开启远程链接权限了
mysql> use mysql;
Database changed
mysql>grant all privileges on *.* to root@'%' identified by "password";
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> select host,user,password from user;
+————–+——+——————————————-+
| host | user | password |
+————–+——+——————————————-+
| localhost | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |
| 192.168.1.1 | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |
| % | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |
+————–+——+——————————————-+
3 rows in set (0.00 sec)
---------------------
远程连接阿里云服务器出现1045-Access denied for user 'root’
更改user表中的root对应的host,改成%号之后(把localhost变成%),就可以进行远程登陆了。
flush privileges 使更改立即生效