Centos7.4 environment installation lamp-php7.0 tutorial

This article describes the method of installing lamp-php7.0 in Centos7.4 environment. Share with you for your reference, as follows:

1. Environmental preparation

Bridge mode

Can access the Internet

# ping www.baidu.com

If you can ping through, you can go to the Internet

Turn off the firewall

# systemctl disable firewalld //Disable firewall
# systemctl stop firewalld    //Turn off the firewall

Turn off seLinux

# vim /etc/selinux/config

To:

SELINUX=disabled

Configure Yum source

# cd /etc/yum.repos.d/
# mkdir repo_bak      //Create backup source folder
# mv *.repo repo_bak///Put all the source files in the backup folder
# wget http://mirrors.aliyun.com/repo/Centos-7.repo     //Configure Ali Source
# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo //Configure NetEase Source
# ls        //List/etc/yum.repos.d/Files in the directory
Centos-7.repo CentOS-Base-163.repo repo.bak
# yum clean all         //Clear all yum cache of the system
# yum makecache         //Generate yum cache
# yum list | grep epel-release     //View the epel source list
# yum install -y epel-release     //Install epel source
# ls         //The epel source is installed successfully, one more epel than the original.repo and epel-testing.repo file
Centos-7.repo CentOS-Base-163.repo epel.repo epel-testing.repo repo.bak
# wget -O /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo         //Download Aliyuan's epel source
# ls
CentOS7-Base-163.repo Centos-7.repo epel-7.repo epel.repo epel-testing.repo repo_bak
# yum clean all        //Clear system yum cache again
# yum makecache        //Regenerate a new yum cache
# yum repolist enabled        //View yum sources available to the system
# yum repolist all            //View all yum sources

Delete old version

# yum -y remove php

2. Apache

  1. Install Apache
# yum install httpd
  1. Configure Apache
# vim /etc/httpd/conf/httpd.conf
//search for
# AddType application/x-gzip .gz .tgz
//Then add
# AddType application/x-httpd-php .php
//search for
# IfModule dir_module
//Add index under DirectoryIndex.php//modify#ServerName www.example.com:80
# ServerName localhost:80

Modify the default Web site directory

Find: DocumentRoot "/var/www/html"
Amend to: DocumentRoot "/var/www"

turn up:<Directory “/var/www/html”>
change into:<Directory “/var/www”>

  1. Start Apache service
# systemctl start httpd
  1. View httpd status
systemctl status httpd

3. PHP 7.0.7

  1. Download the PHP source package of the corresponding version of centos
php-7.0.7.tar.gz
  1. Unzip the source package
# tar zxvf php-7.0.7.tar.gz
  1. Enter the unzip package to compile and install the dependency packages needed for PHP
# yum install -y gcc gcc-c++ make automake autoconf gd file bison patch mlocate flex diffutils zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel libcurl libcurl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers openldap-devellibxslt-devel kernel-devel libtool-libs readline-devel gettext-devel libcap-devel php-mcrypt libmcrypt libmcrypt-devel recode-devel gmp-devel icu libxslt libxslt-devel php-devel
# yum -y install libxslt-devel*
# yum -y install perl*
# yum -y install httpd-devel
# find /-name apxs //The path obtained is:/usr/bin/apxs is used when compiling parameters, which is a key parameter for configuring Apache to support PHP
  1. Compilation parameters

. /configure
–prefix=/usr/local/php
–with-config-file-path=/usr/local/php/etc
–with-zlib-dir
–with-freetype-dir
–enable-mbstring
–with-libxml-dir=/usr
–enable-xmlreader
–enable-xmlwriter
–enable-soap
–enable-calendar
–with-curl
–with-zlib
–with-gd
–with-pdo-sqlite
–with-pdo-mysql
–with-mysqli
–with-mysql-sock
–enable-mysqlnd
–disable-rpath
–enable-inline-optimization
–with-bz2
–with-zlib
–enable-sockets
–enable-sysvsem
–enable-sysvshm
–enable-pcntl
–enable-mbregex
–enable-exif
–enable-bcmath
–with-mhash
–enable-zip
–with-pcre-regex
–with-jpeg-dir=/usr
–with-png-dir=/usr
–with-openssl
–enable-ftp
–with-kerberos
–with-gettext
–with-xmlrpc
–with-xsl
–enable-fpm
–with-fpm-user=php-fpm
–with-fpm-group=php-fpm
–with-fpm-systemd
–with-apsx2
–disable-fileinfo

  1. Compile and install
# make && make install
  1. Check the PHP version after installation
# /usr/local/php/bin/php -v
  1. Edit /etc/profil to add environment variables
# vim /etc/profil

Add in

PATH=$PATH:/usr/local/php/bin
export PATH
  1. Update environment variables
# source /etc/profile
  1. View environment variables
# echo $PATH
  1. View PHP version
# php -v
  1. Configure PHP configuration file php-fpm
# cp php.ini-production /etc/php.ini
# cp /usr/local/php/etc/php-fpm.conf.default/usr/local/php/etc/php-fpm.conf
# cp /usr/local/php/etc/php-fpm.d/www.conf.default/usr/local/php/etc/php-fpm.d/www.conf
# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
# chmod +x /etc/init.d/php-fpm
# vim /usr/local/php/etc/php-fpm.conf
# Configuration error log:
#
# error_log =/usr/local/php/var/php-fpm.log
#
# Configure pid file:
#
# pid =/usr/local/php/var/run/php-fpm.pid
#
# Save and exit
# cd /usr/local/src/php-7.2.4
# cp ./sapi/fpm/php-fpm.service to/usr/lib/systemd/system/under
  1. Start php-fpm

Configure to start php-fpm at boot:

# systemctl enable php-fpm

Start php-fpm

# systemctl start php-fpm

Check status

# systemctl status php-fpm
● php-fpm.service – The PHP FastCGI Process Manager
Loaded:error(Reason: Invalid argument)
Active:inactive(dead)
Dec 1314:37:27 localhost.localdomain systemd[1]:[/usr/lib/systemd/system/php-fpm.service:7] Not an absolute path, ignoring: ${prefix}/va…fpm.pid
Dec 1314:37:27 localhost.localdomain systemd[1]:[/usr/lib/systemd/system/php-fpm.service:8] Executable path is not absolute, ignoring: $…pm.conf
Dec 1314:37:27 localhost.localdomain systemd[1]: php-fpm.service lacks both ExecStart= and ExecStop= setting. Refusing.
Dec 1314:37:27 localhost.localdomain systemd[1]: Cannot add dependency job for unit php-fpm.service, ignoring: Unit is not loaded properl…gument.
Hint: Some lines were ellipsized, use -l to show in full.
  1. Test the configuration of php-fpm
# Test php-fpm configuration
/usr/local/php/sbin/php-fpm -t
/usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini -y /usr/local/php/etc/php-fpm.conf -t
# Start php-fpm
/usr/local/php/sbin/php-fpm
/usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini -y /usr/local/php/etc/php-fpm.conf
# Close php-fpm
kill -INT `cat /usr/local/php/var/run/php-fpm.pid`
# Restart php-fpm
kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`
  1. Solution
# vim /usr/lib/systemd/system/php-fpm.service

Change the prefix and {exec_prefix} to /usr/local/php and save

//Restart the system
# reboot
  1. Restart Apache and php-fpm
# systcl restart httpd
# systcl restart php-fpm
  1. Install the corresponding xdebug

Copy the entire content of phpinfo.php and paste it to https://xdebug.org/wizard.php to determine the Xdebug version

Operate and install according to the prompt document

  1. yum install PHPMyAdmin
# yum install phpmyadmin

Modify the configuration file

# vi /etc/httpd/conf.d/phpMyAdmin.conf
< Directory /usr/share/phpMyAdmin/>
 AddDefaultCharset UTF-8<IfModule mod_authz_core.c>
 # Apache 2.4<RequireAny>
 # Require ip 127.0.0.1 #Comment out
 # Require ip ::1  #Comment out
 Require all granted  #Newly added
 < /RequireAny></IfModule><IfModule !mod_authz_core.c>
 # Apache 2.2
 Order Deny,Allow
 Deny from All
 Allow from127.0.0.1
 Allow from::1</IfModule></Directory><Directory /usr/share/phpMyAdmin/setup/><IfModule mod_authz_core.c>
 # Apache 2.4<RequireAny>
 # Require ip 127.0.0.1 #Comment out
 # Require ip ::1  #Comment out
 Require all granted  #Newly added
 < /RequireAny></IfModule><IfModule !mod_authz_core.c>
 # Apache 2.2
 Order Deny,Allow
 Deny from All
 Allow from127.0.0.1
 Allow from::1</IfModule></Directory>

Modify the phpmyadmin configuration file

# vi /etc/phpMyAdmin/config.inc.php
//Modify the following content
# $cfg['Servers'][$i]['host']='127.0.0.1';
# $cfg['Servers'][$i]['user']='root';
# $cfg['Servers'][$i]['password']='123456';

Restart Apache

# systemctl restart httpd

Test after installing MySQL

# Browser address bar input:Server ip/phpMyAdmin

4. Install MySQL 5.7

  1. Installation source
# rpm -Uvh https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
  1. yum install MySQL
# yum install mysql-community-server
  1. Start MySQL
# systemctl start mysqld
# systemctl enable mysqld //Self-start
  1. Before changing the root default password, you can turn off the password policy as needed. If the password policy is not turned off, the new password requirement is a combination of uppercase and lowercase letters + numbers + characters.
# vim /etc/my.cnf
[ mysqld]
validate_password = off
//Restart to make the modified password policy take effect
# systemctl restart mysqld
  1. Modify the MySQL root default password
//View default password
# grep 'temporary password'/var/log/mysqld.log
//The default password is:)U4FB:Kw!evF
# 2018- 12- 18 A temporary password is generated for root@localhost:)U4FB:Kw!evF

Run the security setup wizard and change the default password

mysql_secure_installation
//Enter root default password
Enter password for user root:***//Set new password
New password:***
Re-enter newpassword:***//Whether to change root password
Change the password for root ?((Press y|Y for Yes, any other key for No)://Enter directly to indicate No
//Whether to delete anonymous users
Remove anonymous users?(Press y|Y for Yes, any other key for No): y
//Prohibit root remote login
Disallow root login remotely?(Press y|Y for Yes, any other key for No): y
//Delete the test database
Remove test database and access to it?(Press y|Y for Yes, any other key for No): y
//Reload the permission table
Reload privilege tables now?(Press y|Y for Yes, any other key for No): y
//You can also use mysql to directly change the root password
mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
exit;
//For the sake of security, root is limited to local login, and a remote user with administrator rights can be created as needed
mysql -uroot -p
GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' IDENTIFIED BY 'login password' WITH GRANT OPTION;
FLUSH PRIVILEGES;
exit;

The installation is complete

I hope this article will help you to configure your CentOS server.

Recommended Posts

Centos7.4 environment installation lamp-php7.0 tutorial
lamp (centos7) installation lamp environment
Linux CentOS 7 installation tutorial
Hyper-V + CentOS7 installation video tutorial
CentOS environment installation of Docker
2019-07-09 CentOS7 installation
centos7_1708 installation
Centos7 installation of Dameng database tutorial
CentOS 8 installation of MariaDB detailed tutorial
CentOS6.8 Chinese/English environment switching tutorial illustration
[Switch] CentOS7 64-bit installation mysql tutorial
Centos5 installation guide
CentOS 7 system installation and configuration graphic tutorial
The software environment required for Centos7 installation
Centos 7 64-bit desktop version installation graphic tutorial
Centos7.5 configuration java environment installation tomcat explanation
Centos-6.5 installation and deployment of LNMP environment
Python - centos6 installation
Docker installation (CentOS7 installation)
(1) Centos7 installation to build a cluster environment
CentOS7 installation zabbix 4.0 tutorial (graphics and text)
Jenkins installation and deployment tutorial under CentOS 7
CentOS7 docker installation
The most complete centos installation tutorial in history
CentOS 6.5 system installation and configuration graphic tutorial (detailed graphic)
Centos7 installation of PHP and Nginx tutorial detailed
MySQL 8.0 installation, deployment and configuration tutorial on CentOS 8
CentOS online installation RabbitMQ3.7
CentOS6.7 build LNMP environment
Zabbix 2.2.20 installation details (Centos6.9)
Centos install MYSQL8.X tutorial
Hadoop environment construction (centos7)
Centos install elasticsearch tutorial
Centos source installation Python3
Centos7 install kubernetes tutorial
Centos7 install Mysql8 tutorial
Centos7 mqtt cluster installation
Centos6.9 install npm environment
Graphical installation of CentOS8
Mysql8.0.15 installation configuration (centos7)
Linux notes (1): CentOS-7 installation
Redis3 installation under Centos7
Centos7 configure nodejs environment
CentOS online installation RabbitMQ3.7
Docker CentOS installation method
Configure CentOS7 GPU environment
CentOS 7 build LNMP environment
Centos7 docker installation details
Centos8 (minimal installation) a new installation of Python3.8+pip method tutorial
Detailed tutorial on installing JDK8 on Linux system (CentOS7 installation)
[CentOS environment deployment] Java7/Java8 deployment under CentOS
Python introduction and environment installation
Build docker environment under Centos6.5
Centos 7 mini installation process record
Centos mysql installation and configuration
CentOS 7 install JAVA environment (JDK 1.8)
SkyWalking study notes (CentOS environment)
Redis cluster installation under CentOS
Centos7 installation and configuration prometheus
CentOS 7 Galera Cluster installation guide
Detailed explanation of Spark installation and configuration tutorial under centOS7