Nginx 特性
Nginx 性能稳定、功能丰富、运维简单、处理静态文件速度快且消耗系统资源极少。
1、相比 Apache,用 Nginx 作为 Web 服务器:使用资源更少,支持更多并发连接,效率更高。
2、作为负载均衡服务器:Nginx 既可在内部直接支持 Rails 和 PHP,也可支持作为 HTTP 代理服务器对外进行服务。Nginx 用 C 编写而成, 不论是系统资源开销还是 CPU 使用效率都比 Perlbal 要好的多。
3、作为邮件代理服务器:Nginx 同时也是一款非常优秀的邮件代理服务器(最早开发这个产品的目的之一,是作为邮件代理服务器)。
4、反向代理可以根据url将请求转向于不同用途的集群,比如图片请求,转向图片服务器集群;视频请求,转身视频服务器集群。
nginx是一款轻量级的web服务器/反向代理服务器/电子邮件代理服务器,安装非常简单,配置文件也很简洁(还支持 perl 语法)。Nginx 支持平滑加载新配置,还能够在不间断服务的情况下进行软件版本升级。
Apache 特性
1、Apache 是 LAMP 架构最核心的 Web Server,开源、稳定、模块丰富是 Apache 的优势。但 Apache 的缺点是有些臃肿,内存和 CPU 开销大,性能上有损耗,不如一些轻量级的 Web 服务器(譬如:Nginx、Tengine等)高效,轻量级的 Web 服务器对于静态文件的响应能力来说远高于 Apache 服务器。
2、Apache 做为 Web Server 是负载 PHP 的最佳选择,如果流量很大的话,可以采用 Nginx 来负载非 PHP 的 Web 请求。Nginx 是一个高性能的 HTTP 和反向代理服务器,Nginx 以其稳定、丰富功能集、示例配置文件和低系统资源的消耗而闻名。Nginx 现能支持 PHP 和 FastCGI,也支持负载均衡和容错,可和 Apache 配合使用,是轻量级的 HTTP 服务器的首选。
3、Web 服务器缓存也有多种方案,Apache 提供了自己的缓存模块,也可以使用外加的 Squid 模块进行缓存,这两种方式均可有效提高 Apache 的访问响应能力。Squid Cache 是一个 Web 缓存服务器,支持高效缓存,可作为网页服务器的前置 cache 服务器缓存相关请求以提高 Web 服务器速度。把 Squid 放在 Apache 的前端来缓存 Web 服务器生成动态内容,而 Web 应用程序只需要适当地设置页面实效时间即可。如访问量巨大,则可考虑使用 memcache 作为分布式缓存。
4、PHP 的加速可使用 eAccelerator 加速器,eAccelerator 是一个自由开放源码的 PHP 加速器。它会优化动态内容缓存,提高 PHP 脚本缓存性能,使 PHP 脚本在编译状态下,对服务器的开销几乎完全消除。它还可对脚本起优化作用,以加快其执行效率。 使 PHP 程序代码执效率可提高 1-10 倍。
##以上资料来源:https://www.zhihu.com/question/19697826
nginx优点:
轻量级服务器,相比较apache占用的资源更加少。
高并发。
配置文件的语法等简单易懂
社区活跃。
支持epoll模型。使得nginx可以支持高并发。
利用nginx可以对ip限速,可以限制连接数
环境:
centos 6.8 2.6.32-642.15.1.el6.x86_64
软件:
libiconv-1.14.tar.gz
libmcrypt-2.5.8.tar.gz
mcrypt-2.6.8.tar.gz
mhash-0.9.9.9.tar.gz
mysql-5.6.12-linux-glibc2.5-x86_64.tar.gz(二进制版)
php-5.6.30.tar.gz
nginx-1.12.0.tar.gz
提示:在进入正题之前一定要先去了解下nginx的工作原理和常用场景。
不要死记,多操作,多理解,自然就懂了。
看别人操作,不如自己操作。
要能清晰的了解同类产品的区别。
大纲:
安装nginx
启动nginx
配置虚拟主机
安装mysql二进制版
安装php
测试lnmp环境
nginx
1、安装nginx
wget http://nginx.org/download/nginx-1.12.0.tar.gz tar zxvf nginx-1.12.0.tar.gz cd nginx-1.12.0/ yum install gcc gcc-c++ zilb.x86_64 zlib-devel.x86_64 pcre-devel.x86_64 pcre.x86_64 openssl.x86_64 openssl-devel.x86_64-y useradd -M -s /sbin/nologin nginx ./configure --help ./configure --prefix=/application/nginx1.12.0 --user=nginx --group=nginx --with-pcre --with-http_ssl_module --with-http_stub_status_module echo $? make echo $? make install echo $? ln -s /application/nginx1.12.0/ /application/nginx cd /application/nginx
nginx目录结构 | |
conf | 配置文件 |
html | 默认站点 |
logs | 日志文件 |
sbin | 命令 |
总结: 1 选择软件一定不能选择最新的,否则出问题不容易解决,因为第一个吃螃蟹。 |
2、启动nginx
/application/nginx/sbin/nginx -t /application/nginx/sbin/nginx lsof -i :80 curl localhost
总结:
|
3、配置虚拟主机
如果熟悉了Apache的虚拟主机那么Nginx的虚拟主机也很容易理解,而且配置还比Apache简单很多。
虚拟主机:
基于域名的虚拟主机
基于IP的虚拟主机
基于端口的虚拟主机
mkdir /application/nginx/conf/extra -p ##把我们的虚拟主机文件放在这个扩展目录中,可以在管理网站的时候更加方便 vim /application/nginx/conf/nginx.conf ##将主配置文件修改为以下内容 worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; include extra/blog.conf; include extra/easy.conf; include extra/bad.conf; } vim /application/nginx/conf/extra/blog.conf ##将虚拟主机blog配置文件配置为以下内容,不存在则创建 server { listen 80; server_name www.blog.vperson.org.cn; location / { root html/blog; index index.html index.htm; } } vim /application/nginx/conf/extra/easy.conf ##将虚拟主机easy配置为以下内容,不存在则创建 server { listen 80; server_name www.easy.vperson.org.cn; location / { root html/easy; index index.html index.htm; } } vim /application/nginx/conf/extra/bad.conf ##将虚拟主机bad配置文件修改为以下内容,不存在则创建 server { listen 80; server_name www.bad.vperson.org.cn; location / { root html/bad; index index.html index.htm; } } cd /application/nginx/html/ for name in blog bad easy;do mkdir $name; echo "$name.vperson.org.cn" > $name/index.html; done ##利用for循环创建目录,并向index.html中写入内容 tree ./ bad │ └── index.html ├── blog │ └── index.html ├── easy │ └── index.html vim /etc/hosts 127.0.0.1 localhost www.blog.vperson.org.cn www.easy.vperson.org.cn ##修改本地hosts文件,为了配合我们的基于域名的虚拟主机 ping -c 1 ping -c 1 ping -c 1 www.bad.vperson.org.cn /application/nginx/sbin/nginx -s reload ##重启nginx服务器 curl blog.vperson.org.cn curl bad.vperson.org.cn curl easy.vperson.org.cn
提示:使用curl访问域名时返回如上信息即基于域名的虚拟主机搭建成功。
扩展:
* 域名重定向
为什么需要域名重定向,第一是为了防止恶意绑定,最简单的道理就是,域名是别人买的,别人想把域名指向公网中的任意一台主机我们也没有办法。但是用了域名重定向后,可以在使用恶意域名访问我们的服务器后,会在地址栏重定向为我们指定的域名,并访问指定的站点。(理解一个原理,在一个未知域名访问我们的主机时其实是以IP的形式访问,也就是说我们重定向的其实是IP地址)
还有就是多域名指向同意服务器,提高访问量。
------------------------------------------------------------------ vim /application/nginx/conf/extra/rewrite.conf ##编译rewirte.conf文件不存在则创建,内容如下 server { listen 80; server_name www.rewrite.vperson.org; rewrite ^/(.*) http://www.easy.vperson.org.cn/$1 permanent; #^/表示 # #永久有效 } ----OK------------------------------------------------------------ ------------------------------------------------------------------ vim /application/nginx/conf/nginx.conf ##修改nginx的主配置文件,注意include的顺序这个很重要否则域名重定向就没用了 worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; include extra/rewrite.conf; include extra/blog.conf; include extra/easy.conf; include extra/bad.conf; } ----OK------------------------------------------------------------ /application/nginx/sbin/nginx -t /application/nginx/sbin/nginx -s reload vim /etc/hosts 127.0.0.1 localhost www.blog.vperson.org.cn www.easy.vperson.org.cn www.rewrite.vperson.org ping -c 1 curl -L www.rewrite.vperson.org curl -I www.rewrite.vperson.org HTTP/1.1 301 Moved Permanently Server: nginx/1.12.0 Date: Sun, 16 Apr 2017 14:19:58 GMT Content-Type: text/html Content-Length: 185 Connection: keep-alive Location: http://www.easy.vperson.org.cn/
隐藏nginx版本号:
vim /application/nginx/conf/nginx.conf ##修改为以下内容 worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server{ listen 8080; server_name www.vperson.win; rewrite ^/(.*) http://www.blog.vperson.org.cn/$1 permanent; } include extra/easy.conf; include extra/bad.conf; include extra/blog.conf; server_tokens off; }
apache隐藏版本号的方法:
----------------------------
cat /application/apache/conf/extra/httpd-default.conf ............. ServerTokens Prod ServerSignature Off .............
-----------------------
nginx日志管理
使用mv工具和crontab工具
具体方法如下:
---------------------------------------------------------------------------- vim nginx.conf worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; include extra/rewrite.conf; include extra/bad.conf; include extra/blog.conf; include extra/easy.conf; server_tokens off; } vim extra/blog.conf server { listen 80; server_name www.blog.vperson.org.cn; access_log logs/blog.access.log main; location / { root html/blog; index index.html index.htm; } } ##其他的配置文件也一样在server标签里添加日志信息 ----OK------------------------------------------------------------ #sed -i '/server_name www.bad.vperson.org.cn;/a\\taccess_log logs\/bad.access.log main; ' extra/bad.conf ../sbin/nginx -t ../sbin/nginx -s reload ll ../logs/ total 220 -rw-r--r-- 1 root root 110155 Apr 17 15:42 access.log -rw-r--r-- 1 root root 0 Apr 17 15:42 bad.access.log -rw-r--r-- 1 root root 0 Apr 17 15:42 blog.access.log -rw-r--r-- 1 root root 0 Apr 17 15:42 easy.access.log -rw-r--r-- 1 root root 98802 Apr 17 15:43 error.log -rw-r--r-- 1 root root 6 Apr 16 22:29 nginx.pid -rw-r--r-- 1 root root 0 Apr 17 15:42 rewrite.access.log ##可见日志文件已经生成 --------------------------------------------------------------------------------- vim /application/nginx/logs/backlog.sh ##写一个自动备份的脚本 #!/bin/sh for name in rewrite bad blog easy; do /bin/mv /application/nginx/logs/${name}.access.log /applog/nginx/access/$(date +%F)_${name}.log if [ $? -eq 0 ] then echo "$(date +%F) ${name}" >> /applog/nginx/access/successfully.txt else echo "$(date +%F) ${name}" >> /applog/nginx/access/error.txt fi done /bin/find /applog/nginx/access/ -mtime +7 -exec rm -rf {} \; ---脚本完成------OK------------------------------------------------------------ chmod +x /application/nginx/logs/backlog.sh crontab -e 30 1 * * * /application/nginx/logs/backlog.sh ##晚上访问量少,适合做备份等工作 mkdir -p /applog/nginx/access/
总结:
|
++++++++++++++++++++++nginx服务安装完成++++++++++++++++++++++++
Mysql
4、安装二进制mysql
mysql分类:
社区版
商业版
集群
wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.32-linux2.6-x86_64.tar.gz tar zxvf mysql-5.5.32-linux2.6-x86_64.tar.gz cp -avr mysql-5.5.32-linux2.6-x86_64/ /application/ cd /application/ mv mysql-5.5.32-linux2.6-x86_64/ mysql-5.5.32/ ln -s mysql-5.5.32/ mysql useradd -M -s /sbin/nologin mysql cd mysql mkdir /application/mysql/data -p chown -R mysql:mysql /application/mysql-5.5.32/ ----------------------------------------------------------------- ./scripts/mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data/ --user=mysql ##初始化数据库 mysql_install_db根据版本的不同可能存放的路径也不一样 --basedir是mysql的安装路缙 --datadir是数据文件存放路径 --user是用户名 成功的标准是echo $?没有错误+两个OK没有error To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system ##想要开机自动启动,就把mysql.server放到正确的位置即/etc/init.d/mysqld /application/mysql//bin/mysqladmin -u root password 'new-password' /application/mysql//bin/mysqladmin -u root -h vperson password 'new-password' Alternatively you can run: /application/mysql//bin/mysql_secure_installation ##设置密码的方法 You can start the MySQL daemon with: cd /application/mysql/ ; /application/mysql//bin/mysqld_safe & ##运行数据库 You can test the MySQL daemon with mysql-test-run.pl cd /application/mysql//mysql-test ; perl mysql-test-run.pl ##测试数据库 提示:/etc/init.d/mysqld实质是复制了mysql.server文件,所以一定不要和cd /application/mysql/ ; /application/mysql//bin/mysqld_safe &方法一起用否则会出错 --------------------------------------------------------------- \cp support-files/my-medium.cnf /etc/my.cnf \cp support-files/mysql.server /etc/init.d/mysqld -------------------------------------- vim /etc/init.d/mysqld .................. basedir=/application/mysql/ datadir=/application/mysql/data ................... 或者 #sed -i'46s/\(basedir=\)/\1\/application\/mysql/p' /etc/init.d/mysqld ##修改46行为basedir=/application/mysql,只限定当前环境,其他环境可能有变化 #sed -i'47s/\(datadir=\)/\1\/application\/mysql\/data/p' /etc/init.d/mysqld ##修改datadir为/application/mysq/data ----OK--------------------------------- chmod +x /etc/init.d/mysqld /etc/init.d/mysqld start echo "export PATH=/application/mysql/bin:$PATH" >> /etc/profile source /etc/profile ---------------------------------------------------- mysql_secure_installation ##以下内容看自己的需求 mysql -uroot -p mysql>show databases; mysql> use mysql mysql> show tables; mysql> select User,Host from user; mysql>DELETE FROM user WHERE User='root' and Host='::1'; ## 目前是不会用的到的所以删除,如果有需求就不用删除 mysql> quit --OK--------------------------------------------------
总结: a) 针对自己的硬件平台选用合适的编译器来优化编译后的二进制代码; |
PHP
需要下载以下的依赖包,并且编译:
libiconv(libiconv-1.14.tar.gz)
libmcrypt-2.5.8.tar.gz,加密库
mcrypt-2.6.8.tar.gz
mhash-0.9.9.9.tar.gz
5、安装PHP
wget tar zxvf php-5.6.30.tar.gz cd php-5.6.30/ yum install libxml2-devel.x86_64 libxml2.x86_64 openssl-devel.x86_64 libcurl-devel.x86_64 libjpeg-turbo.x86_64 libjpeg-turbo-devel.x86_64 png* libpng-devel.x86_64 freetype.x86_64 freetype-devel.x86_64 libxslt-devel.x86_64 libxslt.x86_64 zlib libxml libjpeg freetype libpng gd curl libiconv zlib-devel libxml2-devellibjpeg-devel freetype-devel libpng-devel gd-devel curl-devel -y 编译安装libiconv1.14: ============================================== tar zxvf libiconv-1.14.tar.gz cd libiconv-1.14/ ./configure --prefix=/usr/local/libiconv make make install ------------------------------------------------------------------------------ 错误:./stdio.h:1010:1: 错误:‘gets’未声明(不在函数内) _GL_WARN_ON_USE(gets, "gets is a security hole - use fgets instead"); 解决: vim ./srclib/stdio.h GL_WARN_ON_USE(gets, "gets is a security hole - use fgets instead"); 替换为 #if defined(__GLIBC__) && !defined(__UCLIBC__) && !__GLIBC_PREREQ(2, 16) _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead"); #endif -------------------------------------------------------------------------------- =============================================== 编译安装mhash-0.9.9.9: ================================================= tar zxvf mhash-0.9.9.9.tar.gz cd mhash-0.9.9.9/ ./configure make && make install ================================================ 编译安装libmcrypt ================================================== tar zxvf libmcrypt-2.5.8.tar.gz cd libmcrypt-2.5.8/ ./configure make && make install cp /usr/local/lib/* /usr/local/lib64/ -av ##只正对64位操作系统,32为操作系统直接往下走 rm -f /usr/lib64/libmcrypt.* rm -f /usr/lib64/libmhash* ln -s /usr/local/lib64/libmcrypt.la /usr/lib64/libmcrypt.la ln -s /usr/local/lib64/libmcrypt.so /usr/lib64/libmcrypt.so ln -s /usr/local/lib64/libmcrypt.so.4 /usr/lib64/libmcrypt.so.4 ln -s /usr/local/lib64/libmcrypt.so.4.4.8 /usr/lib64/libmcrypt.so.4.4.8 ln -s /usr/local/lib64/libmhash.a /usr/lib64/libmhash.a ln -s /usr/local/lib64/libmhash.la /usr/lib64/libmhash.la ln -s /usr/local/lib64/libmhash.so /usr/lib64/libmhash.so ln -s /usr/local/lib64/libmhash.so.2 /usr/lib64/libmhash.so.2 ln -s /usr/local/lib64/libmhash.so.2.0.1 /usr/lib64/libmhash.so.2.0.1 ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config ##提示我搭好的环境中我并没有在/usr/local/lib64/下找到文件,文件都在/usr/local/lib, 可以把/usr/local/lib/下的文件复制到/usr/local/lib64/下 ================================================= yum install libxslt* -y ##安装libxslt* 编译安装mcrypt-2.6.8: ================================================ tar zxvf mcrypt-2.6.8.tar.gz cd mcrypt-2.6.8/ ./configure LD_LIBRAPY_PATH=/usr/local/lib ##原因未知,这个我是百度搜出来的 make && make install ================================================ ================================================= vim 1.txt ./configure \ --prefix=/application/php5.6.30 \ --with-mysql=/application/mysql \ --enable-mysqlnd \ --with-pdo-mysql=mysqlnd \ --with-iconv-dir=/usr/local/libiconv \ --with-freetype-dir \ --with-jpeg-dir \ --with-png-dir \ --with-zlib \ --with-libxml-dir=/usr \ --enable-xml \ --disable-rpath \ --enable-safe-mode \ --enable-bcmath \ --enable-shmop \ --enable-sysvsem \ --enable-inline-optimization \ --with-curl \ --with-curlwrappers \ --enable-mbregex \ --enable-fpm \ --enable-mbstring \ --with-mcrypt \ --with-gd \ --enable-gd-native-ttf \ --with-openssl \ --with-mhash \ --enable-pcntl \ --enable-sockets \ --with-xmlrpc \ --enable-zip \ --enable-soap \ --enable-short-tags \ --enable-zend-multibyte \ --enable-static \ --with-xsl \ --with-fpm-user=nginx \ --with-fpm-group=nginx \ --enable-ftp \ --enable-embedded-mysqli \ --with-mysqli \ --with-pdo-mysql=/application/mysql cat 1.txt | bash echo $? make echo $? make install echo $? ln -s /application/php5.6.30/ /application/php cp php.ini-production /application/php/lib/php.ini ##提醒:如果是做开发的话就把php.ini-development复制过去 由于nginx调用PHP是通过一个fcgi的程序,所以,这个程序也是有配置文件的。 cd /application/php/etc/ cp php-fpm.conf.default php-fpm.conf egrep -v "^$|;" php-fpm.conf ------------------------------------------------------------------------ [global] pid = /app/logs/php-fpm.pid error_log = /app/logs/php-fpm.log log_level = error rlimit_files = 32768 events.mechanism = epoll [www] user = nginx group = nginx listen = 127.0.0.1:9000 listen.owner = nginx listen.group = nginx pm = dynamic pm.max_children = 1024 pm.start_servers = 16 pm.min_spare_servers = 5 pm.max_spare_servers = 20 pm.max_requests = 2048 slowlog = /app/logs/$pool.log.slow request_slowlog_timeout = 10 -------------------------------------------------------------------------- ../sbin/php-fpm -t +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 错误:ERROR: Unable to create or open slowlog(/applog/logs/www.log.slow): No such file or directory (2) 解决:mkdir /applog/logs/ -p +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ../sbin/php-fpm lsof -i :9000 ================================================
我编译PHP遇到的错误:
+++++++++++++++++++++++++++++++++++++++++++++++++++++++
错误:configure: error: Don't know how to define struct flock on this system, set --enable-opcache=no
解决:
ln -s /application/mysql/lib/libmysqlclient.so /usr/lib64/
ln -s /application/mysql/lib/libmysqlclient.so.18 /usr/lib64/
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
问题:checking whether to enable embeddedMySQLi support... yes
checking for mysql_set_server_optionin -lmysqlclient... no
configure: error: wrong mysql libraryversion or lib not found. Check config.log for more information.
解决:--with-mysqli后面不加路径
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
问题:Don't know how to define struct flockon this system, set --enable-opcache=no
解决:
以下红色路径看具体mysql安装路径而定
32位系统:
ln -s /usr/local/MySQL/lib/libmysqlclient.so /usr/lib/
ln -s /usr/local/mysql/lib/libmysqlclient.so.18/usr/lib/libmysqlclient.so.18
64位系统:
ln -s /usr/local/MySQL/lib/libmysqlclient.so /usr/lib64/libmysqlclient.so
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/libmysqlclient.so.18
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
问题:configure: error: Please reinstallreadline - I cannot find readline.h
解决:yum install readline-devel.x86_64 -y
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
问题:make: *** [sapi/cli/php] Error 1
解决:
网上统一的解决方式: makeZEND_EXTRA_LIBS='-liconv'
ln -s /usr/local/lib/libiconv.so.2/usr/lib64/
我自己的解决方式:重新编译安装libiconv(注意编译的的参数--with-iconv-dir的路径)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
=================测试LNMP环境==========================
cd /application/nginx/
--------------------------------------------------
vim html/blog/index.php
<?php
phpinfo();
?>
--------------------------------------------------
vim conf/extra/blog.conf
server {
listen 80;
server_name www.blog.vperson.org.cn;
access_log logs/blog.access.log main;
location / {
root html/blog;
index index.php index.html index.htm;
}
location ~ \.php$ {
root html/blog;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
include fastcgi.conf;
}
}
-----------------------------------------------------------------------------
./sbin/nginx -t
./sbin/nginx -s reload
错误集:
|
隐藏PHP版本:
vim /application/php/lib/php.ini
expose_php = On
搭建一个自己的开源网站:
opensns、phpcms、wiki等。
步骤:
下载开源软件包
#如http://kaiyuan.hudong.com/
创建数据库
#create database wiki;
创建数据库中的用户用于管理这个网站的数据
#grant all on wiki.* towiki@’localhost’ identified by ‘wiki’;
#flush privileges;
#quit
解压开源网站到指定的站点目录
#修改权限chown -Rnginx:nginx 目录
用浏览器访问
安装站点
总结: LNMP搭建对于新手来说是比较困难但是要细心,前后要有呼应,理解。 遇到困难先看错误,别急着百度,因为搜出来的大部分都是复制粘贴的。 记录下来每次的错误方便下次解决。 遇到困难,做了好久的,先放松放松,去散步什么的回来说不定就会了。 二进制的mysql不推荐新手完,因为他只是预设了一些参数。 |
网上搜了很多,终于知道测试PHP和mysql连同的代码了:
<?php
//$link_id=mysql_connect('主机名','用户','密码');
$link_id=mysql_connect('localhost','root','redhat')or mysql_error();
if($link_id){
echo"mysql successful";
}else{
echomysql_error();
}
?>
##以上可能有错误,但是还请原谅因为我也是新手,刚刚开始学习linux,请多多指教。
转载于:https://blog.51cto.com/10856118/1916834