Build a php Development Environment on CentOS7.0-Lamp
1. Install mysql directly using yum. mysql is replaced by mariadb in centos7.0.
Command:
Yum install mysql-server mysql
After installation, select to modify the default password of the root user of mysql to start the mysql service.
Command:
Service mysqld start
2. install apache directly using yum. The installation method is similar to that of mysql.
After the installation is complete, enable the apache service.
Command:
Systemctl start httpd. service
Test whether apache is successfully installed. Open the browser and enter http: // localhost to check whether the apache homepage is displayed.
3. install php using yum in a similar way.
After the installation is complete, restart the apache service and create a new PHP file in the/var/www/html directory. The input content is as follows:
<? Php
Phpinfo ();
?>
Enter the URL -- http: // localhost/xxx. php (xxx. php is the php file created for you) in the browser to check whether php version information is displayed.
4. Add php support for mysql and install yum.
Command:
yuminstallphp-mysql
Note: To enable other php functions, you can add related modules by yourself.
5. Add a virtual directory to apache
Because the default project directory of apache is under/var/www, and all file owners under this directory are root users, we need to get the root permission every time we write PHP files.
Editing is very troublesome, so can we customize a directory so that apache can also identify it?
Of course, that is, the virtual directory to be discussed next in this article. I will not introduce the advantages of creating a virtual directory here.
The apache service configuration file is 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 use Alisa to rename your custom directory so that we can access the files in this directory.
Example:
Alias/bbs "/home/xxx/WorkSpace/www"
<Directory "/home/xxx/WorkSpace/www">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
Here, I select my custom path:/home/xxx/WorkSpace/www. A new index.html file is created under the directory. the alias of the directory is/bbs. Access is
Enter http: // localhost/bbs to access the files in the/home/xxx/WorkSpace/www directory.
By now, do not forget that the RedHat system has introduced SELinux security control to manage many network services in Linux, including strict access control over apache.
In this step, enter the URL -- http: // localhost/bbs in the browser to get the 403 error code. At this time, don't worry. Take a look at
The content of the error_log file, which records the apache activity history.
If the error code is AH00035, do the following:
1. Check the permissions of the User-Defined directory/home/xxx/WorkSpace/www, and modify the directory permissions and file permissions respectively against/var/www/html changes.
2. if this error still occurs, it turns out that SELinux is a ghost. First, use semanage fcontext-l | grep '/var/www' To Get The SELinux context of the default/var/www directory. A bunch of information similar to the following will be obtained:
/Var/www (/.*)? All files system_u: object_r: httpd_sys_content_t: so
It can be seen that apache can only access files containing the httpdsyscontent_t tag. If we want to access a custom website directory, we need to add this label to the files under this Directory, which is implemented in two steps:
First, add the default tag type for the files in the Custom directory, semanage fcontext-a-t httpd_sys_content_t '/home/xxx/WorkSpace/www (/.*)? ', And then use the new tag type to mark the existing file: restorecon-R-v/home/xxx/WorkSpace/www. Then apache can use this directory.
2. If the AH00132 error code is displayed in this step, set SELinux to read the files in the directory.
Setsebool-P httpd_read_user_content 1
At this point, you can enter http: // localhost/BBS to access the content of the index.html file.