centos-lamp

安装apache

https://www.linode.com/docs/websites/lamp/lamp-on-centos-7

之前通过下载tar.bz包安装并启动了apache,所以在启动yum安装的httpd时报错。

sudo yum install httpd

安装php

PHP Install and Configure
sudo yum install php php-pear

Edit /etc/php.ini for better error messages and logs, and upgraded performance. These modifications provide a good starting point for a Linode 1GB:

/etc/php.ini
error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR
error_log = /var/log/php/error.log
max_input_time = 30

Create the log directory for PHP and give the Apache user ownership:
sudo mkdir /var/log/php
sudo chown apache /var/log/php

Reload Apache:
sudo systemctl reload httpd

新建php文件输出php信息测试php是否安装成功

<html><body>
<h1>It works!</h1>
<?php phpinfo(); ?>
</body></html>

安装数据库

https://www.linode.com/docs/databases/mariadb/how-to-install-mariadb-on-centos-7

centos 7默认的数据库服务器是mariadb。

Enable MariaDB to start on boot and then start the service:
sudo systemctl enable mariadb
sudo systemctl start mariadb

Harden MariaDB Server
sudo mysql_secure_installation
You will be given the choice to change the MariaDB root password, remove anonymous user accounts, disable root logins outside of localhost, and remove test databases. It is recommended that you answer yes to these options.

To log in to MariaDB as the root user:
mysql -u root -p

Create a New MariaDB User and Database
In the example below, testdb is the name of the database, testuser is the user, and password is the user’s password:
create database testdb;
create user 'testuser'@localhost identified by 'password';
grant all on testdb.* to 'testuser' identified by 'password';

Create a Sample Table
mysql -u testuser -p

Create a sample table called customers. This creates a table with a customer ID field of the type INT for integer (auto-incremented for new records, used as the primary key), as well as two fields for storing the customer’s name:
use testdb;
create table customers (customer_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, first_name TEXT, last_name TEXT);

View the new table:
show tables;

Reset the MariaDB Root Password
Stop the current MariaDB server instance, then restart it with an option to not ask for a password:
sudo systemctl stop mariadb
sudo mysqld_safe --skip-grant-tables &

Reconnect to the MariaDB server with the MariaDB root account:
mysql -u root

Use the following commands to reset root’s password. Replace password with a strong password:
use mysql;
update user SET PASSWORD=PASSWORD("password") WHERE USER='root';
flush privileges;
exit

Then restart MariaDB:
sudo systemctl start mariadb

Tune MariaDB
The script needs the bc language installed:
sudo yum install bc

Download MySQL Tuner to your home directory and make it executable:
wget http://www.day32.com/MySQL/tuning-primer.sh
chmod u+x tuning-primer.sh

To run it:
sudo ./tuning-primer.sh
You will be asked if you would like to run the script against a different MySQL socket than /var/lib/mysql/mysql.sock. Select N. You will then be asked if you have your login. Enter y, then the credentials when asked.

原文地址:https://www.cnblogs.com/qike/p/5262463.html