1. Trang chủ
  2. » Công Nghệ Thông Tin

Phát triển web với PHP và MySQL - p 82 doc

10 121 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 10
Dung lượng 632,67 KB

Nội dung

Let’s begin! Become root by using su. $ su and enter the user root’s password. Change to the directory that you have stored the source files in, for example # cd /tmp/download/ Extract the files using the following command: # gunzip -c mysql-3.22.xx.tar.gz | tar xvf - Change to the new directory. This was created by tar during the extraction, like this: # cd mysql-3.22.xx Now you can start configuring the MySQL server. You can specify many options with the configure command. Type configure help to see all options. The configure script will check for your compiler and a number of other things. If you have any errors, you can check the config.cache file to see them. # ./configure prefix=/usr/local/mysql After you are done with configure, you can make the actual binaries by executing the follow- ing line (this will take a while): # make Now you are ready to install all the binaries. Run the following lines to install the binaries to the directory you specified with the configure prefix option. # make install Now it’s time to create the mysql tables, which are used to define the permissions. Make sure you replace new-password with something of your choice; otherwise, new-password will be your root password. # scripts/mysql_install_db # cd /usr/local/mysql/bin # ./safe_mysqld & # ./mysqladmin -u root password ‘new-password’ You can verify that MySQL is working by running some simple tests. The output should be similar to what is shown here: # /usr/local/mysql/bin/mysqlshow -p Installing PHP 4 and MySQL A PPENDIX A A INSTALLING PHP 4 AND MYSQL 785 38 7842 app a 3/6/01 3:40 PM Page 785 Enter password: + + | Databases | + + | mysql | + + When you install MySQL, it will automatically create two databases. One is the mysql table, which controls users, hosts, and DB permissions in the actual server. The other is a test DB. You can check your database via the command line like this: # mysql -u root -p Enter password: mysql> show databases; + + | Database | + + | mysql | | test | + + 2 rows in set (0.00 sec) Now it’s time to install PHP. You should still be acting as root, if not su back to root. PHP requires that you have Apache preconfigured so that it knows where everything is. You will come back to this later in the section when you set up the Apache server. Change back to the directory where you have the sources. # cd /tmp/download # gunzip -c apache_1.3.x.tar.gz | tar xf - # cd apache_1.3.x # ./configure prefix=/usr/local/apache # cd Okay, now you can start setting up PHP. Extract the source files and change to its directory: # gunzip -c php-4.0.x.tar.gz | tar xvf - # cd php-4.0.x Again there are many options with PHP’s configure command. Use configure help to determine what you want to add. In this case, we want to add support for MySQL, Apache, PDFLib, cURL, and PSPELL. Note that the following is all one command. We can put it all on one line, or as we have here, use the continuation character, backslash (\), to allow us to type one command across multiple lines to improve readability. Appendixes P ART VI 786 38 7842 app a 3/6/01 3:40 PM Page 786 # ./configure with-mysql=/usr/local/mysql \ with-xml with-apache= /apache_1.3.x \ with-curl=/usr/local/curl \ with-pspell=/usr/local/pspell \ enable-shared-pdflib enable-track-vars Next, make and install the binaries: # make # make install Copy the ini file to the lib directory: # cp php.ini-dist /usr/local/lib/php.ini You can edit the PHP file to set PHP options. You could, for example, increase the max_ execution_time in PHP by inserting the following line in your php.ini file. max_execution_time = 60; Apache and mod_SSL Time to configure and install mod_SSL and Apache. If you are in the United States, you will need the rsaref-2.0 files. Unfortunately, because this file is no longer distributed by RSA, it does not have a stable home page. You will need to use a search engine such as Lycos http://ftpsearch.lycos.com or Google http://www.google.com to search for the file rsaref20.tar.Z. Make sure you get the UNIX distribution. Create the rsaref directory where you will extract the files. Note that this assumes you have downloaded to the temp directory where you are. # mkdir rsaref-2.0 # cd rsaref-2.0 # gunzip -c /rsaref20.tar.Z | tar xvf - Now configure and build the OpenSSL Library. If inside the USA, you have to build OpenSSL in conjunction with the RSAref library. # cd rsaref-2.0 # cp -rp install/unix local # cd local # make # mv rsaref.a librsaref.a # cd / Installing PHP 4 and MySQL A PPENDIX A A INSTALLING PHP 4 AND MYSQL 787 38 7842 app a 3/6/01 3:40 PM Page 787 It’s time to set up OpenSSL. This is what you will use to create temporary certificates and CSR files. The prefix specifies the main installation directory. Appendixes P ART VI 788 Only include the -L`pwd`/ /rsaref-2.0/local/rsaref -fPIC’ line if you are in the USA. NOTE # gunzip c openssl-0.9.x.tar.gz | tar xvf - # cd openssl-0.9.x # ./config prefix=/usr/local/ssl \ -L`pwd`/ /rsaref-2.0/local/rsaref -fPIC Now make it, test it, and install it: # make # make test # make install # cd We will configure the mod_SSL module and then specify it to be a loadable module with the Apache configuration. # gunzip -c mod_ssl-2.6.x.tar.gz |tar xvf - # cd mod_ssl-2.5.x-1.3.x # ./configure with-apache= /apache_1.3.x # cd Note that we can add more Apache modules to the Apache source tree. The optional enable-shared=ssl option enables the building of mod_SSL as a DSO ‘libssl.so’. Read the INSTALL and htdocs/manual/dso.html documents in the Apache source tree for more informa- tion about DSO support in Apache. We strongly advise ISPs and package maintainers to use the DSO facility for maximum flexibility with mod_SSL. Notice, however, that Apache does not support DSO on all platforms. # cd apache_1.3.x # SSL_BASE= /openssl-0.9.x \ RSA_BASE= /rsaref-2.0/local \ ./configure \ enable-module=ssl \ activate-module=src/modules/php4/libphp4.a \ enable-module=php4 \ prefix=/usr/local/apache \ enable-shared=ssl [ you can add more options here ] 38 7842 app a 3/6/01 3:40 PM Page 788 (You could alternatively set SSL_BASE and RSA_BASE as environment variables if you prefer.) Finally you can make Apache and the certificates, and then install them. # make If you have done everything right, you will a message similar to the following: + + | Before you install the package you now should prepare the SSL | | certificate system by running the ‘make certificate’ command. | | For different situations the following variants are provided: | | | | % make certificate TYPE=dummy (dummy self-signed Snake Oil cert) | | % make certificate TYPE=test (test cert signed by Snake Oil CA) | | % make certificate TYPE=custom (custom cert signed by own CA) | | % make certificate TYPE=existing (existing cert) | | CRT=/path/to/your.crt [KEY=/path/to/your.key] | | Use TYPE=dummy when you’re a vendor package maintainer, | | the TYPE=test when you’re an admin but want to do tests only, | | the TYPE=custom when you’re an admin willing to run a real server | | and TYPE=existing when you’re an admin who upgrades a server. | | (The default is TYPE=test) | | | | Additionally add ALGO=RSA (default) or ALGO=DSA to select | | the signature algorithm used for the generated certificate. | | Use ‘make certificate VIEW=1’ to display the generated data. | | Thanks for using Apache & mod_ssl. Ralf S. Engelschall | | rse@engelschall.com - www.engelschall.com | + + Now you can create a custom certificate. This option will prompt you for location, company, and a couple of other things. # make certificate TYPE=custom Now install Apache: # make install If everything went well, the message that you should see is something similar to this: + + | You now have successfully built and installed the | | Apache 1.3 HTTP server. To verify that Apache actually | | works correctly you now should first check the | | (initially created or preserved) configuration files | | | | /usr/local/apache/conf/httpd.conf | | and then you should be able to immediately fire up | Installing PHP 4 and MySQL A PPENDIX A A INSTALLING PHP 4 AND MYSQL 789 38 7842 app a 3/6/01 3:40 PM Page 789 | Apache the first time by running: | | | | /usr/local/apache/bin/apachectl start | | Or when you want to run it with SSL enabled use: | | | | /usr/local/apache/bin/apachectl startssl | | Thanks for using Apache. The Apache Group | | http://www.apache.org/ | + + Now it’s time to see whether Apache and PHP are working. However, we need to edit the httpd.conf of srm.conf to add the PHP type to the configuration. Look at the httpd.conf and uncomment the following lines. If you have followed the previous instructions, your httpd.conf file will be located in the /usr/local/apache/conf directory. The file has the addtype for PHP 4 commented out. You should uncomment it at this time. httpd.conf File—Snippets > > # And for PHP 4.x, use: > # > AddType application/x-httpd-php .php > AddType application/x-httpd-php-source .phps > > Now we are ready to start the Apache server to see whether it worked. First, we will start the server without the SSL support to see whether it comes up. We will check for PHP support, and then we will stop the server and start it with the SSL support enabled and see whether we got everything working. The configtest will check whether the entire configuration is set up properly: # cd /usr/local/apache/bin # ./apachectl configtest Syntax OK # ./apachectl start ./apachectl start: httpd started If it worked correctly, you will see something similar to Figure A.1 when you connect to the server with a Web browser. Appendixes P ART VI 790 38 7842 app a 3/6/01 3:40 PM Page 790 FIGURE A.1 The default test page provided by Apache. Is PHP Support Working? Now we will test for PHP support. Create a file with the name of test.php with the following code in it. The file needs to be located in document root path, which should be set up by default to /usr/local/apache/htdocs. Note that this is dependent on the directory prefix that we chose initially. However, this could be changed in the httpd.conf. <? phpinfo() ?> The output screen should look like Figure A.2. Installing PHP 4 and MySQL A PPENDIX A A INSTALLING PHP 4 AND MYSQL 791 You can connect to the server with a domain name or using the actual IP address of the computer. Check both cases, to ensure that everything is working properly. Note 38 7842 app a 3/6/01 3:40 PM Page 791 FIGURE A.2 The function phpinfo() provides useful configuration information. Is SSL Working? Okay, now we are ready to test for SSL. First, stop the server, and restart with the SSL option enabled: # /usr/local/apache/bin/apachectl stop # /usr/local/apache/bin/apachectl startssl Test to see whether it works, by connecting to the server with a Web browser and selecting the https protocol, like this: https://yourserver.yourdomain.com or http://yoursever.yourdomain.com:443 Try your server’s IP address also, like this: https://xxx.xxx.xxx.xxx or http://xxx.xxx.xxx.xxx:443 If it worked, the server will send the certificate to the browser to establish a secure connection. This will make the browser prompt you for accepting the self-signed certificate. If it were a Appendixes P ART VI 792 38 7842 app a 3/6/01 3:40 PM Page 792 certificate from VeriSign or Thawte, the browser would not prompt you because their certifi- cates come from a trusted Certification Authority (CA). In our case, we created and signed our own certificates. We didn’t want to purchase one right away. We wanted to ensure that we could get everything working properly, first. If you are using Internet Explorer or Netscape, you will see a padlock symbol in the status bar. This tells you that a secure connection has been established. The icon used by Netscape is shown in Figure A.3. Installing PHP 4 and MySQL A PPENDIX A A INSTALLING PHP 4 AND MYSQL 793 FIGURE A.3 Web browsers display an icon to indicate the page you are viewing came via an SSL connection. Installing Apache, PHP, and MySQL Under Windows With Windows the installation process is a little bit different because PHP is set up either as a CGI (php.exe) script or as a ISAPI (php4isapi.dll) module. However, Apache and MySQL are installed in a similar fashion to the way they are installed under UNIX. Make sure you have the latest operating system service patches applied to the machine before you begin the Windows installation. You should start by downloading all the latest source files to a temporary directory with ample space. For our installation we will use C:\TEMP\DOWNLOAD as our temp directory. Installing MySQL Under Windows Let’s begin by setting up MySQL. Because you have already downloaded all sources, begin by unzipping the files to the temp directory and run the Setup.exe program. Note, that the default directory where MySQL will install itself will be the C:\mysql directory. You can move it to a different directory if needed, after it’s fully installed. If you do move MySQL, you must tell mysqld where everything is by supplying options to mysqld. Use C:\mysql\bin\mysqld help to display all options. For example, if you have moved the MySQL distribution to ‘D:\programs\mysql’, you must start mysqld with ‘D:\programs\mysql\bin\mysqld basedir D:\programs\mysql’. With the newest versions of MySQL, you can create a ‘C:\my.cnf’ file that holds any default option for the MySQL server. Copy the file ‘C:\mysql\my-xxxxx.cnf’ to ‘C:\my.cnf’ and edit it to suit your custom setup. 38 7842 app a 3/6/01 3:40 PM Page 793 Windows 95/98 The Windows 95/98 version of MySQL comes with two different MySQL servers: • mysqld: Compiled with full debugging and automatic memory allocation with checking • mysqld-opt: Optimized for a Pentium processor Both will work on any current Intel X386 or later processors. You can start the mysqld server from a Windows prompt by typing the following: C:\mysql\bin\mysqld-opt This starts the MySQL server in the background. If the server doesn’t start, check whether or not the ‘\mysql\mysql.err’ file contains any errors indicating what could be wrong. You can shut down the MySQL server by executing C:\mysql\bin\mysqladmin -u root shutdown Windows NT/Win2000 There are some minor differences depending on whether you run MySQL on NT or Windows 2000. In the NT/Win2000 setup, the name of the server is mysqld-nt, and it will normally be installed as a service. You can install the server as a service like this: C:\mysql\bin\mysqld-nt -install Now you can start and stop the MySQL server as a service with NET START mysql NET STOP mysql Appendixes P ART VI 794 Use mysql and not mysql-nt here. Note After the server is installed, it must be started using Services Control Manager (SCM) utility (found in Control Panel) or by using the NET START MySQL command. The SCM is shown in Figure A.4. If any options are desired, they must be specified as startup parameters in the SCM utility before you start the MySQL service. When it is running, mysqld-nt can be stopped using mysqladmin, or from the SCM utility, or by using the command NET STOP MySQL . 38 7842 app a 3/6/01 3:40 PM Page 794 . it at this time. httpd.conf File—Snippets > > # And for PHP 4.x, use: > # > AddType application/x-httpd -php .php > AddType application/x-httpd -php- source .phps > > Now we. app a 3/6/01 3:40 PM Page 786 # ./configure with -mysql= /usr/local /mysql with-xml with-apache= /apache_1.3.x with-curl=/usr/local/curl with-pspell=/usr/local/pspell enable-shared-pdflib. 7842 app a 3/6/01 3:40 PM Page 790 FIGURE A.1 The default test page provided by Apache. Is PHP Support Working? Now we will test for PHP support. Create a file with the name of test .php with

Ngày đăng: 06/07/2014, 19:20

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

  • Đang cập nhật ...

TÀI LIỆU LIÊN QUAN