Build social networking sites

Source: Internet
Author: User
Tags fpm php language php server nginx server

Deploy social networking site case overview

The company's social networking site in the PHP language development, in order to manage the code developed by PHP programmers, the senior leaders asked to build SVN server version control. The first version of the social networking site is deployed on the LNMP platform, with Nginx at the front and access to the backend's PHP server via the FASTCGI protocol. In order to ensure data security, MySQL database is required to build a master-slave cluster.

Social networking sites include users ' photo albums, allow users to upload photos, and upload photos that need to be stored using shared storage. The company decided to use the MFS Distributed file system and to mount the MFS to the relevant directory of the PHP server.

Case Environment

Case Environment requirements See table below

Host Operating System IP Address main software
Nginx CentOS 7 x86_64 Nginx
Php CentOS 7 x86_64 Php
MySQL Master CentOS 7 x86_64 mysql-5.5.24
MySQL Slave CentOS 7 x86_64 mysql-5.5.24
Svn CentOS 7 x86_64 Subversion
Build LNMP server to deploy Nginx server

First install the environment package, the dependency package.

  [[email protected] opt]# yum-y install pcre-devel zlib-devel[[email protected] opt]# useradd-m-S /sbin/nologin nginx #添加管理nginx的用户和组 [[email protected] mnt]# tar xf nginx-1.6.0.tar.gz-c/opt/#将软件包解压到指定目录 [[EMA               Il protected] opt]# cd nginx-1.6.0/#到解压目录中 [[email protected] nginx-1.6.0]#./configure \                                           #开始配置 >--prefix=/usr/local/nginx \ #指定安装目录 >--user=nginx \ #指定管理用户 >--group=nginx \ #指定管理组 >--with-http_st Ub_status_module #开启stub_status状态统计模块 [[email protected] nginx-1.6.0]# make && make Install #开始编译和安装 [[email protected] nginx-1.6.0]# ln-s/USR/LOCAL/NGINX/SBIN/NGINX/USR/LOCAL/SBIN/[[EMAIL&NB Sp;protected] nginx-1.6.0]# Nginx #开启nginx服务 # Establish a soft link to enable the system to identify the Nginx command  

Visit on the host to see if the access was successful.

Modify Nginx Configuration

The fastcgi access interface in the Nginx configuration file needs to be modified in order to access the PHP page.

[[email protected] nginx-1.6.0]# vim /usr/local/nginx/conf/nginx.conf        location ~ \.php$ {            root           /var/www/html/webphp;   #指定PHP服务器站点家目录            fastcgi_pass;    #指定PHP服务器地址及端口            fastcgi_index  index.php;            include        fastcgi.conf;        }

Restart Nginx Service

Deploying a PHP Server

Install PHP and accept nginx requests by configuring the PHP-FPM process to listen on port 9000. Install the environment pack and the dependent packages first.

[[email protected] ~]# yum -y install > gd > libxml2-devel > libjpeg-devel > libpng-devel > zlib-devel > fontconfig-devel > openssl-devel > bzip2-devel

Add PHP Admin Process user

useradd -M -s /sbin/nologin php

Extract the php-5.4.5 package to the specified directory.

[[email protected] mnt]# tar xf php-5.4.5.tar.bz2 -C /opt/

Switch to the php-5.4.5 unpacking directory and configure it.

[[email protected] mnt]# cd /opt/php-5.4.5./configure --prefix=/usr/local/php5 \                    #指定安装路径--with-gd #打开gd库的支持--with-zlib #开启zlib库的支持--with-config-file-path=/usr/local/php5 #指定php配置文件所在路径--enable-mbstring #多字节,字符串的支持--with-jpeg-dir #开启对jpeg图片的支持--with-openssl #openssl的支持,加密传输会用到--disable-ipv6 #关闭ipv6功能--with-mysql #最后几项都是让php支持mysql模块--with-mysqli --with-pdo-mysq --enable-fpm#启用fpm进程[[email protected] php-5.4.5]# make      #进行编译

However, an error occurred during the compilation process, such as finding a solution after the study.

/opt/php-5.4.5/ext/dom/node.c: 在函数‘dom_canonicalization’中:/opt/php-5.4.5/ext/dom/node.c:1898:21: 错误:提领指向不完全类型的指针

Here's the workaround, you need to hit a patch package.

[[email protected] opt]# curl -o php-5.2.17.patch下载patch包[[email protected] opt]# lsphp-5.2.17.patch  php-5.4.5  rh[[email protected] opt]# cd php-5.4.5/[[email protected] php-5.4.5]# patch -p0 -b <../php-5.2.17.patch  #将patch导入到php软件包中。patching file ext/dom/node.cpatching file ext/dom/documenttype.cpatching file ext/simplexml/simplexml.c#显示导入成功[[email protected] php-5.4.5]# make && make install #重新编译和安装

After the compilation installation is successful, start modifying the configuration file and making some optimizations.

[ro[email protected] php-5.4.5]# cp php.ini-development /usr/local/php5/php.ini#将配置文件模版复制出来[[email protected] php-5.4.5]# ln -s /usr/local/php5/bin/* /usr/local/bin/[[email protected] php-5.4.5]# ln -s /usr/local/php5/sbin/* /usr/local/sbin/#以上两项都是让系统能够识别php相关命令

Install the Accelerator for PHP.

Configure the PHP recognition accelerator.

[[email protected] php-5.3.x]# vim /usr/local/php5/php.ini[Zend Guard Loader]zend_extension=/usr/local/php5/lib/php/ZendGuardLoader.sozend_loader.enable=1#将这段话加入到php.ini配置文件中

Open Nginx's php-fpm support.

[[email protected] php-5.3.x]# cd /usr/local/php5/etc/[[email protected] etc]# cp  php-fpm.conf.default php-fpm.conf[[email protected] etc]# vim php-fpm.conf  #修改配置文件的相关参数pid = run/php-fpm.piduser = phpgroup = phppm.max_children=50pm.start_servers = 20pm.min_spare_servers = 5pm.max_spare_servers = 35listen =监听端口修改下,监听所有ip,如果只是127.0.0.1,那么php服务器无法监听到nginx服务器

Start the PHP-FPM process and see Port 9000 open.

[[email protected] etc]# /usr/local/sbin/php-fpm[[email protected] etc]# netstat -ntap | grep 9000    #9000端口已经开启tcp        0      0  *               LISTEN      

Just now in the Nginx configuration file, we configure the PHP server site, we need to create a site directory that is index.php.

[[email protected] etc]# mkdir -p /var/www/html/webphp#创建站点目录[[email protected] etc]# cd /var/www/html/webphp/[[email protected] webphp]# echo "123">index.php#创建站点首页

Test, Access, you can see the PHP site home page.

Deploying a MySQL Server

Install MySQL dependency packages and environment packs.

[[email protected] ~]# yum -y install ncurses-devel cmake#ncurses是字符终端下屏幕控制的基本库

Unzip the package to the specified directory and configure

[[email protected] ~]# cd /mnt/[[email protected] mnt]# tar xf mysql-5.5.24.tar.gz -C /opt/[[email protected] mnt]# cd /opt/mysql-5.5.24/[[email protected] mysql-5.5.24]# cmake  > -DCMAKE_INSTALL_PREFIX=/usr/local/mysql > -DDEFAULT_CHARSET=utf8 > -DDEFAULT_COLLATION=utf8_general_ci > -DWITH_EXTRA_CHARSETS=all > -DSYSCONFDIR=/etc > -DMYSQL_DATADIR=/home/mysql/ > -DMYSQL_UNIX_ADDR=/home/mysql/mysql.sock > -DWITH_MYISAM_STORAGE_ENGINE=1 > -DWITH_INNOBASE_STORAGE_ENGINE=1 > -DWITH_ARCHIVE_STORAGE_ENGINE=1 > -DWITH_BLACKHOLE_STORAGE_ENGINE=1 > -DENABLED_LOCAL_INFILE=1 > -DWITH_SSL=system > -DMYSQL_TCP_PORT=3306 > -DENABLE_DOWNLOADS=1 > -DWITH_SSL=bundled[[email protected] mysql-5.5.24]# make && make install#编译后安装

After the compilation is installed, the optimization is done.

[[email protected] mysql-5.5.24]# cp support-files/my-medium.cnf /etc/my.cnf#复制配置文件到/etc中cp:是否覆盖"/etc/my.cnf"? y[[email protected] mysql-5.5.24]# cp support-files/mysql.server /etc/init.d/mysqld#方便mysqld被service服务管理[[email protected] mysql-5.5.24]# echo "PATH=$PATH:/usr/local/mysql/bin/" >> /etc/profile#更改环境变量[[email protected] mysql-5.5.24]# source /etc/profile#使环境变量文件刷新生效[[email protected] mysql-5.5.24]# useradd -s /sbin/nologin mysql#添加mysql服务用户[[email protected] mysql-5.5.24]# chown -R mysql.mysql /usr/local/mysql#更改主文件夹的属主和属组

Initialize MySQL.

To create a soft link to a Mysql.sock file

[[email protected] mysql-5.5.24]# ln -s /var/lib/mysql/mysql.sock  /home/mysql/mysql.sock

Modify the MySQL startup script file.

[[email protected] mysql-5.5.24]# vim /etc/init.d/mysqldbasedir=/usr/local/mysqldatadir=/home/mysql[[email protected] mysql-5.5.24]# chmod +x /etc/init.d/mysqld [[email protected] mysql-5.5.24]# service mysqld startStarting MySQL.. SUCCESS! [[email protected] mysql-5.5.24]# netstat -ntap | grep 3306tcp        0      0  *               LISTEN      13702/mysqld#启动成功

Create the root user for MySQL.

[[email protected] mysql-5.5.24]# mysqladmin -u root -p password ‘abc123‘[[email protected] mysql-5.5.24]# mysql -u root -pEnter password: Welcome to the MariaDB monitor.  Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.5.24 Source distributionCopyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.#登录成功
Deploy MySQL master-slave database

Modify the MySQL master server ( configuration file.

[[email protected] mysql-5.5.24]# Vim/etc/my.cnfserver-id = 11#server-id master server cannot be the same log-bin=master-bin #主服务器日志文件log-slave-updates=true #从服务器更新二进制日志 [[email protected] mysql-5.5.24]# Servi Ce mysqld restartshutting down MySQL. success! Starting MySQL. success! #重启数据库 [[email protected] mysql-5.5.24]# mysql-u root-penter Password: #登录数据库MySQL [(None)]> GRANT REPLICATION S Lave on * * to ' myslave ' @ ' 192.168.58.% ' identified by ' 123456 '; Query OK, 0 rows affected (0.06 sec) #授权给192.168.58.0 Network segment Server sync permissions MySQL [(none)]> flush privileges; Query OK, 0 rows Affected (0.00 sec) #刷新权限MySQL [(none)]> Show Master status;+-------------------+----------+--------- -----+------------------+| File | Position | binlog_do_db | binlog_ignore_db |+-------------------+----------+--------------+------------------+|      master-bin.000001 |              338 |                  | |+-------------------+----------+--------------+------------------+1 Row in Set (0.00 sec) #这两个值很重要, use the following 

Modify MySQL from server configuration file

[[email protected] ~]# vim /etc/my.cnfserver-id = 12relay-log=relay-log-binrelay-log-index=slave-relay-bin.index[[email protected] ~]# service mysqld restart ERROR! MySQL server process #62735 is not running!Starting MySQL........ SUCCESS! #重启数据库[[email protected] ~]# mysql -u root -pEnter password: mysql>  change master to master_host=‘‘,master_user=‘myslave‘,master_password=‘123456‘,master_log_file=‘master-bin.000001‘,master_log_pos=338#指定主服务器,登录账号和密码,同步文件和文件偏移量mysql> start slave;Query OK, 0 rows affected (0.28 sec)#开启slave同步功能mysql> show slave status\G;

You can see the master-slave synchronization is successful, do a validation on the primary database to create a friend database, and also automatically generated from the database.

Deploying SVN server to install SVN service
[[email protected] ~]# yum install subversion -y   #通过yum仓库安装[[email protected] ~]# svnserve --version    #查看版本信息svnserve,版本 1.7.14 (r1542130)   编译于 Apr 11 2018,02:40:28
Create a warehouse catalog repo
[[email protected] ~]# mkdir -p /opt/svn/repo             #创建一个目录[[email protected] ~]# svnadmin create /opt/svn/repo/     #将这个目录作为仓库[[email protected] ~]# cd /opt/svn/repo/[[email protected] repo]# ls                              #查看仓库目录下的文件conf  db  format  hooks  locks  README.txt
Configuring the Svnserve.conf File
[[email protected] repo]# vim /opt/svn/repo/conf/svnserve.conf anon-access = none                              #匿名用户u没有任何权限                  auth-access = write                             #认证用户具有写的权限password-db =/opt/svn/repo/conf/passwd          #用户的密码文件authz-db =/opt/svn/repo/conf/authz              #用户的信息文件

Configuring the passwd File
[[email protected] repo]# vim /opt/svn/repo/conf/passwd [users]# harry = harryssecret# sally = sallyssecretalpha=abc123      #格式:用户名=密码

Configuring the Authz File
[[email protected] repo]# vim /opt/svn/repo/conf/authz [/]alpha = r                       #在/opt/svn/repo目录下有读取权限[/webphp]alpha = rw                      #对于webphp木有有读写权限,用于上传下载代码

Start SVN service
[[email protected] repo]# svnserve -d -r /opt/svn/repo/  #关闭通过kill‘进程[[email protected] repo]# netstat -ntap | grep svn*tcp        0      0  *               LISTEN      3566/svnserve       
Import webphp Folder
[[email protected] repo]# cd webphp/[[email protected] webphp]# ls[[email protected] webphp]# touch 123.txt 234.txt[[email protected] webphp]# svn import webphp file:///opt/svn/repo/webphp -m "initial"#初始化webphp目录
Test SVN service
This time we switch to the Nginx server's/usr/local/nginx/html/webphp directory to download the SVN server update content [[email protected] ~]# yum Install subversion -Y #安装subversion [[email protected] html]# SVN co svn:// #将svn服务器的webphp目录下载下来认证领域: &LT;SVN:> 07d793c7-c030-4485-8f7a-f531171e80ca "root" Password: Authentication field: <svn://> 07D793C7-C030-4485-8F7A-F531171E80CA Username: Alpha "alpha" Password:------------------------------------------------------  -----------------Attention!  Your password, for authentication domain: <svn://> 07d793c7-c030-4485-8f7a-f531171e80ca can only be saved in plaintext on disk! If possible, consider configuring your system so that subversion can save the encrypted password. Please refer to the documentation for more information. You can avoid this warning again by setting the option "Store-plaintext-passwords" to "yes" or "no" in "/root/.subversion/servers".    -----------------------------------------------------------------------Save the unencrypted password (yes/no)? Yesa webphp/555.txta WEBPHP/1A webphp/2a webphp/3a webphp/123.txta webphp/4a webphp/234.txt Remove version 4. [[email protected] html]# ls50x.html index.html Webphp[[email&nbsP;protected] html]# CD webphp/[[email protected] webphp]# LS1 123.txt 2 234.txt 3 4 555.txt 

You can see that the contents of the Webphp warehouse are synchronized to the specified path of the Nginx server.

MFS Building

Detailed construction process to see the reproduced blog, the other part of the building.

Build social networking sites

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.