CentOS7 yum lamp 虚拟主机配置 lamp各组件简单影响性能的参数调整--for 一定的环境需求
LAMP Server on CentOS 7
Updated Tuesday, January 13, 2015 by Joel Kruger
This guide provides step-by-step instructions for installing a full-featured LAMP stack on a CentOS 7 system.
In this guide, you will be instructed on setting up Apache, MariaDB, and PHP.
The CentOS 7 Project has elected to replace the
initservice management daemon with the newer,systemddaemon for this latest release. In addition, this release of CentOS ships with MariaDB repositories instead of MySQL. If you would prefer to use the more traditional MySQL instead, there are instructions provided below to use those repositories as well.
Throughout this guide we will offer several suggested values for specific configuration settings. Some of these values will be set by default. These settings are shown in the guide as a reference, in the event that you change these settings to suit your needs and then need to change them back.
Prerequisites
Your Linode should already be set up according to the instructions in our Getting Started guide, and it is suggested that security precautions be implemented. For assistance with this, please see our documentation: Securing Your Server
This guide is written for a non-root user. Commands that require elevated privileges are prefixed with
sudo. If you’re not familiar with thesudocommand, you can check our Users and Groups guide.
Set the Hostname
Before you begin installing and configuring the components described in this guide, please make sure you’ve followed our instructions for setting your hostname. Issue the following commands to make sure it is set properly:
1 |
hostname |
The first command should show your short hostname, and the second should show your fully qualified domain name (FQDN).
Install and Configure the Apache Web Server
The Apache Web Server is a very popular choice for serving web pages. While many alternatives have appeared in the last few years, Apache remains a powerful option that we recommend for most uses.
Update existing packages:
1
sudo yum update
Install the current version of the Apache web server (in the 2.x series):
1
sudo yum install httpd
The configuration for Apache is contained in the
httpd.conffile, which is located at:/etc/httpd/conf/httpd.conf. We advise you to make a backup of this file into your home directory:1
cp /etc/httpd/conf/httpd.conf ~/httpd.conf.backup
By default, all files ending in the
.confextension in/etc/httpdand/etc/httpd/conf.d/are treated as Apache configuration files, and we recommend placing your non-standard configuration options in files in these directories. Regardless how you choose to organize your configuration files, making regular backups of known working states is highly recommended.Edit the main Apache configuration file to adjust the resource use settings. The settings shown below are a good starting point for a Linode 1GB.
- /etc/httpd/conf/httpd.conf
-
1
2
3
4
5
6
7
8
9
10
11KeepAlive Off ... <IfModule prefork.c>
StartServers 2
MinSpareServers 6
MaxSpareServers 12
MaxClients 80
MaxRequestsPerChild 3000
</IfModule>
Configure Name-based Virtual Hosts
There are different ways to set up virtual hosts; however, we recommend the method below. This configuration instructs Apache to listen on all IP addresses available to it.
Create virtual host entries for each site that we need to host with this server. For this example we are using “example.com” and “example.org”.
- /etc/httpd/conf.d/vhost.conf
-
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19NameVirtualHost *:80 <VirtualHost *:80>
ServerAdmin webmaster@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /srv/www/example.com/public_html/
ErrorLog /srv/www/example.com/logs/error.log
CustomLog /srv/www/example.com/logs/access.log combined
</VirtualHost> <VirtualHost *:80>
ServerAdmin webmaster@example.org
ServerName example.org
ServerAlias www.example.org
DocumentRoot /srv/www/example.org/public_html/
ErrorLog /srv/www/example.org/logs/error.log
CustomLog /srv/www/example.org/logs/access.log combined
</VirtualHost>
Notes regarding this example configuration:
- All of the files for the sites that you host will be located in directories that exist underneath
/srv/www. You can symbolically link these directories into other locations if you need them to exist elsewhere. ErrorLogandCustomLogentries are suggested for more fine-grained logging, but are not required. If they are defined (as shown above), thelogsdirectories must be created before you restart Apache.
Before you can use the above configuration you’ll need to create the specified directories. For the above configuration, you can do this by issuing the following commands:
1
2
3
4
5sudo mkdir -p /srv/www/example.com/public_html
sudo mkdir /srv/www/example.com/logs sudo mkdir -p /srv/www/example.org/public_html
sudo mkdir /srv/www/example.org/logsAfter you’ve set up your virtual hosts, you can issue the following commands to enable Apache to start on boot and run for the first time:
1
2sudo /bin/systemctl enable httpd.service
sudo /bin/systemctl start httpd.service
Assuming that you have configured the DNS for your domain to point to your Linode’s IP address, virtual hosting for your domain should now work. Remember that you can create as many virtual hosts as you require.
Any time you change an option in your vhost.conf file, or any other Apache configuration file, remember to reload the configuration with the following command:
1 |
sudo /bin/systemctl reload httpd.service |
Install and Configure MariaDB Database Server
MariaDB is a relational database management system (RDBMS) and ships by default in CentOS 7. MariaDB is a popular component in contemporary web development tool-chains, and is used to store data for many popular applications, including Wordpress and Drupal.
If you prefer to use the MySQL branded database in CentOS 7, you will need to add the required repositories by issuing the following command:
1 sudo yum install http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
Install MariaDB
Install the MariaDB-server package:
1
sudo yum install mariadb-server
CentOS 7 provides version 10.1.1 of MariaDB. Before you can use MariaDB some configuration is required. If you want to run MariaDB by default when the system boots, execute the following command:
1
sudo /bin/systemctl enable mariadb.service
Now you can start the MariaDB daemon (
mariadb) with the following command:1
sudo /bin/systemctl start mariadb.service
At this point, MariaDB should be ready to configure and run. While you shouldn’t need to change the configuration file, note that it is located at
/etc/my.cnffor future reference. The default values should be fine for a Linode 1GB, but if you decide to adjust them you should first make a backup copy:1
cp /etc/my.cnf ~/my.cnf.backup
Configure MariaDB and Set Up MariaDB databases
After installing MariaDB, it’s recommended that you run
mysql_secure_installation, a program that helps secure MariaDB. While runningmysql_secure_installation, you will be presented with the opportunity to change the MariaDB root password, remove anonymous user accounts, disable root logins outside of localhost, and remove test databases and reload privileges. It is recommended that you answer yes to these options. Run the following command to execute the program:1
mysql_secure_installation
Next, we’ll create a database and grant your users permissions to use databases. First, log in to MariaDB:
1
mysql -u root -p
Enter MariaDB’s root password, and you’ll be presented with a prompt where you can issue SQL statements to interact with the database.
In the example below,
example_database_nameis the name of the database,example_useris used as the username, andexample_passwordis used as the password for the root account on this newly established database. You should replace all three of these parameters to reflect your unique circumstances. It is recommended to create both a root and one additional user account within your database.To create a new database and grant your users permissions on it, issue the following commands. Note that the semi-colons (
;) at the end of the lines are crucial for ending the commands:1
2create database example_database_name;
grant all on example_database_name.* to 'example_user'@'localhost' identified by 'example_password';Database user names and passwords are only used by scripts connecting to the database, and that database user account names need not (and perhaps should not) represent actual user accounts on the system. If you need to create additional users in the database you just created, simply run the command below, substituting the new user name and password where appropriate:
1
grant all on example_database_name.* to 'example_user2'@'localhost' identified by 'example_password2';
With that completed, you’ve successfully configured MariaDB. To exit the MariaDB database administration utility issue the following command:
1
quit
With Apache and MariaDB installed you are now ready to move on to installing PHP to provide scripting support for your web pages.
Installing and Configuring PHP
PHP makes it possible to produce dynamic and interactive pages using your own scripts and web development frameworks. Furthermore, many popular web applications like WordPress are written in PHP. If you want to be able to develop your websites using PHP, you must first install it.
CentOS includes packages for installing PHP from the terminal. Issue the following command:
1
sudo yum install php php-pear
Once PHP5 is installed we’ll need to tune the configuration file located in
/etc/php.inito enable more descriptive errors, logging, and better performance. These modifications provide a good starting point if you’re unfamiliar with PHP configuration. Make sure that the following values are set, and relevant lines are uncommented (comments are lines beginning with a semi-colon [;]):- /etc/php.ini
-
1
2
3
4
5
6
7error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR
display_errors = Off
log_errors = On
error_log = /var/log/php/error.log
max_execution_time = 30
memory_limit = 128M
max_input_time = 30
Create the log directory for PHP and give the Apache user ownership:
1
2sudo mkdir /var/log/php
sudo chown apache /var/log/phpIf you need support for MariaDB or MySQL in PHP, then install the php5-mysql package with the following command:
1
sudo yum install php-mysql
After making changes to PHP, restart Apache by issuing the following command:
1
sudo /bin/systemctl reload httpd
You should now have a fully functioning LAMP stack on your Linode! From here, you can serve up tons of content to your followers on the internet. If you are interested in setting up a WordPress site on your new LAMP stack, please consider reviewing this tutorial: Manage Web Content with WordPress.
More Information
You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.
CentOS7 yum lamp 虚拟主机配置 lamp各组件简单影响性能的参数调整--for 一定的环境需求的更多相关文章
- LAMP虚拟主机配置以及控制目录访问
3.基于域名的虚拟主机配置 NameVirtualHost192.168.3.32:80#apache2.2.xx版本需要开启此选项,而且要和下面的保持一致:2.4.x版本就不需要此项设置了 < ...
- lamp centos虚拟主机配置
1.基于不同端口的虚拟主机配置 [root@lamp~]# vi /etc/httpd/conf/httpd.conf Listen 80 #设置监听不同的虚拟主机需要使用的端口 Liste ...
- Nginx--服务部署、基于域名的虚拟主机配置
一.服务部署 1.预处理 安装CentOS ,配置hosts.静态IP.设置必要的安全参数等(略) 1-1.系统环境 [root@vnx ~]# cat /etc/redhat-release Cen ...
- linux下lamp.sh一键配置lamp环境流程
linux下lamp.sh一键配置lamp环境流程 一.总结 一句话总结: 2.将网站从github上clone到/data/www/网站域名/ 3.更改网站目录权限:chown -R apache: ...
- Ngnix 安装、信号量、虚拟主机配置
ngnix的安装很简单 1.先从ngnix官网下载ngnix压缩包 wget http://nginx.org/download/nginx-1.6.2.tar.gz 2.解压并进入其目录 tar - ...
- linux apache虚拟主机配置(基于ip,端口,域名)
配置环境: linux版本:Centos6.4 httpd版本: [root@centos64Study init.d]# pwd/etc/init.d[root@centos64Study init ...
- Linux Apache虚拟主机配置方法
apache 虚拟主机配置 注意: 虚拟主机可以开很多个 虚拟主机配置之后,原来的默认/etc/httpd/httpd.conf中的默认网站就不会生效了 练习: 主机server0 ip:172.25 ...
- 第四百零二节,Django+Xadmin打造上线标准的在线教育平台—生产环境部署,uwsgi安装和启动,nginx的安装与启动,uwsgi与nginx的配置文件+虚拟主机配置
第四百零二节,Django+Xadmin打造上线标准的在线教育平台—生产环境部署,uwsgi安装和启动,nginx的安装与启动,uwsgi与nginx的配置文件+虚拟主机配置 软件版本 uwsgi- ...
- CentOS 7运维管理笔记(7)----Apache 基于端口的虚拟主机配置
如果一台服务器只有一个IP或需要通过不同的端口访问不同的虚拟主机,可以使用基于端口的虚拟主机配置. (1) 在虚拟机的CentOS7服务器上配置 eth0:4 为192.168.1.214: (2) ...
随机推荐
- python处理.seq文件
# Deal with .seq format for video sequence # Author: Kaij # The .seq file is combined with images, # ...
- UESTC_秋实大哥の恋爱物语 2015 UESTC Training for Search Algorithm & String<Problem K>
K - 秋实大哥の恋爱物语 Time Limit: 5000/2000MS (Java/Others) Memory Limit: 32000/32000KB (Java/Others) Su ...
- Cdev
1,#和##操作符Operator,使用 首个参数返回为一个带引号的字符串 predefined variable was not declared in the scope;
- Elasticsearch 安装与集群配置
一.软件版本 操作系统:CentOS-6.5-x86_64 ES版本:5.0 主机:192.168.63.246 主机: 192.168.63.242 二.部署环境规划: 1. 需求:jdk版本: ...
- Kyoya and Colored Balls(组合数)
Kyoya and Colored Balls time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- Collections你用对了吗?
.Net有两类基础的集合类型:List和Dictionary.List是基于Index的,Dictionary是基于key的.集合类型一般实现了IEnumberable,ICollection或者Il ...
- 【枚举+数学】【HDU1271】整数对 难度:五颗星
整数对 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submis ...
- NPOI兼容 excel2003,2007版本
根据项目需要,需要对excel进行导入导出,所以选择NPOI,优点在这里就不详细介绍了,下面进入正题. public int Import(string path) { IList<Studen ...
- 通过递归方法对一个单词所有的组合进行列举(java)
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public ...
- HDU 1194 - Beat the Spread!
给两数之和和两数之差,求两数,两数还必须同奇偶 #include <iostream> using namespace std; int main() { int a,b,t; cin&g ...