就最近買了VPS权均,才有了這些文章.準(zhǔn)備開始寫博客了.環(huán)境我們采用比較流行的纱扭,相對(duì)百度老的資料巩搏,本文還是相對(duì)比較新的.也許希望大家給以后的小站支持.
LNMP:CentOS7+PHP7+Nginx+MariaDB
如果文章有錯(cuò)盐捷,請(qǐng)指出孽江,方便修正!
軟件包更新:
sudo yum update -y
epel,remi庫(kù)登記
sudo yum -y install epel-release
wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
sudo rpm -ivh remi-release-7.rpm
vim,git安裝
sudo yum install vim git
修改時(shí)間(我國(guó)外的VPS宣鄙,所以改不改都無(wú)所謂)
sudo timedatectl set-timezone Asia/xxx
Nginx安裝
sudo rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
sudo yum -y install nginx
Nginx的設(shè)置
/etc/nginx/conf.d/default.conf
server {
listen 80;
server_name example.com;
access_log /var/log/nginx/laos.access.log;
error_log /var/log/nginx/laos.error.log warn;
root /vagrant/laos/webroot;
index index.html index.php;
location / {
try_files $uri $uri?$args $uri/ /index.php?$uri&$args /index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
目錄位置:/etc/nginx/nginx.conf
user nginx;
worker_processes auto;
worker_rlimit_nofile 100000;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 2048;
multi_accept on;
use epoll;
}
http {
server_tokens off;
include /etc/nginx/mime.types;
default_type text/html;
charset UTF-8;
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 /var/log/nginx/access.log main;
sendfile off;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 10;
client_header_timeout 10;
client_body_timeout 10;
reset_timedout_connection on;
send_timeout 10;
limit_conn_zone $binary_remote_addr zone=addr:5m;
limit_conn addr 100;
gzip on;
gzip_http_version 1.0;
gzip_disable "msie6";
gzip_proxied any;
gzip_min_length 1024;
gzip_comp_level 6;
gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript application/json;
open_file_cache off;
client_max_body_size 20m;
server_names_hash_bucket_size 64;
include /etc/nginx/conf.d/*.conf;
}
Nginx起動(dòng)
sudo systemctl start nginx
sudo systemctl enable nginx
PHP7安裝(安裝必要的包)
sudo yum --enablerepo=epel,remi,remi-php70w install php70w php70w-php-mcrypt php70w-php-mbstring php70w-php-fpm php70w-php-gd php70w-php-pecl-xdebug php70w-php-pecl-redis php70w-php-pecl-imagick-devel php70w-php-pecl-imagick php70wphp-mysqlnd php70w-php-intl php70w-php-bcmath php70w-php-pecl-zip php70w-php-xmlrpc php70w-php-xml php70w-php-pecl-http php70w-php-pecl-http-devel php70w-php-opcache
Nginx通過(guò)路勁
cat /opt/remi/php70/enable
export PATH=/opt/remi/php70/root/usr/bin:/opt/remi/php70/root/usr/sbin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/opt/remi/php70/root/usr/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
export MANPATH=/opt/remi/php70/root/usr/share/man:${MANPATH}
~/.bashrc
export PATH=/opt/remi/php70/root/usr/bin:/opt/remi/php70/root/usr/sbin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/opt/remi/php70/root/usr/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
export MANPATH=/opt/remi/php70/root/usr/share/man:${MANPATH}
source ~/.bashrc
確認(rèn)
/etc/opt/remi/php70/php-fpm.d/www.conf
user = nginx
group = nginx
listen = /var/run/php-fpm.sock
listen.owner = nginx
listen.group = nginx
listen.mode = 0666
php-fpm起動(dòng)
/etc/systemd/system/php-fpm.service
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=simple
PIDFile=/var/run/php-fpm.pid
ExecStart=/opt/remi/php70/root/usr/sbin/php-fpm --nodaemonize --fpm-config /etc/opt/remi/php70/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
[Install]
WantedBy=multi-user.target
sudo systemctl start php-fpm
sudo systemctl enable php-fpm
為了能夠是HTTP防火墻設(shè)置訪問(wèn)
sudo firewall-cmd --add-service=http --permanent
sudo firewall-cmd --reload
MariaDB安裝(從官方請(qǐng)從網(wǎng)站資料庫(kù))
/etc/yum.repos.d/mariadb.repo
# MariaDB 10.1 CentOS repository list - created 2017-01-16 10:19 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
MariaDB正式安裝
sudo yum install MariaDB-server MariaDB-client MariaDB-devel
設(shè)置
sudo mkdir /home/mysql
sudo chown mysql. /home/mysql
/etc/my.cnf.d/server.cnf
[mysqld]
character-set-server=utf8
plugin-load = handlersocket.so
log-bin=mysql-bin
expire_logs_days = 30
secure_file_priv=/home/mysql
起動(dòng)
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service
初回設(shè)定
mysql_secure_installation
連接
mysql -u root -p
CREATE SCHEMA `laos` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ;