CentOS7系统搭建LAMP及更新PHP版本操作详解

吾爱主题 阅读:129 2021-10-06 13:53:00 评论:0

本文实例讲述了centos7系统搭建lamp及更新php版本操作。分享给大家供大家参考,具体如下:

搭建lamp环境 用yum安装

安装apache
  1. 安装apache
?
1 [root@localhost /]# yum install httpd httpd-devel
  1. 启动apache
?
1 [root@localhost /]# systemctl start httpd
  1. 设置apache开机启动
?
1 2 [root@localhost /]# systemctl enable httpd created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
  1. 查看apache状态
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 [root@localhost /]# systemctl status httpd ● httpd.service - the apache http server    loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)    active: active (running) since 五 2017-07-21 17:21:37 cst; 6min ago     docs: man:httpd(8)        man:apachectl(8)   main pid: 2449 (httpd)    status: "total requests: 11; current requests/sec: 0; current traffic:  0 b/sec"    cgroup: /system.slice/httpd.service        ├─2449 /usr/sbin/httpd -dforeground        ├─2450 /usr/sbin/httpd -dforeground        ├─2451 /usr/sbin/httpd -dforeground        ├─2452 /usr/sbin/httpd -dforeground        ├─2453 /usr/sbin/httpd -dforeground        ├─2454 /usr/sbin/httpd -dforeground        ├─2493 /usr/sbin/httpd -dforeground        ├─2494 /usr/sbin/httpd -dforeground        └─2495 /usr/sbin/httpd -dforeground   7月 21 17:21:35 nmserver-7.test.com systemd[1]: starting the apache http server... 7月 21 17:21:36 nmserver-7.test.com httpd[2449]: ah00558: httpd: could not reliably determine the server's fully q...ssage 7月 21 17:21:37 nmserver-7.test.com systemd[1]: started the apache http server. hint: some lines were ellipsized, use -l to show in full.
  1. 防火墙开启80端口, 依此执行以下命令
?
1 2 3 4 5 6 [root@localhost /]# firewall-cmd --permanent --zone= public --add-service=http success [root@localhost /]# firewall-cmd --permanent --zone= public --add-service=https success [root@localhost /]# firewall-cmd --reload success
  1. 查看80端口监听状态
?
1 2 3 4 5 6 7 8 9 10 [root@localhost /]# netstat -tulp active internet connections (only servers) proto recv-q send-q local address      foreign address     state    pid/program name  tcp    0   0 0.0.0.0:ssh       0.0.0.0:*        listen   1084/sshd      tcp    0   0 localhost:smtp     0.0.0.0:*        listen   1486/master     tcp6    0   0 [::]:ssh        [::]:*         listen   1084/sshd      tcp6    0   0 localhost:smtp     [::]:*         listen   1486/master     tcp6    0   0 [::]:http        [::]:*         listen   2449/httpd     udp    0   0 localhost:323      0.0.0.0:*              592/chronyd     udp6    0   0 localhost:323      [::]:*               592/chronyd
  1. 查看服务器ip
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 [root@localhost /]# ip addr 1: lo: <loopback,up,lower_up> mtu 65536 qdisc noqueue state unknown qlen 1    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00    inet 127.0.0.1/8 scope host lo      valid_lft forever preferred_lft forever    inet6 ::1/128 scope host      valid_lft forever preferred_lft forever 2: ens33: <broadcast,multicast,up,lower_up> mtu 1500 qdisc pfifo_fast state up qlen 1000    link/ether 00:0c:29:56:bc:cf brd ff:ff:ff:ff:ff:ff    inet 192.168.5.133/24 brd 192.168.8.255 scope global ens33      valid_lft forever preferred_lft forever    inet6 fe80::20c:29ff:fe56:bccf/64 scope link      valid_lft forever preferred_lft forever 3: bridge0: <no-carrier,broadcast,multicast,up> mtu 1500 qdisc noqueue state down qlen 1000    link/ether ea:89:d5:c7:32:73 brd ff:ff:ff:ff:ff:ff
  1. 浏览器登陆查看
安装mysql
  1. 安装mysql
?
1 2 3 4 5 6 [root@localhost /]# yum install mariadb mariadb-server mariadb-libs mariadb-devel [root@localhost /]# rpm -qa |grep maria mariadb-libs-5.5.52-1.el7.i686 mariadb-5.5.52-1.el7.i686 mariadb-server-5.5.52-1.el7.i686 mariadb-devel-5.5.52-1.el7.i686
  1. 开启mysql,并设置开机启动,检查状态
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 [root@localhost /]# systemctl start mariadb [root@localhost /]# systemctl enable mariadb created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service. [root@localhost /]# systemctl status mariadb ● mariadb.service - mariadb database server    loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)    active: active (running) since 六 2017-07-22 21:19:20 cst; 21s ago   main pid: 9603 (mysqld_safe)    cgroup: /system.slice/mariadb.service        ├─9603 /bin/sh /usr/bin/mysqld_safe --basedir=/usr        └─9760 /usr/libexec/mysqld --basedir=/usr --datadir=/v...   7月 22 21:19:15 nmserver-7.test.com mariadb-prepare-db-dir[9524]: ... 7月 22 21:19:15 nmserver-7.test.com mariadb-prepare-db-dir[9524]: ... 7月 22 21:19:15 nmserver-7.test.com mariadb-prepare-db-dir[9524]: ... 7月 22 21:19:15 nmserver-7.test.com mariadb-prepare-db-dir[9524]: ... 7月 22 21:19:15 nmserver-7.test.com mariadb-prepare-db-dir[9524]: ... 7月 22 21:19:15 nmserver-7.test.com mariadb-prepare-db-dir[9524]: ... 7月 22 21:19:15 nmserver-7.test.com mariadb-prepare-db-dir[9524]: ... 7月 22 21:19:16 nmserver-7.test.com mysqld_safe[9603]: 170722 21... 7月 22 21:19:16 nmserver-7.test.com mysqld_safe[9603]: 170722 21... 7月 22 21:19:20 nmserver-7.test.com systemd[1]: started mariadb ...
  1. 查看监听状态
?
1 2 3 4 5 6 7 8 9 [root@localhost /]# netstat -tulp active internet connections (only servers) proto recv-q send-q local address      foreign address     state    pid/program name  tcp    0   0 0.0.0.0:ssh       0.0.0.0:*        listen   1084/sshd      tcp    0   0 0.0.0.0:mysql      0.0.0.0:*        listen   9760/mysqld     tcp6    0   0 [::]:ssh        [::]:*         listen   1084/sshd      tcp6    0   0 [::]:http        [::]:*         listen   2449/httpd     udp    0   0 localhost:323      0.0.0.0:*              592/chronyd     udp6    0   0 localhost:323      [::]:*               592/chronyd
  1. 数据库安全设置
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 [root@localhost /]# mysql_secure_installation   note: running all parts of this script is recommended for all mariadb     servers in production use ! please read each step carefully!   in order to log into mariadb to secure it, we'll need the current password for the root user. if you've just installed mariadb, and you haven't set the root password yet, the password will be blank, so you should just press enter here.   enter current password for root (enter for none): ok, successfully used password, moving on...   setting the root password ensures that nobody can log into the mariadb root user without the proper authorisation.   set root password? [y/n] y new password: re-enter new password: password updated successfully! reloading privilege tables..   ... success!     by default , a mariadb installation has an anonymous user, allowing anyone to log into mariadb without having to have a user account created for them. this is intended only for testing, and to make the installation go a bit smoother. you should remove them before moving into a production environment.   remove anonymous users? [y/n] y   ... success!   normally, root should only be allowed to connect from 'localhost' . this ensures that someone cannot guess at the root password from the network.   disallow root login remotely? [y/n] n   ... skipping.   by default , mariadb comes with a database named 'test' that anyone can access. this is also intended only for testing, and should be removed before moving into a production environment.   remove test database and access to it? [y/n] y   - dropping test database...   ... success!   - removing privileges on test database...   ... success!   reloading the privilege tables will ensure that all changes made so far will take effect immediately.   reload privilege tables now? [y/n] y   ... success!   cleaning up...   all done! if you've completed all of the above steps, your mariadb installation should now be secure.   thanks for using mariadb!
  1. 登陆数据库测试
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 [root@localhost /]# mysql -uroot -p enter password: welcome to the mariadb monitor. commands end with ; or \g. your mariadb connection id is 11 server version: 5.5.52-mariadb mariadb server   copyright (c) 2000, 2016, 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 | +--------------------+ 3 rows in set (0.02 sec)   mariadb [(none)]>
安装php
  1. 安装php
?
1 2 3 4 5 6 7 [root@localhost /]# yum -y install php [root@localhost /]# rpm -ql php /etc/httpd/conf.d/php.conf /etc/httpd/conf.modules.d/10-php.conf /usr/lib/httpd/modules/libphp5.so /usr/share/httpd/icons/php.gif / var /lib/php/session
  1. 将php与mysql关联起来
?
1 2 3 4 5 6 7 8 [root@localhost /]# yum install php-mysql [root@localhost /]# rpm -ql php-mysql /etc/php.d/mysql.ini /etc/php.d/mysqli.ini /etc/php.d/pdo_mysql.ini /usr/lib/php/modules/mysql.so /usr/lib/php/modules/mysqli.so /usr/lib/php/modules/pdo_mysql.so
  1. 安装常用php模块
?
1 [root@localhost /]# yum install -y php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel php-bcmath
  1. 测试php
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 [root@localhost /]# cd / var /www/html/ [root@localhost /]# ls [root@localhost /]# pwd / var /www/html [root@localhost /]# vi info.php   <?php      phpinfo(); ?> ~                                            ~                                            ~                                            ~                                            ~                                            ~                                            ~                                            ~                                      :wq
  1. 重启apache
?
1 [root@localhost /]# systemctl restart httpd
  1. 测试php

更新php版本

  1. 首先查看是否有老版本
?
1 [root@localhost /]# yum list installed | grep php
  1. 移除老版本
?
1 [root@localhost /]# yum remove php.x86_64 php-cli.x86_64 php-common.x86_64 php-gd.x86_64 php-ldap.x86_64 php-mbstring.x86_64 php-mcrypt.x86_64 php-mysql.x86_64 php-pdo.x86_64
  1. 由于linux的yum源不存在php7.x,所以我们要更改yum源:
?
1 2 [root@localhost /]# rpm -uvh https: //dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm [root@localhost /]# rpm -uvh https: //mirror.webtatic.com/yum/el7/webtatic-release.rpm
  1. 查看yum源中有没有php7.x
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 [root@localhost /]# yum search php7 loaded plugins: fastestmirror, langpacks loading mirror speeds from cached hostfile epel/x86_64/metalink                                                 | 5.9 kb 00:00:00     * base: mirrors.aliyun.com   * epel: my.mirrors.thegigabit.com   * extras: mirrors.cn99.com   * updates: mirrors.163.com   * webtatic: uk.repo.webtatic.com epel                                                         | 5.4 kb 00:00:00   webtatic                                                       | 3.6 kb 00:00:00   (1/5): epel/x86_64/group_gz                                              | 90 kb 00:00:01   (2/5): webtatic/x86_64/group_gz                                            | 448 b 00:00:04   (3/5): epel/x86_64/primary_db                                             | 6.9 mb 00:00:06   (4/5): epel/x86_64/updateinfo                                             | 1.0 mb 00:00:10   (5/5): webtatic/x86_64/primary_db                                           | 232 kb 00:00:14   ============================================================= n/s matched: php7 ============================================================= mod_php71w.x86_64 : php module for the apache http server mod_php72w.x86_64 : php module for the apache http server php70w.x86_64 : php scripting language for creating dynamic web sites php70w-bcmath.x86_64 : a module for php applications for using the bcmath library php70w-cli.x86_64 : command-line interface for php php70w-common.x86_64 : common files for php php70w-dba.x86_64 : a database abstraction layer module for php applications php70w-devel.x86_64 : files needed for building php extensions php70w-embedded.x86_64 : php library for embedding in applications php70w-enchant.x86_64 : enchant spelling extension for php applications php70w-fpm.x86_64 : php fastcgi process manager php70w-gd.x86_64 : a module for php applications for using the gd graphics library php70w-imap.x86_64 : a module for php applications that use imap php70w-interbase.x86_64 : a module for php applications that use interbase/firebird databases php70w-intl.x86_64 : internationalization extension for php applications php70w-ldap.x86_64 : a module for php applications that use ldap php70w-mbstring.x86_64 : a module for php applications which need multi-byte string handling php70w-mcrypt.x86_64 : standard php module provides mcrypt library support php70w-mysql.x86_64 : a module for php applications that use mysql databases php70w-mysqlnd.x86_64 : a module for php applications that use mysql databases php70w-odbc.x86_64 : a module for php applications that use odbc databases php70w-opcache.x86_64 : an opcode cache zend extension php70w-pdo.x86_64 : a database access abstraction module for php applications php70w-pdo_dblib.x86_64 : mssql database module for php php70w-pear.noarch : php extension and application repository framework php70w-pecl-apcu.x86_64 : apcu - apc user cache php70w-pecl-apcu-devel.x86_64 : apcu developer files (header) php70w-pecl-geoip.x86_64 : extension to map ip addresses to geographic places php70w-pecl-igbinary.x86_64 : replacement for the standard php serializer php70w-pecl-igbinary-devel.x86_64 : igbinary developer files (header) php70w-pecl-imagick.x86_64 : provides a wrapper to the imagemagick library php70w-pecl-imagick-devel.x86_64 : imagick developer files (header) php70w-pecl-memcached.x86_64 : extension to work with the memcached caching daemon php70w-pecl-mongodb.x86_64 : pecl package mongodb driver php70w-pecl-redis.x86_64 : extension for communicating with the redis key-value store php70w-pecl-xdebug.x86_64 : pecl package for debugging php scripts php70w-pgsql.x86_64 : a postgresql database module for php php70w-phpdbg.x86_64 : interactive php debugger php70w-process.x86_64 : modules for php script using system process interfaces php70w-pspell.x86_64 : a module for php applications for using pspell interfaces php70w-recode.x86_64 : a module for php applications for using the recode library php70w-snmp.x86_64 : a module for php applications that query snmp-managed devices php70w-soap.x86_64 : a module for php applications that use the soap protocol php70w-tidy.x86_64 : standard php module provides tidy library support php70w-xml.x86_64 : a module for php applications which use xml php70w-xmlrpc.x86_64 : a module for php applications which use the xml-rpc protocol php71w-bcmath.x86_64 : a module for php applications for using the bcmath library php71w-cli.x86_64 : command-line interface for php php71w-common.x86_64 : common files for php php71w-dba.x86_64 : a database abstraction layer module for php applications php71w-devel.x86_64 : files needed for building php extensions php71w-embedded.x86_64 : php library for embedding in applications php71w-enchant.x86_64 : enchant spelling extension for php applications php71w-fpm.x86_64 : php fastcgi process manager php71w-gd.x86_64 : a module for php applications for using the gd graphics library php71w-imap.x86_64 : a module for php applications that use imap php71w-interbase.x86_64 : a module for php applications that use interbase/firebird databases php71w-intl.x86_64 : internationalization extension for php applications php71w-ldap.x86_64 : a module for php applications that use ldap php71w-mbstring.x86_64 : a module for php applications which need multi-byte string handling php71w-mcrypt.x86_64 : standard php module provides mcrypt library support php71w-mysql.x86_64 : a module for php applications that use mysql databases php71w-mysqlnd.x86_64 : a module for php applications that use mysql databases php71w-odbc.x86_64 : a module for php applications that use odbc databases php71w-opcache.x86_64 : an opcode cache zend extension php71w-pdo.x86_64 : a database access abstraction module for php applications php71w-pdo_dblib.x86_64 : mssql database module for php php71w-pear.noarch : php extension and application repository framework php71w-pecl-apcu.x86_64 : apcu - apc user cache php71w-pecl-apcu-devel.x86_64 : apcu developer files (header) php71w-pecl-geoip.x86_64 : extension to map ip addresses to geographic places php71w-pecl-igbinary.x86_64 : replacement for the standard php serializer php71w-pecl-igbinary-devel.x86_64 : igbinary developer files (header) php71w-pecl-imagick.x86_64 : provides a wrapper to the imagemagick library php71w-pecl-imagick-devel.x86_64 : imagick developer files (header) php71w-pecl-memcached.x86_64 : extension to work with the memcached caching daemon php71w-pecl-mongodb.x86_64 : pecl package mongodb driver php71w-pecl-redis.x86_64 : extension for communicating with the redis key-value store php71w-pecl-xdebug.x86_64 : pecl package for debugging php scripts php71w-pgsql.x86_64 : a postgresql database module for php php71w-phpdbg.x86_64 : interactive php debugger php71w-process.x86_64 : modules for php script using system process interfaces php71w-pspell.x86_64 : a module for php applications for using pspell interfaces php71w-recode.x86_64 : a module for php applications for using the recode library php71w-snmp.x86_64 : a module for php applications that query snmp-managed devices php71w-soap.x86_64 : a module for php applications that use the soap protocol php71w-tidy.x86_64 : standard php module provides tidy library support php71w-xml.x86_64 : a module for php applications which use xml php71w-xmlrpc.x86_64 : a module for php applications which use the xml-rpc protocol php72w-bcmath.x86_64 : a module for php applications for using the bcmath library php72w-cli.x86_64 : command-line interface for php php72w-common.x86_64 : common files for php php72w-dba.x86_64 : a database abstraction layer module for php applications php72w-devel.x86_64 : files needed for building php extensions php72w-embedded.x86_64 : php library for embedding in applications php72w-enchant.x86_64 : enchant spelling extension for php applications php72w-fpm.x86_64 : php fastcgi process manager php72w-gd.x86_64 : a module for php applications for using the gd graphics library php72w-imap.x86_64 : a module for php applications that use imap php72w-interbase.x86_64 : a module for php applications that use interbase/firebird databases php72w-intl.x86_64 : internationalization extension for php applications php72w-ldap.x86_64 : a module for php applications that use ldap php72w-mbstring.x86_64 : a module for php applications which need multi-byte string handling php72w-mysql.x86_64 : a module for php applications that use mysql databases php72w-mysqlnd.x86_64 : a module for php applications that use mysql databases php72w-odbc.x86_64 : a module for php applications that use odbc databases php72w-opcache.x86_64 : an opcode cache zend extension php72w-pdo.x86_64 : a database access abstraction module for php applications php72w-pdo_dblib.x86_64 : mssql database module for php php72w-pear.noarch : php extension and application repository framework php72w-pecl-apcu.x86_64 : apcu - apc user cache php72w-pecl-apcu-devel.x86_64 : apcu developer files (header) php72w-pecl-geoip.x86_64 : extension to map ip addresses to geographic places php72w-pecl-igbinary.x86_64 : replacement for the standard php serializer php72w-pecl-igbinary-devel.x86_64 : igbinary developer files (header) php72w-pecl-imagick.x86_64 : provides a wrapper to the imagemagick library php72w-pecl-imagick-devel.x86_64 : imagick developer files (header) php72w-pecl-libsodium.x86_64 : wrapper for the sodium cryptographic library php72w-pecl-memcached.x86_64 : extension to work with the memcached caching daemon php72w-pecl-mongodb.x86_64 : pecl package mongodb driver php72w-pecl-redis.x86_64 : extension for communicating with the redis key-value store php72w-pecl-xdebug.x86_64 : pecl package for debugging php scripts php72w-pgsql.x86_64 : a postgresql database module for php php72w-phpdbg.x86_64 : interactive php debugger php72w-process.x86_64 : modules for php script using system process interfaces php72w-pspell.x86_64 : a module for php applications for using pspell interfaces php72w-recode.x86_64 : a module for php applications for using the recode library php72w-snmp.x86_64 : a module for php applications that query snmp-managed devices php72w-soap.x86_64 : a module for php applications that use the soap protocol php72w-sodium.x86_64 : wrapper for the sodium cryptographic library php72w-tidy.x86_64 : standard php module provides tidy library support php72w-xml.x86_64 : a module for php applications which use xml php72w-xmlrpc.x86_64 : a module for php applications which use the xml-rpc protocol     name and summary matches only, use "search all" for everything.
  1. yum 安装php72w和各种拓展,选自己需要的即可:
?
1 [root@localhost /]# yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-fpm php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml php72w-pear
  1. 完成安装 , 查看php版本
?
1 [root@localhost /]# php -v
  1. 重启服务器
?
1 [root@localhost /]# systemctl restart httpd

希望本文所述对大家centos系统配置有所帮助。

原文链接:https://blog.csdn.net/qq_36261130/article/details/103531728

可以去百度分享获取分享代码输入这里。
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

【腾讯云】云服务器产品特惠热卖中
搜索
标签列表
    关注我们

    了解等多精彩内容