操作时间2018年5月4日
1.查看目前环境
腾讯云,已设置ssh连接
[root@VM_0_10_centos ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
已安装centos7.2
2.安装第三方yum源
wget http://www.atomicorp.com/installers/atomic #下载
sh ./atomic #安装
yum check-update #更新yum源
以下为操作记录供参考
[root@VM_0_10_centos ~]# wget http://www.atomicorp.com/installers/atomi
--2018-05-04 08:57:34-- http://www.atomicorp.com/installers/atomic
Resolving www.atomicorp.com (www.atomicorp.com)... 74.208.77.16
Connecting to www.atomicorp.com (www.atomicorp.com)|74.208.77.16|:80...d.
HTTP request sent, awaiting response... 200 OK
Length: 12594 (12K)
Saving to: ‘atomic’
100%[======================================>] 12,594 --.-K/s in
2018-05-04 08:57:36 (132 MB/s) - ‘atomic’ saved [12594/12594]
[root@VM_0_10_centos ~]# sh ./atomic
Atomic Free Unsupported Archive installer, version 4.0
BY INSTALLING THIS SOFTWARE AND BY USING ANY AND ALL SOFTWARE
PROVIDED BY ATOMICORP LIMITED YOU ACKNOWLEDGE AND AGREE:
THIS SOFTWARE AND ALL SOFTWARE PROVIDED IN THIS REPOSITORY IS
PROVIDED BY ATOMICORP LIMITED AS IS, IS UNSUPPORTED AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ATOMICORP LIMITED, THE
COPYRIGHT OWNER OR ANY CONTRIBUTOR TO ANY AND ALL SOFTWARE PROVIDED
BY OR PUBLISHED IN THIS REPOSITORY BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
For supported software packages please contact us at:
sales@atomicorp.com
Do you agree to these terms? (yes/no) [Default: yes] yes
Configuring the [atomic] repo archive for this system
Installing the Atomic GPG keys: OK
Downloading atomic-release-1.0-21.el7.art.noarch.rpm: Preparing... ################################# [100%]
Updating / installing...
1:atomic-release-1.0-21.el7.art #################################
OK
Enable repo by default? (yes/no) [Default: yes]: yes
The Atomic repo has now been installed and configured for your system
The following channels are available:
atomic - [ACTIVATED] - contains the stable tree of ART packa
atomic-testing - [DISABLED] - contains the testing tree of ART pack
atomic-bleeding - [DISABLED] - contains the development tree of ART
[root@VM_0_10_centos ~]# yum check-update
5.安装nginx
yum remove httpd* php* #删除系统自带的软件包
yum install nginx #安装nginx 根据提示输入y进行安装
chkconfig nginx on #设置nginx开机启动
service nginx start #启动nginx
以下为操作参考
[root@VM_0_10_centos ~]# yum install nginx
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* atomic: mirrors.neusoft.edu.cn
Resolving Dependencies
-->
...省略....
--> Finished Dependency Resolution
Dependencies Resolved
=======================================================================
Package Arch Version Repository
Size
=======================================================================
Installing:
nginx x86_64 1:1.13.12-4308.el7.art atomic 750 k
Updating for dependencies:
openssl x86_64 1:1.0.2k-8.el7 os 492 k
openssl-libs x86_64 1:1.0.2k-8.el7 os 1.2 M
Transaction Summary
=======================================================================
Install 1 Package
Upgrade ( 2 Dependent packages)
Total download size: 2.4 M
Is this ok [y/d/N]: y
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/3): openssl-1.0.2k-8.el7.x86_64.rpm | 492 kB 00:00
(2/3): openssl-libs-1.0.2k-8.el7.x86_64.rpm | 1.2 MB 00:00
(3/3): nginx-1.13.12-4308.el7.art.x86_64.rpm | 750 kB 00:01
-----------------------------------------------------------------------
Total 2.3 MB/s | 2.4 MB 00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
Updating : 1:openssl-libs-1.0.2k-8.el7.x86_64 1/5
Updating : 1:openssl-1.0.2k-8.el7.x86_64 2/5
Installing : 1:nginx-1.13.12-4308.el7.art.x86_64 3/5
----------------------------------------------------------------------
Thanks for using nginx!
Please find the official documentation for nginx here:
* http://nginx.org/en/docs/
Please subscribe to nginx-announce mailing list to get
the most important news about nginx:
* http://nginx.org/en/support.html
Commercial subscriptions for nginx are available on:
* http://nginx.com/products/
----------------------------------------------------------------------
Cleanup : 1:openssl-1.0.1e-60.el7_3.1.x86_64 4/5
Cleanup : 1:openssl-libs-1.0.1e-60.el7_3.1.x86_64 5/5
Verifying : 1:nginx-1.13.12-4308.el7.art.x86_64 1/5
Verifying : 1:openssl-libs-1.0.2k-8.el7.x86_64 2/5
Verifying : 1:openssl-1.0.2k-8.el7.x86_64 3/5
Verifying : 1:openssl-1.0.1e-60.el7_3.1.x86_64 4/5
Verifying : 1:openssl-libs-1.0.1e-60.el7_3.1.x86_64 5/5
Installed:
nginx.x86_64 1:1.13.12-4308.el7.art
Dependency Updated:
openssl.x86_64 1:1.0.2k-8.el7 openssl-libs.x86_64 1:1.0.2k-8.el7
Complete!
[root@VM_0_10_centos ~]# chkconfig nginx on
Note: Forwarding request to 'systemctl enable nginx.service'.
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[root@VM_0_10_centos ~]# service nginx start
Redirecting to /bin/systemctl start nginx.service
centOS7的命令变化了 这里可以看得出
然后我们在浏览器访问自己的ip,应该可以看到nginx欢迎界面了
最后,可以看到nginx安装后主要用到这么几个文件夹
[root@VM_0_10_centos /]# find -name nginx
./etc/sysconfig/nginx
./etc/nginx //配置文件夹
./etc/logrotate.d/nginx
./var/cache/nginx
./var/log/nginx //日志文件夹
./usr/sbin/nginx //主程序文件夹
./usr/lib64/nginx
./usr/libexec/initscripts/legacy-actions/nginx
./usr/share/nginx //以后网站可以放这里
一会儿我们再来配置nginx
6.安装MySQL
yum install mysql mysql-server #输入Y即可自动安装,直到安装完成
/etc/init.d/mysqld start #启动MySQL
chkconfig mysqld on #设为开机启动
cp /usr/share/mysql/my-medium.cnf /etc/my.cnf #拷贝配置文件(注意:如果/etc目录下面默认有一个my.cnf,直接覆盖即可)
为root账户设置密码
mysql_secure_installation 回车,根据提示输入,输入2次密码,回车,根据提示一路输入Y,最后出现:Thanks for using MySQL!
MySql密码设置完成,重新启动 MySQL:
/etc/init.d/mysqld restart #重启
/etc/init.d/mysqld stop #停止
/etc/init.d/mysqld start #启动
以下为操作记录
[root@VM_0_10_centos /]# yum install mysql mysql-server
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* atomic: mirrors.neusoft.edu.cn
No package mysql-server available.
Resolving Dependencies
--> Running transaction check
---> Package mariadb.x86_64 1:5.5.56-2.el7 will be installed
--> Processing Dependency: mariadb-libs(x86-64) = 1:5.5.56-2.el7 for package: 1:mariadb-5.5.56-2.el7.x86_64
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.52-1.el7 will be updated
---> Package mariadb-libs.x86_64 1:5.5.56-2.el7 will be an update
--> Finished Dependency Resolution
Dependencies Resolved
=======================================================================
Package Arch Version Repository
Size
=======================================================================
Installing:
mariadb x86_64 1:5.5.56-2.el7 os 8.7 M
Updating for dependencies:
mariadb-libs x86_64 1:5.5.56-2.el7 os 757 k
Transaction Summary
=======================================================================
Install 1 Package
Upgrade ( 1 Dependent package)
Total download size: 9.5 M
Is this ok [y/d/N]: y
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/2): mariadb-libs-5.5.56-2.el7.x86_64.rpm | 757 kB 00:00
(2/2): mariadb-5.5.56-2.el7.x86_64.rpm | 8.7 MB 00:00
-----------------------------------------------------------------------
Total 9.6 MB/s | 9.5 MB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating : 1:mariadb-libs-5.5.56-2.el7.x86_64 1/3
Installing : 1:mariadb-5.5.56-2.el7.x86_64 2/3
Cleanup : 1:mariadb-libs-5.5.52-1.el7.x86_64 3/3
Verifying : 1:mariadb-libs-5.5.56-2.el7.x86_64 1/3
Verifying : 1:mariadb-5.5.56-2.el7.x86_64 2/3
Verifying : 1:mariadb-libs-5.5.52-1.el7.x86_64 3/3
Installed:
mariadb.x86_64 1:5.5.56-2.el7
Dependency Updated:
mariadb-libs.x86_64 1:5.5.56-2.el7
Complete!
备注下
mysql-devel 开发用到的库以及包含文件
mysql mysql 客户端
mysql-server 数据库服务器
然鹅 No package mysql-server available.
mysql-server安装失败,垃圾哇,因为mysql被买走了,但是有一个mysql的马甲叫mariadb还是免费的,所以mysql换成mariadb就好了,我并没有删除mysql相关东西,直接重新下载mariadb看看
yum install mariadb-server mariadb //安装
systemctl start mariadb //启动
systemctl enable mariadb //开机启动
以下为操作记录
[root@VM_0_10_centos /]# yum install mariadb-server mariadb
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* atomic: mirrors.neusoft.edu.cn
Package 1:mariadb-5.5.56-2.el7.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
...省略...
--> Finished Dependency Resolution
Dependencies Resolved
=======================================================================
Package Arch Version Repository
Size
=======================================================================
Installing:
mariadb-server x86_64 1:5.5.56-2.el7 os 11 M
Installing for dependencies:
perl-Compress-Raw-Bzip2 x86_64 2.061-3.el7 os 32 k
perl-Compress-Raw-Zlib x86_64 1:2.061-4.el7 os 57 k
perl-DBD-MySQL x86_64 4.023-5.el7 os 140 k
perl-DBI x86_64 1.627-4.el7 os 802 k
perl-Data-Dumper x86_64 2.145-3.el7 os 47 k
perl-IO-Compress noarch 2.061-2.el7 os 260 k
perl-Net-Daemon noarch 0.48-5.el7 os 51 k
perl-PlRPC noarch 0.2020-14.el7 os 36 k
Transaction Summary
=======================================================================
Install 1 Package (+8 Dependent packages)
Total download size: 13 M
Installed size: 62 M
Is this ok [y/d/N]: y
Downloading packages:
(1/9): perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64 | 32 kB 00:00
(2/9): perl-Compress-Raw-Zlib-2.061-4.el7.x86_64. | 57 kB 00:00
(3/9): perl-DBD-MySQL-4.023-5.el7.x86_64.rpm | 140 kB 00:00
(4/9): perl-DBI-1.627-4.el7.x86_64.rpm | 802 kB 00:00
(5/9): perl-Data-Dumper-2.145-3.el7.x86_64.rpm | 47 kB 00:00
(6/9): perl-IO-Compress-2.061-2.el7.noarch.rpm | 260 kB 00:00
(7/9): perl-Net-Daemon-0.48-5.el7.noarch.rpm | 51 kB 00:00
(8/9): perl-PlRPC-0.2020-14.el7.noarch.rpm | 36 kB 00:00
(9/9): mariadb-server-5.5.56-2.el7.x86_64.rpm | 11 MB 00:01
-----------------------------------------------------------------------
Total 9.5 MB/s | 13 MB 00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : perl-Data-Dumper-2.145-3.el7.x86_64 1/9
Installing : perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64 2/9
Installing : 1:perl-Compress-Raw-Zlib-2.061-4.el7.x86_64 3/9
Installing : perl-IO-Compress-2.061-2.el7.noarch 4/9
Installing : perl-Net-Daemon-0.48-5.el7.noarch 5/9
Installing : perl-PlRPC-0.2020-14.el7.noarch 6/9
Installing : perl-DBI-1.627-4.el7.x86_64 7/9
Installing : perl-DBD-MySQL-4.023-5.el7.x86_64 8/9
Installing : 1:mariadb-server-5.5.56-2.el7.x86_64 9/9
Verifying : perl-DBI-1.627-4.el7.x86_64 1/9
Verifying : perl-Net-Daemon-0.48-5.el7.noarch 2/9
Verifying : perl-Data-Dumper-2.145-3.el7.x86_64 3/9
Verifying : perl-PlRPC-0.2020-14.el7.noarch 4/9
Verifying : 1:perl-Compress-Raw-Zlib-2.061-4.el7.x86_64 5/9
Verifying : perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64 6/9
Verifying : 1:mariadb-server-5.5.56-2.el7.x86_64 7/9
Verifying : perl-IO-Compress-2.061-2.el7.noarch 8/9
Verifying : perl-DBD-MySQL-4.023-5.el7.x86_64 9/9
Installed:
mariadb-server.x86_64 1:5.5.56-2.el7
Dependency Installed:
perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7
perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7
perl-DBD-MySQL.x86_64 0:4.023-5.el7
perl-DBI.x86_64 0:1.627-4.el7
perl-Data-Dumper.x86_64 0:2.145-3.el7
perl-IO-Compress.noarch 0:2.061-2.el7
perl-Net-Daemon.noarch 0:0.48-5.el7
perl-PlRPC.noarch 0:0.2020-14.el7
Complete!
[root@VM_0_10_centos /]# systemctl start mariadb
[root@VM_0_10_centos /]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.56-MariaDB MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
MariaDB [mysql]> Ctrl-C -- exit!
Aborted
[root@VM_0_10_centos /]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
参考
centos7 mysql数据库安装和配置
Mariadb安装之后的各种设置
先这样 回头我们还要配置远程连接
7.安装PHP5
yum install php php-fpm #根据提示输入Y直到安装完成
安装PHP组件,使PHP5支持MySQL
yum install php-mysql php-gd libjpeg* php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-bcmath php-mhash libmcrypt #这里选择以上安装包进行安装,根据提示输入Y回车
chkconfig php-fpm on #设置php-fpm开机启动
/etc/init.d/php-fpm start #启动php-fpm
9.php配置
vi /etc/php.ini #编辑
;date.timezone = #把前面的分号去掉,改为date.timezone = PRC
disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname
#在386行 列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用。
expose_php = Off #禁止显示php版本的信息
short_open_tag = ON #支持php短标签
open_basedir = 网站根目录:/tmp/
#设置表示允许访问当前目录(即PHP脚本文件所在之目录)和/tmp/目录;冒号为分隔符。
:wq! #保存退出
open_basedir配置选项中有些教程会配置为open_basedir=.:/tmp/,其中’.’代表当前目录。这种方式在nginx+phpfastcgi下好像行不通。
配置php-fpm
cp /etc/php-fpm.d/www.conf /etc/php-fpm.d/www.confbak #备份原有配置文件
vi /etc/php-fpm.d/www.conf #编辑
user = nginx #修改用户为nginx
group = nginx #修改组为nginx
:wq #保存退出
8.配置nginx支持php
cp /etc/nginx/nginx.conf /etc/nginx/nginx.confbak #备份原有配置文件
vi /etc/nginx/nginx.conf #编辑
user nginx nginx; #修改nginx运行账号为:nginx组的nginx用户
:wq #保存退出
cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.confbak #备份原有配置文件
vi /etc/nginx/conf.d/default.conf #编辑
index index.php index.html index.htm; #增加index.php
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;#此处改成跟location的root一致的 可能为use/share/nginx/html
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
#取消FastCGI server部分location的注释,并要注意fastcgi_param行的参数,改为$document_root$fastcgi_script_name,或者使用绝对路径
service nginx restart #重启nginx
10.测试
cd /usr/share/nginx/html
vi index.php #添加以下代码
<?php
phpinfo();
?>
:wq! #保存退出
chown nginx.nginx /usr/share/nginx/html -R #设置权限
service nginx restart #重启nginx
service php-fpm restart #重启php-fpm
在客户端浏览器输入服务器IP地址,可以看到相关的配置信息!说明lnmp配置成功!
然后其实我看到的还是nginx的欢迎界面不是phpinfo
这里需要把ngnix的配置的index一行把index.php写在index.html前面
至此,CnetOS 安装配置LNMP(Nginx+PHP+MySQL)完成。
接下来还有几件事
服务器放了几个网站的话 nginx的url重写
另外说吧
域名配置,
在vps设置
设置mysqlroot密码
MariaDB [(none)]> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('ABCDE');
Query OK, 0 rows affected (0.00 sec)
设置远程账户
MariaDB [(none)]> grant all on *.* to 'remote'@'%' identified by 'yourpassword';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
此处我没有需要设置3306端口什么的,连接就成功了