服務器架構及實戰(架構篇)- PHP建站



概述php

 詳解html

   PHP的環境搭建mysql

   PHP的幫助使用和配置文件linux

   PHP的Hello Worldnginx

   PHP的庫函數調用程序員

   PHP的Web程序web

   PHP的函數和麪向對象使用sql

   PHP的數據庫訪問數據庫

   Nginx安裝和配置訪問編程

   WordPress的安裝和配置實用

   推動資料:圖書,視頻,代碼等

總述

 

PHP基礎環境準備

安裝虛擬機

VM(Virtual Box)

安裝操做系統

Centos

網絡使用橋接的方式鏈接

虛擬機有獨立的IP,和主機能夠相互訪問

PHP安裝

#wget http://pa1.php.net/distributions/php-5.6.22.tar.gz

#tar –zxf php-5.6.22.tar.gz

#./configure

#yum install libxml2 libxslt

#yum install libxml2-devel –y

#find / -name 「xml2-config」

#make

#make install

#php version

 

PHP的幫助和配置文件

php --help

php –i

php –ini

http://php.net/manual/en/configuration.file.php

 

 php –m

 pear

 pear list

 

 

 

PHP基礎編程

 

 第一個PHP程序

 文件helloworld.php

 執行$php helloword.php

 將來常常用來測試的代碼

 

PHP庫函數調用

 

使用庫函數

文件func.php

 執行$php func.php

  設置php.ini文件#locate php.ini # vi /usr/local/lib/php.ini

或者直接設置

PHP的Web程序

啓動內置服務器

 

訪問:

能夠編輯hello.php文件:

 


 
  PHP Test

 




 

PHP的函數和麪向對象使用

 

參考代碼

 

PHP的數據庫訪問

MySQL的安裝

#yum install mysql

#mysql -h 192.168.5.116 -P 3306 -u root -p123456

 

PHP的配置

./configure  --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-zlib

 

echo "mysql conn start. \n";        

$mysqli = new mysqli(" 192.168.0.104 ", " root ", " 123456","test");

if ($mysqli->connect_errno) {    echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;}

else {

echo 「database connection success. \n」;}

echo "mysql conn end. \n";

?>

 

Nginx安裝

#yum list | grep nginx

#vi /etc/yum.repos.d/nginx.repo

#yum install -y nginx

service nginx start # 啓動Nginx服務

service nginx stop # 中止Nginx服務

/etc/nginx/nginx.conf # Nginx配置文件位置

 

[nginx]

name=nginx repo

baseurl=http://nginx.org/packages/centos/$releasever/$basearch/

gpgcheck=0

enabled=1

 

 

Nginx配置訪問

 Nginx

#iptables -A IN_public_allow -p tcp -m tcp --dport 80 -m conntrack --ctstate NEW -j ACCEPT

 

#nginx -t

 

[root@10 ~]# cat /etc/nginx/nginx.confuser  nginx;worker_processes  1;error_log  /var/log/nginx/error.log warn;pid        /var/run/nginx.pid;events {    worker_connections  1024;}http {    include       /etc/nginx/mime.types;    default_type  application/octet-stream;    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        on;    #tcp_nopush     on;    keepalive_timeout  65;    #gzip  on;    upstream blog.91tianwu.com {server localhost:8000 weight=5;    }    server {listen 80;        server_name blog.91tianwu.com;location / {proxy_pass http:// blog.91tianwu.com/;}    }    include /etc/nginx/conf.d/*.conf;    client_max_body_size 20m;}

 

WordPress安裝

 

MySQL的database建立

WordPress的下載和解壓

#wget https://cn.wordpress.org/wordpress-4.5.2-zh_CN.tar.gz

#tar –zxf word*

#php -S localhost:8000

 

多域名的Nginx配置和WordPress設置

[root@10 ~]# cat /etc/nginx/nginx.confuser  nginx;worker_processes  1;error_log  /var/log/nginx/error.log warn;pid        /var/run/nginx.pid;events {    worker_connections  1024;}http {    include       /etc/nginx/mime.types;    default_type  application/octet-stream;    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        on;    #tcp_nopush     on;    keepalive_timeout  65;    #gzip  on;    upstream blog.91tianwu.com {server localhost:8000 weight=5;    }    upstream bbs.91tianwu.com {server localhost:8001 weight=5;    }    server {listen 80;        server_name blog.91tianwu.com;location / {proxy_pass http://blog.91tianwu.com/;}    }    server {listen 80;        server_name bbs.91tianwu.com;location / {proxy_pass http://bbs.91tianwu.com/;         }    }    include /etc/nginx/conf.d/*.conf;    client_max_body_size 20m;}

#php -S localhost:8000

#php -S localhost:8001

 

Database創建2個

Nginx配置2個域名和proxy

啓動配置WordPress

 

推薦資料

 

李明老師講Linux

http://study.163.com/course/courseMain.htm?courseId=266032

《php和mysql web開發》

 

網站

http://php.net/

沒有比官網更權威的了!

 

推薦免費視頻

一小時學會建網站(三樂大掌櫃)

http://study.163.com/course/courseMain.htm?courseId=582007

 

基本參考文獻

http://php.net/

http://php.net/manual/en/

 

排錯時使用

http://blog.chinaunix.net/uid-26719405-id-3409842.html

http://stackoverflow.com/questions/16765158/date-it-is-not-safe-to-rely-on-the-systems-timezone-settings

http://php.net/manual/zh/datetime.configuration.php#ini.date.timezone

附錄:Linux服務器安全設置

 iptables關閉

/sbin/iptables -P INPUT ACCEPT

/sbin/iptables -F

Iptables -nL

 

#iptables -A IN_public_allow -p tcp -m tcp --dport 80 -m conntrack --ctstate NEW -j ACCEPT

#iptables -A IN_public_allow -p tcp -m tcp --dport 21-m conntrack --ctstate NEW -j ACCEPT

SELinux關閉

/usr/sbin/sestatus -v 

修改/etc/selinux/config 文件

將SELINUX=enforcing改成SELINUX=disabled

重啓機器便可

附錄:Linux服務器FTP安裝

#yum install vsftpd –y

#useradd -d /phproot/blog -m -s /sbin/nologin blogftp

#mkdir -p /phproot/blog

#chown -R blogftp.blogftp /phproot/blog

#passwd blogftp

vi /etc/vsftpd/vsftpd.conf

#禁止匿名訪問 anonymous_enable=NO

#用戶只能訪問限制的目錄 chroot_local_user=YES

#service vsftpd restart

#cd /phproot/blog

#touch test.txt

 

$ftp blogftp@192.168.0.104

 

報錯:500 OOPS: vsftpd: refusing to run with writable root inside chroot()

#vi /etc/vsftpd/vsftpd.conf

allow_writeable_chroot=YES

報錯:500 OOPS: could not read chroot() list file:/etc/vsftpd/chroot_list

vi /etc/vsftpd/vsftpd.conf 設置 chroot_local_user=YES chroot_list_enable=YES # (default follows) chroot_list_file=/etc/vsftpd/chroot_list

vi /etc/vsftpd/chroot_list 添加用戶名

chmod 755 blog/

 

 

附錄:Linux下PHP環境變量設置

 

[root@twjp bin]# cat ~/.bash_profile

# .bash_profile

# Get the aliases and functions

if [ -f ~/.bashrc ]; then

. ~/.bashrc

fi

# User specific environment and startup programs

PHP_HOME=/usr/local/php

PATH=$PATH:$HOME/bin:$PHP_HOME/bin

export PATH

 

添物網官方賬號。添物專一於互聯網信息技術研究和應用,關注程序員發展,特別是Java程序員的發展。創始人(碩士研究生)獨立架構實現了添物網(含APP),有超過10年的編程和架構經驗,但願經過添物網平臺架構,傳遞軟件開發架構相關知識。添物提供零基礎到大型平臺架構師一站通培訓服務,幫助你們瞭解和學習整個軟件的開發,測試,運維,架構,發佈等內容。同時也整理分享IT相關技術內容,並提供諮詢服務,促進你們共同發展。歡迎你們共同交流。

相關文章
相關標籤/搜索