Notes on building the lamp environment under Centos7

0. First update the source

Source of Tsinghua University Open Source Mirror Site
https://mirrors.tuna.tsinghua.edu.cn/help/centos/

First backup CentOS-Base.repo
sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
to write source content to
/etc/yum.repos.d/CentOS-Base.repo
update package cache
sudo yum makecache
yum -y update
became
---
---

1. Install apache service

Install apache ,
yum install httpd httpd-devel
start the apache service ,
systemctl start httpd
set the boot to start
systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
, check the service status
systemctl status httpd

The firewall opens the service port to
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload
confirm the service.
netstat -tulp
Access to localhost or 127.0.0.1 or ip returns a success, indicating that the service installation is successful
---
---

2. Install mysql

install mysql
yum install mariadb mariadb-server mariadb-libs mariadb-devel

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

Enable service settings Startup check status
systemctl start mariadb
systemctl enable mariadb
systemctl status mariadb
Confirm service
netstat -tulp
database security configuration
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!

Login
mysql -uroot -p
---

2.1 Permission configuration of database users

If software such as phpmyadmin is not installed
, you need to configure the permissions of different users through sql statements in the build environment

View User
select user from mysql.user;
Create User
Create a user whose username is test and whose password is test
create user'test'@'localhost'identified by'test';
You can use password('passwd') to encrypt the password
create user 'test'@'localhost'identified by password'被加密后的值';

Deleting a user
Deleting a user requires a specific username and hostname
drop user test@localhost;
Modifying an account and
rename user'test'@'localhost'to'test1'@'localhost';
modifying a password
The new password must be passed to password() for encryption, or the encrypted password value (with quotation marks).
Change the password of user test from the original 'test' to the hash value corresponding to the plaintext 'test'
set password for 'test'@'localhost'=password('test');

User rights management
View rights
show grants for 'test'@'localhost';

Permission granted

grant select(cust_id,cust_name)
    on mysql_test.customers
    to'test'@'localhost';

Grants select privileges on the columns cust_id and cust_name on the table customers in the database mysql_test

grant select ,update
    on mysql_test.customers
    to 'test22'@'localhost'identified by'123'; 

Create a new user as test22 and grant it select and update permissions on the table customers in the database mysql_test

grant all
    on mysql_test.*
    to'test'@'localhost';

Grant permission to perform all operations in database mysql_test

grant create user
    on *.*
    to'test'@'localhost';
    

Grant the user test that already exists in the system the permission to create a user

Transfer and Restriction of Privileges
Grant a non-existent user admin in the current system to have select and update privileges on the table customers in the database mysql_test, and allow it to grant this privilege to other users (via with grant option):

grant select,update
    on mysql_test.customers
    to'admin'@'localhost'identified by'admin'
    with grant option;

If the above with clause is followed by one of max_queries_per_hour count,
max_updates_per_hour count,
max_connections_per_hour count,
max_user_connections count
, the grant statement can be used to limit permissions

grant delete
    on mysql_test.customers
    to 'admin6'@'localhost'
    with max_queries_per_hour 1;--每小时只能处理一条delete语句的权限 

Revocation of permissions
Use revoke to revoke permissions without deleting the user

revoke select 
    on mysql_test.customers
    from'test'@'localhost';--回收用户test在数据库mysql_test的表customers上的select权限

---

install php

install php
yum -y install php

执行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

Associate mysql and php
yum install php-mysql
view

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

install php extension
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

restart apache server
systemctl restart http

Just write a phpinfo and go check it out to know if it's successful or not, that's
basically ok

---

Reference articles when preparing the environment before

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325630492&siteId=291194637