失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > 服务器架构及实战(架构篇)- PHP建站

服务器架构及实战(架构篇)- PHP建站

时间:2021-02-07 15:18:46

相关推荐

服务器架构及实战(架构篇)- PHP建站

概述

详解

PHP的环境搭建

PHP的帮助使用和配置文件

PHP的Hello World

PHP的库函数调用

PHP的Web程序

PHP的函数和面向对象使用

PHP的数据库访问

Nginx安装和配置访问

WordPress的安装和配置实用

推进资料:图书,视频,代码等

总述

PHP基础环境准备

安装虚拟机

VM(Virtual Box)

安装操作系统

Centos

网络使用桥接的方式连接

虚拟机有独立的IP,和主机可以相互访问

PHP安装

#wget /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

/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文件:

PHPTest

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=/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 {server localhost:8000 weight=5; } server {listen 80; server_name ;location / {proxy_pass http:// /;} } include /etc/nginx/conf.d/*.conf; client_max_body_size 20m;}

WordPress安装

MySQL的database创建

WordPress的下载和解压

#wget /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 {server localhost:8000 weight=5; } upstream {server localhost:8001 weight=5; } server {listen 80; server_name ;location / {proxy_pass /;} } server {listen 80; server_name ;location / {proxy_pass /; } } 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

/course/courseMain.htm?courseId=266032

《php和mysql web开发》

网站

/

没有比官网更权威的了!

推荐免费视频

一小时学会建网站(三乐大掌柜)

/course/courseMain.htm?courseId=58

基本参考文献

/

/manual/en/

排错时使用

/uid-26719405-id-3409842.html

/questions/16765158/date-it-is-not-safe-to-rely-on-the-systems-timezone-settings

/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),有超过的编程和架构经验,希望通过添物网平台架构,传递软件开发架构相关知识。添物提供零基础到大型平台架构师一站通培训服务,帮助大家了解和学习整个软件的开发,测试,运维,架构,发布等内容。同时也整理分享IT相关技术内容,并提供咨询服务,促进大家共同发展。欢迎大家共同交流。

如果觉得《服务器架构及实战(架构篇)- PHP建站》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。