Quickly set up a working environment, test environment, and start your PHP programming journey.
liunx
Preparation:
1. Configure the firewall and open port 80 and 3306
vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT #Allow port 80 Through the firewall
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT #Allow port 3306 through the firewall
As shown below:
############################ After adding, the firewall rules will look as follows###### #######################
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp - j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp- host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
########################## ################################################ ####################
/etc/init.d/iptables restart #Finally restart the firewall to make the configuration take effect
2. Turn off SELINUX
vi /etc/selinux/config
#SELINUX=enforcing #Comment out
#SELINUXTYPE=targeted #Comment out
SELINUX=disabled #Add
:wq #Save, close
shutdown - r now #Restart the system
Installation:
1. Install Apache
yum install httpd #According to the prompts, enter Y to install to successfully install
/etc/init.d/httpd start #Start Apache
Note: Apache will prompt an error after starting:
Starting httpd: httpd: Could not reliably determine the server's fully qualif domain name, using ::1 for ServerName
Solution:
vi /etc/httpd/conf/httpd .conf #Edit
Find #ServerName www.example.com:80
Change to ServerName www.osyunwei.com:80 #Set it to your own domain name here. If there is no domain name, you can set it to localhost
:wq! #Save and exit
chkconfig httpd on #Set to start at boot
/etc/init.d/httpd restart #Restart Apache
2. Install MySQL
1. Install MySQL
yum install mysql mysql-server #Ask if you want to install it, enter Y to install automatically until the installation is completed
/etc/init.d/mysqld start #Start MySQL
chkconfig mysqld on #Set To start up
cp /usr/share/mysql/my-medium.cnf /etc/my.cnf #Copy the configuration file (Note: If there is a my.cnf under the /etc directory by default, just overwrite it directly)
2. Set the password for the root account
mysql_secure_installation
Press Enter, enter Y according to the prompts
Enter the password twice, press Enter
Enter Y all the way according to the prompts
Finally, the following message appears: Thanks for using MySQL!
MySql password setting is completed, restart MySQL:
/etc/init.d/mysqld restart #restart
/etc/init.d/mysqld stop #stop
/etc/init.d/mysqld start #start
3. Install PHP5
1. Install PHP5
yum install php
Enter Y according to the prompts until the installation is completed
2. Install PHP components so that PHP5 supports MySQL
yum
install php-mysql php-gd libjpeg* php-imap php-ldap php-odbc php-pear
php-xml php-xmlrpc php-mbstring php-mcrypt php-bcmath php-mhash
libmcrypt
Select the above installation package here to install
Enter Y and press Enter according to the prompts
/etc/init.d/mysqld restart #Restart MySql
/etc/init.d/httpd restart #Restart Apche
Configuration
1. Apache configuration
vi /etc/httpd/conf/httpd.conf #Edit file
ServerTokens OS Change line 44 to: ServerTokens Prod (the name of the server operating system will not be displayed when an error page appears)
ServerSignature On Change on line 536 to: ServerSignature Off (do not display the version of Apache in the error page)
Options Indexes FollowSymLinks Change on line 331 to: Options Includes ExecCGI FollowSymLinks (allow the server to execute CGI and SSI, prohibit listing directories)
#AddHandler cgi-script .cgi Changed on line 796 to: AddHandler cgi-script .cgi .pl (allow CGI scripts with extension .pl to run)
AllowOverride None Modified on line 338 to: AllowOverride All (allow. htaccess)
AddDefaultCharset UTF-8 Change on line 759 to: AddDefaultCharset GB2312 (Add GB2312 as the default encoding)
Options Indexes MultiViews FollowSymLinks Change on line 554 to Options MultiViews FollowSymLinks (do not display the tree directory structure on the browser)
DirectoryIndex index.html index.html.var is modified on line 402 to: DirectoryIndex index.html index.htm Default.html Default.htm
index.php Default.php index.html.var (Set the default homepage file, add index.php)
KeepAlive Off Modify on line 76 to: KeepAlive On (allow programmatic online connection)
MaxKeepAliveRequests 100 Modify on line 83 is: MaxKeepAliveRequests 1000 (increase the number of simultaneous connections)
:wq! #Save and exit
/etc/init.d/httpd restart #Restart
rm -f /etc/httpd/conf.d/welcome.conf /var/ www/error/noindex.html #Delete default test page
2. PHP configuration
vi /etc/php.ini #Edit
date.timezone = PRC #On line 946, remove the semicolon in front and change it to date.timezone = PRC
disable_functions
=
passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr, checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd,
posix_getegid,posix_geteuid,posix_getgid,
posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,
posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit,
posix_getsid,posix_getuid,posix_isatty,
posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,
posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname
#On line 386, list the functions that can be disabled in PHP. If some programs need to use this function, it can be deleted and undisabled.
expose_php = Off #Suppress display of php version information on line 432
magic_quotes_gpc = On #Turn on magic_quotes_gpc on line 745 to prevent SQL injection
short_open_tag = ON #Support php short tags on line 229
open_basedir = .:/tmp / # Setting on line 380 means allowing access to the current directory (that is, the directory where the PHP script file is located) and the /tmp/ directory, which can prevent PHP Trojans from crossing the site. If there is a problem with the installation program after changing it (for example: DreamWeaver Content Management system), you can log out of this line, or write directly to the program directory /data/www.osyunwei.com/:/tmp/
:wq! #Save and exit
/etc/init.d/mysqld restart #Restart MySql
/etc/init.d/httpd restart #RestartApche
Test article
cd /var/www/html
vi index.php #Enter the following content
phpinfo();
?>
:wq! #Save and exit
on the client Enter the server IP address in the browser, and you can see the relevant configuration information as shown below!