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

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

本文实例讲述了CentOS7系统搭建LAMP及更新PHP版本操作。分享给大家供大家参考,具体如下: 搭建LAMP环境 用yum安装 安装Apache 安装Apache [[email protected] /]# yum install httpd httpd-devel 启动Apache [[email protected] /]# systemctl start httpd 设置Apache开机启动 [[email protected] /]# systemctl enable httpdCreated symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service. 查看Apache状态 [[email protected] /]# 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 -DFOREGROUND7月 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...ssage7月 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. 防火墙开启80端口, 依此执行以下命令 [[email protected] /]# firewall-cmd --permanent --zone=public --add-service=httpsuccess[[email protected] /]# firewall-cmd --permanent --zone=public --add-service=httpssuccess[[email protected] /]# firewall-cmd --reloadsuccess 查看80端口监听状态 [[email protected] /]# netstat -tulpActive 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 查看服务器IP [[email protected] /]# ip addr1: 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 forever2: 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 forever3: 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 浏览器登陆查看 安装mysql 安装mysql [[email protected] /]# yum install mariadb mariadb-server mariadb-libs mariadb-devel[[email protected] /]# rpm -qa |grep mariamariadb-libs-5.5.52-1.el7.i686mariadb-5.5.52-1.el7.i686mariadb-server-5.5.52-1.el7.i686mariadb-devel-5.5.52-1.el7.i686 开启Mysql,并设置开机启动,检查状态 [[email protected] /]# systemctl start mariadb [[email protected] /]# systemctl enable mariadb Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.[[email protected] /]# 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 ... 查看监听状态 [[email protected] /]# netstat -tulpActive 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 数据库安全设置 [[email protected] /]# 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 currentpassword for the root user. If you've just installed MariaDB, andyou 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 MariaDBroot user without the proper authorisation.Set root password? [Y/n] yNew password: Re-enter new password: Password updated successfully!Reloading privilege tables.. ... Success!By default, a MariaDB installation has an anonymous user, allowing anyoneto log into MariaDB without having to have a user account created forthem. This is intended only for testing, and to make the installationgo a bit smoother. You should remove them before moving into aproduction environment.Remove anonymous users? [Y/n] y ... Success!Normally, root should only be allowed to connect from 'localhost'. Thisensures 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 canaccess. This is also intended only for testing, and should be removedbefore 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 farwill 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 MariaDBinstallation should now be secure.Thanks for using MariaDB! 登陆数据库测试 [[email protected] /]# mysql -uroot -pEnter password: Welcome to the MariaDB monitor. Commands end with ; or \g.Your MariaDB connection id is 11Server version: 5.5.52-MariaDB MariaDB ServerCopyright (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 安装PHP [[email protected] /]# yum -y install php[[email protected] /]# 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 将php与mysql关联起来 [[email protected] /]# yum install php-mysql[[email protected] /]# 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 安装常用PHP模块 [[email protected] /]# 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 测试PHP [[email protected] /]# cd /var/www/html/[[email protected] /]# ls[[email protected] /]# pwd/var/www/html[[email protected] /]# vi info.php<?php phpinfo();?>~ ~ ~ ~ ~ ~ ~ ~ :wq 重启Apache [[email protected] /]# systemctl restart httpd 测试PHP 更新PHP版本 首先查看是否有老版本 [[email protected] /]# yum list installed | grep php 移除老版本 [[email protected] /]# 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 由于linux的yum源不存在php7.x,所以我们要更改yum源: [[email protected] /]# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm[[email protected] /]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm 查看yum源中有没有php7.x [[email protected] /]# yum search php7Loaded plugins: fastestmirror, langpacksLoading mirror speeds from cached hostfileepel/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.comepel | 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 Servermod_php72w.x86_64 : PHP module for the Apache HTTP Serverphp70w.x86_64 : PHP scripting language for creating dynamic web sitesphp70w-bcmath.x86_64 : A module for PHP applications for using the bcmath libraryphp70w-cli.x86_64 : Command-line interface for PHPphp70w-common.x86_64 : Common files for PHPphp70w-dba.x86_64 : A database abstraction layer module for PHP applicationsphp70w-devel.x86_64 : Files needed for building PHP extensionsphp70w-embedded.x86_64 : PHP library for embedding in applicationsphp70w-enchant.x86_64 : Enchant spelling extension for PHP applicationsphp70w-fpm.x86_64 : PHP FastCGI Process Managerphp70w-gd.x86_64 : A module for PHP applications for using the gd graphics libraryphp70w-imap.x86_64 : A module for PHP applications that use IMAPphp70w-interbase.x86_64 : A module for PHP applications that use Interbase/Firebird databasesphp70w-intl.x86_64 : Internationalization extension for PHP applicationsphp70w-ldap.x86_64 : A module for PHP applications that use LDAPphp70w-mbstring.x86_64 : A module for PHP applications which need multi-byte string handlingphp70w-mcrypt.x86_64 : Standard PHP module provides mcrypt library supportphp70w-mysql.x86_64 : A module for PHP applications that use MySQL databasesphp70w-mysqlnd.x86_64 : A module for PHP applications that use MySQL databasesphp70w-odbc.x86_64 : A module for PHP applications that use ODBC databasesphp70w-opcache.x86_64 : An opcode cache Zend extensionphp70w-pdo.x86_64 : A database access abstraction module for PHP applicationsphp70w-pdo_dblib.x86_64 : MSSQL database module for PHPphp70w-pear.noarch : PHP Extension and Application Repository frameworkphp70w-pecl-apcu.x86_64 : APCu - APC User Cachephp70w-pecl-apcu-devel.x86_64 : APCu developer files (header)php70w-pecl-geoip.x86_64 : Extension to map IP addresses to geographic placesphp70w-pecl-igbinary.x86_64 : Replacement for the standard PHP serializerphp70w-pecl-igbinary-devel.x86_64 : Igbinary developer files (header)php70w-pecl-imagick.x86_64 : Provides a wrapper to the ImageMagick libraryphp70w-pecl-imagick-devel.x86_64 : Imagick developer files (header)php70w-pecl-memcached.x86_64 : Extension to work with the Memcached caching daemonphp70w-pecl-mongodb.x86_64 : PECL package MongoDB driverphp70w-pecl-redis.x86_64 : Extension for communicating with the Redis key-value storephp70w-pecl-xdebug.x86_64 : PECL package for debugging PHP scriptsphp70w-pgsql.x86_64 : A PostgreSQL database module for PHPphp70w-phpdbg.x86_64 : Interactive PHP debuggerphp70w-process.x86_64 : Modules for PHP script using system process interfacesphp70w-pspell.x86_64 : A module for PHP applications for using pspell interfacesphp70w-recode.x86_64 : A module for PHP applications for using the recode libraryphp70w-snmp.x86_64 : A module for PHP applications that query SNMP-managed devicesphp70w-soap.x86_64 : A module for PHP applications that use the SOAP protocolphp70w-tidy.x86_64 : Standard PHP module provides tidy library supportphp70w-xml.x86_64 : A module for PHP applications which use XMLphp70w-xmlrpc.x86_64 : A module for PHP applications which use the XML-RPC protocolphp71w-bcmath.x86_64 : A module for PHP applications for using the bcmath libraryphp71w-cli.x86_64 : Command-line interface for PHPphp71w-common.x86_64 : Common files for PHPphp71w-dba.x86_64 : A database abstraction layer module for PHP applicationsphp71w-devel.x86_64 : Files needed for building PHP extensionsphp71w-embedded.x86_64 : PHP library for embedding in applicationsphp71w-enchant.x86_64 : Enchant spelling extension for PHP applicationsphp71w-fpm.x86_64 : PHP FastCGI Process Managerphp71w-gd.x86_64 : A module for PHP applications for using the gd graphics libraryphp71w-imap.x86_64 : A module for PHP applications that use IMAPphp71w-interbase.x86_64 : A module for PHP applications that use Interbase/Firebird databasesphp71w-intl.x86_64 : Internationalization extension for PHP applicationsphp71w-ldap.x86_64 : A module for PHP applications that use LDAPphp71w-mbstring.x86_64 : A module for PHP applications which need multi-byte string handlingphp71w-mcrypt.x86_64 : Standard PHP module provides mcrypt library supportphp71w-mysql.x86_64 : A module for PHP applications that use MySQL databasesphp71w-mysqlnd.x86_64 : A module for PHP applications that use MySQL databasesphp71w-odbc.x86_64 : A module for PHP applications that use ODBC databasesphp71w-opcache.x86_64 : An opcode cache Zend extensionphp71w-pdo.x86_64 : A database access abstraction module for PHP applicationsphp71w-pdo_dblib.x86_64 : MSSQL database module for PHPphp71w-pear.noarch : PHP Extension and Application Repository frameworkphp71w-pecl-apcu.x86_64 : APCu - APC User Cachephp71w-pecl-apcu-devel.x86_64 : APCu developer files (header)php71w-pecl-geoip.x86_64 : Extension to map IP addresses to geographic placesphp71w-pecl-igbinary.x86_64 : Replacement for the standard PHP serializerphp71w-pecl-igbinary-devel.x86_64 : Igbinary developer files (header)php71w-pecl-imagick.x86_64 : Provides a wrapper to the ImageMagick libraryphp71w-pecl-imagick-devel.x86_64 : Imagick developer files (header)php71w-pecl-memcached.x86_64 : Extension to work with the Memcached caching daemonphp71w-pecl-mongodb.x86_64 : PECL package MongoDB driverphp71w-pecl-redis.x86_64 : Extension for communicating with the Redis key-value storephp71w-pecl-xdebug.x86_64 : PECL package for debugging PHP scriptsphp71w-pgsql.x86_64 : A PostgreSQL database module for PHPphp71w-phpdbg.x86_64 : Interactive PHP debuggerphp71w-process.x86_64 : Modules for PHP script using system process interfacesphp71w-pspell.x86_64 : A module for PHP applications for using pspell interfacesphp71w-recode.x86_64 : A module for PHP applications for using the recode libraryphp71w-snmp.x86_64 : A module for PHP applications that query SNMP-managed devicesphp71w-soap.x86_64 : A module for PHP applications that use the SOAP protocolphp71w-tidy.x86_64 : Standard PHP module provides tidy library supportphp71w-xml.x86_64 : A module for PHP applications which use XMLphp71w-xmlrpc.x86_64 : A module for PHP applications which use the XML-RPC protocolphp72w-bcmath.x86_64 : A module for PHP applications for using the bcmath libraryphp72w-cli.x86_64 : Command-line interface for PHPphp72w-common.x86_64 : Common files for PHPphp72w-dba.x86_64 : A database abstraction layer module for PHP applicationsphp72w-devel.x86_64 : Files needed for building PHP extensionsphp72w-embedded.x86_64 : PHP library for embedding in applicationsphp72w-enchant.x86_64 : Enchant spelling extension for PHP applicationsphp72w-fpm.x86_64 : PHP FastCGI Process Managerphp72w-gd.x86_64 : A module for PHP applications for using the gd graphics libraryphp72w-imap.x86_64 : A module for PHP applications that use IMAPphp72w-interbase.x86_64 : A module for PHP applications that use Interbase/Firebird databasesphp72w-intl.x86_64 : Internationalization extension for PHP applicationsphp72w-ldap.x86_64 : A module for PHP applications that use LDAPphp72w-mbstring.x86_64 : A module for PHP applications which need multi-byte string handlingphp72w-mysql.x86_64 : A module for PHP applications that use MySQL databasesphp72w-mysqlnd.x86_64 : A module for PHP applications that use MySQL databasesphp72w-odbc.x86_64 : A module for PHP applications that use ODBC databasesphp72w-opcache.x86_64 : An opcode cache Zend extensionphp72w-pdo.x86_64 : A database access abstraction module for PHP applicationsphp72w-pdo_dblib.x86_64 : MSSQL database module for PHPphp72w-pear.noarch : PHP Extension and Application Repository frameworkphp72w-pecl-apcu.x86_64 : APCu - APC User Cachephp72w-pecl-apcu-devel.x86_64 : APCu developer files (header)php72w-pecl-geoip.x86_64 : Extension to map IP addresses to geographic placesphp72w-pecl-igbinary.x86_64 : Replacement for the standard PHP serializerphp72w-pecl-igbinary-devel.x86_64 : Igbinary developer files (header)php72w-pecl-imagick.x86_64 : Provides a wrapper to the ImageMagick libraryphp72w-pecl-imagick-devel.x86_64 : Imagick developer files (header)php72w-pecl-libsodium.x86_64 : Wrapper for the Sodium cryptographic libraryphp72w-pecl-memcached.x86_64 : Extension to work with the Memcached caching daemonphp72w-pecl-mongodb.x86_64 : PECL package MongoDB driverphp72w-pecl-redis.x86_64 : Extension for communicating with the Redis key-value storephp72w-pecl-xdebug.x86_64 : PECL package for debugging PHP scriptsphp72w-pgsql.x86_64 : A PostgreSQL database module for PHPphp72w-phpdbg.x86_64 : Interactive PHP debuggerphp72w-process.x86_64 : Modules for PHP script using system process interfacesphp72w-pspell.x86_64 : A module for PHP applications for using pspell interfacesphp72w-recode.x86_64 : A module for PHP applications for using the recode libraryphp72w-snmp.x86_64 : A module for PHP applications that query SNMP-managed devicesphp72w-soap.x86_64 : A module for PHP applications that use the SOAP protocolphp72w-sodium.x86_64 : Wrapper for the Sodium cryptographic libraryphp72w-tidy.x86_64 : Standard PHP module provides tidy library supportphp72w-xml.x86_64 : A module for PHP applications which use XMLphp72w-xmlrpc.x86_64 : A module for PHP applications which use the XML-RPC protocol Name and summary matches only, use "search all" for everything. yum 安装php72w和各种拓展,选自己需要的即可: [[email protected] /]# 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 完成安装 , 查看PHP版本 [[email protected] /]# php -v 重启服务器 [[email protected] /]# systemctl restart httpd 希望本文所述对大家centos系统配置有所帮助。...
微信二维码