Build PHP development environment--lamp on CentOS7.0 x86_64 system (including setting up virtual directories, adding SELinux support for httpd)

Source: Internet
Author: User
Tags php development environment

Install MySQL, install it directly with Yum, and MySQL is replaced by MARIADB in the centos7.0 version.

Command:

Yum install mysql-server MySQL

Install, select Modify MySQL default root user password, start the MySQL service.

Command:

Service mysqld Start

Two. Install Apache, direct yum installation, and MySQL installation method similar, no longer repeat.

After installation, open Apache service.

Command:

Systemctl Start Httpd.service

Test whether the following Apache is installed successfully, open the browser, enter http://localhost, whether to display the Apache homepage.

Three. Install PHP, install with Yum in a similar way.

After installation, restart the Apache service, create a new PHP file under the/var/www/html directory, and enter the following:

<?php

Phpinfo ();

?>

Enter url--http://localhost/xxx.php (xxx.php for your new PHP file) in the browser to see if some version information about PHP will be displayed.

Four. Add PHP support for MySQL, yum installation.

Command:

yum installphp-mysql

Note: To turn on other PHP features, you can add additional modules yourself.

Five. Apache Add virtual directory

Because the Apache default project directory under/var/www, and all the files in this directory are the root user, so that every time we write PHP files to get root permission to do

editing, it is very troublesome, so can we customize a directory, let Apache also recognize this directory?

Of course, it is possible, that is the next virtual directory to be discussed in this article, the various benefits of establishing a virtual directory I do not introduce a lot here, directly on the method.

Apache service configuration file in/etc/httpd/conf/httpd.conf, make the following backup before editing the file.

CP httpd.conf Httpd.conf.backup

Edit the httpd.conf file and rename your custom directory with Alisa for easy access to the files in that directory.

Example:

Alias/bbs "/home/xxx/workspace/www"
<directory "/home/xxx/workspace/www" >
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>

I choose my custom path here is/home/xxx/workspace/www, in this directory to create a new index.html file, the directory corresponding to the alias is/bbs, Access is

Direct input: Http://localhost/bbs can access the files under the real directory/home/xxx/workspace/www.

Here, don't think Bob, the Redhat system introduces SELinux security control, which manages many of the network services in Linux, including strict access control for Apache.

In this step, entering url--Http://localhost/bbs in the browsershould be the 403 error code. At this time, don't worry, look at the/etc/httpd/logs directory

Error_log file content, which records the history of Apache activity.

If it is a AH00035 error code, then you have the following work to do:

1. Check the permissions of the custom directory/home/xxx/workspace/www, and modify the directory permissions and file permissions, respectively, against the/var/www/html changes.

2. If this error still occurs, then 80% is the ghost of SELinux, first, with Semanage fcontext-l | grep '/var/www ' learns the SELinux context of the default/var/www directory , and will get a bunch of information similar to the one listed below:

/var/www (/.*)? All Files System_u:object_r:httpd_sys_content_t:so

You can see that Apache can only access files that contain httpdsyscontent_t tags. If we want to access a custom Web site directory, then we need to add this tag to the file in this directory, which is divided into two steps:

First, add the default label type for the file in the custom directory, Semanage fcontext-a-T httpd_sys_content_t '/home/xxx/workspace/www (/.*), and then label the existing file with the new label type: Restorecon-r-v/home/xxx/workspace/www, then Apache will be able to use this directory.

2. In this step, the AH00132 error code appears, then set SELinux to the file in the directory is readable, can be accessed.

Setsebool-p httpd_read_user_content 1

By entering Http://localhost/bbs, you can access the contents of the index.html file.

Build PHP development environment--lamp on CentOS7.0 x86_64 system (including setting up virtual directories, adding SELinux support for httpd)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.