網絡配置php
centos中的網絡接口配置:html
nat: vim /etc/sysconfig/network-scripts/ifcfg-eth0python
DEVICE=eth0 HWADDR=08:00:27:60:8D:FC ONBOOT=yes NM_CONTROLLED=yes BOOTPROTO=dhcp
host-only:vim /etc/sysconfig/network-scripts/ifcfg-enp0s3mysql
TYPE=Ethernet HWADDR=08:00:27:17:94:19 BOOTPROTO=static DEFROUTE=yes PEERDNS=yes PEERROUTES=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_PEERDNS=yes IPV6_PEERROUTES=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy NAME=enp0s3 UUID=fac7f008-3be8-49cd-8d9d-99986a3f0322 DEVICE=enp0s3 ONBOOT=yes IPADDR=192.168.3.102 GATEWAY=192.168.3.1 NETMASK=255.255.255.0
SELinuxlinux
防火牆(firewalld,本文改用iptables)nginx
軟件源配置:c++
安裝經常使用軟件git
yum group list gcc和開發環境 : yum groupinstall "Development Tools" yum install -y pcre-devel openssl-devel libxslt* perl-ExtUtils-Embed at gcc-c++ python subversion gperf make rpm-build git curl bzip2-devel libcurl-devel gd gd-devel t1lib t1lib-devel libmcrypt libmcrypt-devel libtidy libtidy-devel GeoIP-devel libatomic_ops-devel zlib-devel unzip libstdc++* net-snmp net-snmp* gmp gmp-devel openldap openldap-devel libpcap-devel glib2-devel libxml2-devel redis vim wget htop iftop libtool automake mlocate pam-devel gcc screen openssl iptables-services bash-completion* net-tools
預安裝(檢查pcre是否安裝,安裝pcre庫是爲了使Nginx支持具有URL重寫的rewrite模塊.openssl是nginx使用https服務要用的模塊。)web
rpm -qa|grep -E 'pcre|pcre-devel' //若是無返回結果,證實pcre包未安裝,使用如下命令下載安裝 yum install pcre pcre-devel -y rpm -qa|grep -E 'openssl|openssl-devel' //若是返回值爲空,表示系統還沒有安裝,安裝命令以下 yum install openssl openssl-devel rpm -qa |grep gcc gcc-c++ //若是未安裝gcc,則編譯過程當中會出現./configure: error: C compiler cc is not found錯誤 yum install gcc gcc-c++
創建用戶和用戶組redis
追加一個www組 groupadd -f www 追加一個www用戶 useradd -s /sbin/nologin -g www www
編譯安裝nginx
./configure --user=www \ --group=www \ --prefix=/usr/local/nginx-1.xx.xx \ --with-http_stub_status_module \ --with-http_ssl_module
編譯參數說明:
echo $? //返回0表示上面的命令正確執行 make && make install echo $? ln -s /usr/local/nginx-1.xx.xx /usr/local/nginx //設立一條軟鏈接,好處是程序中若是有引用nginx路徑的地方,不須要修改程序,若是升級nginx版本,直接從新作一條鏈接便可
啓動並檢查安裝結果
檢查配置文件: /usr/local/nginx/sbin/nginx -t 檢查經過後啓動nginx服務: /usr/local/nginx/sbin/nginx 查看編譯安裝nginx時的參數: /usr/local/nginx/sbin/nginx -V
啓用iptables開放80端口
systemctl enable iptables //設置iptables爲開機啓動 systemctl start iptables //當即啓動iptable systemctl disable ip6tables //禁止IPv6的ip6tables開機啓動 systemctl stop ip6tables //當即中止IPv6的ip6tables iptables -A INPUT -p tcp --dport 80 -j ACCEPT //開放tcp80端口 serviece iptables save //保存修改 systemctl reload iptables systemctl restart iptables
7.檢驗成果
在放行80端口的狀況下,能夠經過瀏覽器訪問測試安裝效果。
#進入nginx文件夾 [root@centos7-test openresty-1.11.2.2]# cd /usr/local/nginx/ #新建文件夾 [root@centos7-test nginx]# mkdir vhosts.d #修改配置文件 [root@centos7-test nginx]# vim nginx.conf #將server段的內容所有註釋掉 server { ... ... } #在最後一個}的上方添加如下內容並保存 include /usr/local/nginx/vhosts.d/*.ngx.conf; 而後檢查並從新加載nginx: #檢查配置文件是否正常 [root@centos7-test nginx]# 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 #從新加載nginx [root@centos7-test nginx]# nginx -s reload 而後新建一個虛擬空間 #新建虛擬目錄 [root@centos7-test nginx]# mkdir -p /data/web/darkgel.com #新建日誌目錄 [root@centos7-test nginx]# mkdir /usr/local/nginx/logs/darkgel_access.log #新建虛擬空間配置文件 [root@centos7-test nginx]# vim /usr/local/nginx/vhosts.d/darkgel.com.conf server{ listen 80; root /data/web/darkgel.com; access_log /usr/local/nginx/logs/darkgel_access.log; location / { index index.html; } }
嘗試訪問站點看是否成功
因爲mysql的編譯實在太耗時,這裏沒有采用編譯安裝
首先添加 MariaDB 的 YUM 配置文件 MariaDB.repo 文件。
# vi /etc/yum.repos.d/MariaDB.repo # MariaDB 10.2 CentOS repository list - created 2017-06-14 09:14 UTC # http://downloads.mariadb.org/mariadb/repositories/ [mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.2/centos7-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1
採用國內鏡像加速(具體操做參考https://lug.ustc.edu.cn/wiki/...)
sudo yum install MariaDB-server MariaDB-client
MariaDB 包安裝完畢後,當即啓動數據庫服務守護進程,並能夠經過下面的操做設置,在操做系統重啓後自動啓動服務。
# systemctl start mariadb # systemctl enable mariadb # systemctl status mariadb
對 MariaDB 進行安全配置
# mysql_secure_installation
開始使用
# mysql -V # mysqld --print-defaults # mysql -u root -p
下載
wget http://cn2.php.net/distributi...
安裝依賴庫
yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel mhash gd gd-devel
編譯配置
./configure --prefix=/usr/local/php7 \ --with-config-file-path=/usr/local/php7/etc \ --with-config-file-scan-dir=/usr/local/php7/etc/php.d \ --with-mcrypt=/usr/include \ --enable-mysqlnd \ --with-mysqli \ --with-pdo-mysql \ --enable-fpm \ --with-fpm-user=www \ --with-fpm-group=www \ --with-gd \ --with-iconv \ --with-zlib \ --enable-xml \ --enable-shmop \ --enable-sysvsem \ --enable-inline-optimization \ --enable-mbregex \ --enable-mbstring \ --enable-ftp \ --enable-gd-native-ttf \ --with-openssl \ --enable-pcntl \ --enable-sockets \ --with-xmlrpc \ --enable-zip \ --enable-soap \ --without-pear \ --with-gettext \ --enable-session \ --with-curl \ --with-jpeg-dir \ --with-freetype-dir \ --enable-opcache
編譯&安裝
make && make install
調整php配置
從源碼包中找到ini文件:
php.ini-development php.ini-production
複製到--with-config-file-path指定的目錄下,並更名爲php.ini
啓用php-fpm服務
配置文件在--with-config-file-path指定的目錄下:
php-fpm.conf.default
重命名爲php-fpm.conf(一樣處理的還有當前目錄下的php-fpm.d目錄下的配置文件)
使用源碼中提供的腳原本啓動php-fpm(在源碼目錄/sapi/fpm/init.d.php-fpm)
$ cp init.d.php-fpm /etc/init.d/php-fpm $ chmod +x /etc/init.d/php-fpm $ chkconfig --add php-fpm $ chkconfig php-fpm on 啓用php-fpm $service php-fpm start
配置nginx對接php-fpm及站點(在server{...}中添加)
location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /$document_root$fastcgi_script_name; include fastcgi_params; } 重啓nginx /usr/local/nginx/sbin/nginx -s reload