最最最基础的linx+nginx+mysql+PHP的运行环境搭建
本次安装的linux系统版本为centos7.4 64位
首先需要更新yum
yum update
安装Nginx
yum安装nginx
安装nginx最新源
yum localinstall http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum repolist enabled | grep "nginx*"
安装nginx
yum -y install nginx
启动nginx
service nginx start
设置nginx服务器开机自启动
systemctl enable nginx.service
检查开机自动是否设置成功(成功会有nginx.servive的字样)
systemctl list-dependencies | grep nginx
浏览器中输入公网ip,检测是否安装成功(会显示ngxin的默认欢迎页)
安装Mysql5.7
yum安装Mysql5.7
安装mysql源
yum -y localinstall http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
yum repolist enabled | grep "mysql.*-community.*"
安装mysql
yum -y install mysql-community-server install mysql-community-devel
启动mysql
service mysqld start
检查mysql启动是否正常
service mysqld status 或者 ps -ef | grep mysql
设置mysqld服务开机自启动
systemctl enable mysqld.service
检查mysqld开机自启动是否设置成功(成功会有mysql.servive的字样)
systemctl list-dependencies | grep mysqld
mysql5.7以后的增强了安全机制, 所以使用yum安装,启动会系统会自动生成一个随机的密码
查看mysql的随机密码(最后的就是密码)
grep 'temporary password' /var/log/mysqld.log
登录mysql(把上面的随机密码输入)
mysql -u root -p
更改密码(mysql文档规定,密码必须包括大小写字母数字加特殊符号>8位)
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Yourpassword';
创建用户
CREATE USER 'username'@'host' IDENTIFIED BY 'password';
host -
指定该用户在哪个主机上可以登陆,此处的"localhost",是指该用户只能在本地登录,不能在另外一台机器上远程登录,如果想远程登录的话,将"localhost"改为"%",表示在任何一台电脑上都可以登录;也可以指定某台机器可以远程登录;
用户授权 GRANT privileges ON databasename.tablename TO 'username'@'host'
PS: privileges - 用户的操作权限,如SELECT , INSERT ,
UPDATE 等.如果要授予所的权限则使用ALL.;databasename -
数据库名,tablename-表名,如果要授予该用户对所有数据库和表的相应操作权限则可用表示, 如.*远程访问
修改mysql的配置文件/etc/mysql/my.conf(Ubuntu下是/etc/mysql/mysql.conf.d/mysqld.cnf),将bind-address后面增加远程访问IP地址或者禁掉这句话就可以让远程机登陆访问了。
安装PHP7.2
yum安装php7.2
由于linux的yum源不存在php7.x,所以我们要更改yum源
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum 安装php72w和各种拓展,选自己需要的即可,这些是基本配置的
yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-fpm php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml php72w-pecl-memcached php72w-pecl-redis
验证php是否安装成功
php -v
验证对应的扩展是否安装成功
php -m
启动php-fpm
service php-fpm start
检查启动是否成功
service php-fpm status
设置开机自启动
systemctl enable php-fpm.service
检查开机自启动是否设置成功
systemctl list-dependencies | grep php-fpm
至此LNMP基础环境已搭建完毕
查看nginx版本 `nginx -v`
查看nginx运行状态 `service nginx status`
重启nginx `service nginx restart`
开启nginx `service nginx start`
关闭nginx `service nginx stop`
查看php版本 php -v
查看nginx运行状态 service php-fpm status
重启php service php-fpm restart
开启php service php-fpm start
关闭php service php-fpm stop
查看mysql版本 mysql -V(大写的v)
查看nginx运行状态 service mysqld status
重启php service mysqld restart
开启php service mysqld start
关闭php service mysqld stop
nginx配置文件在 /etc/nginx/
php.ini在/etc/php.ini
mysql数据文文件在/var/lib/mysql
mysql配置文件在/etc/my.cnf
mysql日志文件在/var/log/mysqld.log
nginx的配置在另外的文档有,下面这个是最基础的,重写index.php以及兼容ThinkPHP的pathinfo模式
server {
listen 80;
server_name 47.107.136.7;
root /web/web/public/;
index index.html index.htm index.php;
error_log /var/log/nginx/test-error.log crit;
access_log /var/log/nginx/test-access.log;
error_page 500 502 503 504 /50x.html;
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}