Tutorial on installing lamp-php7.0 in Centos7.4 environment

Tutorial on installing lamp-php7.0 in Centos7.4 environment

This article describes how to install lamp-php7.0 in Centos7.4 environment. Share with you for your reference, the details are as follows:

1. Environmental Preparation

Bridge Mode

Able to access external network

#ping www.baidu.com

If ping succeeds, you can reach the external network.

Turn off firewall

#systemctl disable firewalld //Disable the firewall #systemctl stop firewalld //Shut down the firewall

Turn off seLinux

#vim /etc/selinux/config

to:

SELINUX=disabled

Configure yum source

# cd /etc/yum.repos.d/
# mkdir repo_bak //Create a backup source folder# mv *.repo repo_bak/ //Put all 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 the files in the /etc/yum.repos.d/directory Centos-7.repo CentOS-Base-163.repo repo.bak
# yum clean all //Clear all yum caches in the system# yum makecache //Generate yum cache# yum list | grep epel-release //View the epel source list# yum install -y epel-release //Install the epel source# ls //The epel source is installed successfully. There are two more epel.repo and epel-testing.repo files than before. 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 the epel source from Alibaba source# ls
CentOS7-Base-163.repo Centos-7.repo epel-7.repo epel.repo epel-testing.repo repo_bak
# yum clean all //Clear the system yum cache again# yum makecache //Regenerate a new yum cache# yum repolist enabled //View the yum sources available on the system# yum repolist all //View all yum sources

Delete old versions

# yum -y remove php

2. Apache

1. Install Apache

# yum install httpd

2. Configure Apache

# vim /etc/httpd/conf/httpd.conf
//Search#AddType application/x-gzip .gz .tgz
//Then add # AddType application/x-httpd-php .php
//Search #IfModule dir_module
//Add index.php under DirectoryIndex
//Modify #ServerName www.example.com:80
# ServerName localhost:80

Modify the default website directory

Found: DocumentRoot "/var/www/html"
Modify to: DocumentRoot "/var/www"

Found: <Directory "/var/www/html">
Modify to: <Directory "/var/www">

3. Start Apache service

# systemctl start httpd

4. Check httpd status

systemctl status httpd

3. PHP 7.0.7

1. Download the corresponding version of centos PHP source package

php-7.0.7.tar.gz

2. Unzip the source package

# tar zxvf php-7.0.7.tar.gz

3. Enter the unzipped package to compile and install the dependency packages required by 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. It is used when compiling parameters and is the key parameter for configuring Apache to support PHP.

4. 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

6. Compile and install

# make && make install

7. Check the PHP version after installation

# /usr/local/php/bin/php -v

8. Edit /etc/profil and add environment variables

# vim /etc/profil

Add it

PATH=$PATH:/usr/local/php/bin
export PATH

9. Update environment variables

# source /etc/profile

10. Check environment variables

# echo $PATH

11. Check PHP version

# php -v

12. 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
# Configure 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/

13. Start php-fpm

Configure php-fpm to start at boot:

# systemctl enable php-fpm

Start php-fpm

# systemctl start php-fpm

View Status

# systemctl status php-fpm
● php-fpm.service – The PHP FastCGI Process Manager
Loaded: error (Reason: Invalid argument)
Active: inactive (dead)
Dec 13 14:37:27 localhost.localdomain systemd[1]: [/usr/lib/systemd/system/php-fpm.service:7] Not an absolute path, ignoring: ${prefix}/va…fpm.pid
Dec 13 14:37:27 localhost.localdomain systemd[1]: [/usr/lib/systemd/system/php-fpm.service:8] Executable path is not absolute, ignoring: $…pm.conf
Dec 13 14:37:27 localhost.localdomain systemd[1]: php-fpm.service lacks both ExecStart= and ExecStop= setting. Refusing.
Dec 13 14:37:27 localhost.localdomain systemd[1]: Cannot add dependency job for unit php-fpm.service, ignoring: Unit is not loaded properly.
Hint: Some lines were ellipsized, use -l to show in full.

14. 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
#Shut down 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`

15. Solution

# vim /usr/lib/systemd/system/php-fpm.service

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

//Reboot the system# reboot

16. Restart Apache and php-fpm

# systcl restart httpd
# systcl restart php-fpm

17. Install the corresponding xdebug

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

Follow the prompts to install the document

18. Install PHPMyAdmin with yum

# 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 from 127.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 from 127.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

# Enter in the browser address bar: 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

2. Install MySQL using yum

# yum install mysql-community-server

3. Start MySQL

# systemctl start mysqld
# systemctl enable mysqld //Start automatically at boot

4. Before changing the default root password, you can disable the password policy as needed. If the password policy is not turned off, the new password must be 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

5. Change the default root password of MySQL

//View the 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 the default root passwordEnter password for user root: ***
//Set a new passwordNew password:***
Re-enter new password: ***
//Do you want to change the password for root? ((Press y|Y for Yes, any other key for No) ://Press Enter directly to indicate No
//Do you want to delete anonymous users? (Press y|Y for Yes, any other key for No) : y
//Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
//Delete the test databaseRemove test database and access to it? (Press y|Y for Yes, any other key for No) : y
//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 security reasons, root can only log in locally. If needed, you can create a remote user with administrator privileges. mysql -uroot -p
GRANT ALL PRIVILEGES ON *.* TO 'user name'@'%' IDENTIFIED BY 'login password' WITH GRANT OPTION;
FLUSH PRIVILEGES;
exit;

Installation Complete

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

You may also be interested in:
  • Specific operation method of building LAMP environment in centos7.2
  • CentOS 7.0 Lnmp and Lamp detailed introduction
  • Install lamp environment with yum on Centos7.2 system
  • CentOS7 + PHP7 Lamp full set of latest version configuration and mongodb and redis tutorial detailed explanation
  • Detailed tutorial on installing the latest version of PHP7 on Centos7
  • How to install PHP7.2 with CentOS7yum
  • Centos7.2 compile and install PHP7.0.2 steps
  • Tutorial on installing lnmp using yum on centos7 (linux+nginx+php7.1+mysql5.7)
  • Alibaba Cloud CentOS7 builds Apache+PHP+MySQL environment
  • Detailed instructions for building LAMP and updating PHP version on CentOS7 system

<<:  Brief analysis of MySQL union and union all

>>:  CocosCreator learning modular script

Recommend

MySQL 8.0.19 installation detailed tutorial (windows 64 bit)

Table of contents Initialize MySQL Install MySQL ...

This article will help you understand the life cycle in Vue

Table of contents 1. beforeCreate & created 2...

Introduction to CSS BEM Naming Standard (Recommended)

1 What is BEM Naming Standard Bem is the abbrevia...

Sharing ideas on processing tens of millions of data in a single MySQL table

Table of contents Project Background Improvement ...

How to implement real-time polygon refraction with threejs

Table of contents Preface Step 1: Setup and front...

mysql 8.0.12 winx64 download and installation tutorial

MySQL 8.0.12 download and installation tutorial f...

Introduction to Nginx regular expression related parameters and rules

Preface Recently, I have been helping clients con...

Solution to Mysql binlog log file being too large

Table of contents 1. Related binlog configuration...

JS 4 super practical tips to improve development efficiency

Table of contents 1. Short circuit judgment 2. Op...

MySQL 5.6.28 installation and configuration tutorial under Linux (Ubuntu)

mysql5.6.28 installation and configuration method...

Summary of 7 reasons why Docker is not suitable for deploying databases

Docker has been very popular in the past two year...

Native JS implementation of loading progress bar

This article shares a dynamic loading progress ba...

How to recover data after accidentally deleting ibdata files in mysql5.7.33

Table of contents 1. Scenario description: 2. Cas...

How to use domestic image warehouse for Docker

1. Problem description Due to some reasons, the d...