Configure Apache + PHP + MySql in Mac OS X)

Source: Internet
Author: User
Tags apache php mcrypt php mysql zts

Introduction: This is a detailed page for configuring Apache + PHP + MySql in Mac OS X. It introduces the related knowledge, skills, experience, and some PHP source code.

Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 344026 'rolling = 'no'>

Mac OS X has built-in Apache and PHP, which is very convenient to use. This article takes Mac OS X 10.6.3 as an example. The main content includes:

Start Apache
Run php
Install MySQL
Use phpMyAdmin
Configure the mcrypt extension library of PHP
Set VM
Start Apache
There are two methods:

Choose System Preferences> sharing> Web Sharing )"
Open "terminal" and (Note: The password required by sudo is the root account password of the system)
Run"sudo apachectl start", And then enter the account password to run Apache.
Run"sudo apachectl -v", You will see the apache version number in Mac OS X 10.6.3:
Server version: Apache/2.2.14 (Unix)Server built: Feb 11 2010 14:40:31
In this way, enter "http: // localhost" in the browser, and you can see that the content is "It works !" Is located under "/Library (resource library)/webserver/documents/", which is the default root directory of Apache.



NOTE: If Apache is enabled, "Web Sharing" is enabled, and connected users access "/Library (resource library)" through "http: // [local IP address) /webserver/documents/"directory, through" http: // [local IP address]/~ [User name] to access the "/users/[user name]/sites/" directory. You can set "firewall" in "security" of "system preference settings) to prohibit such access.

Run php
Run"sudo vi /etc/apache2/httpd.confOpen the Apache configuration file. (If you are not familiar with operating terminal and VI, you can set to display all system hidden files in the finder. Remember to restart the finder so that you can find the corresponding file and edit it as you like, note that you need to enable the root account to modify some files, but it is safer to use sudo on the terminal to temporarily obtain the root permission .)
Find"#LoadModule php5_module libexec/apache2/libphp5.so", Remove the # sign and save it (enter it in the command line):w) And exit VI (enter in the command line:q).
Run"sudo cp /etc/php.ini.default /etc/php.ini", You can use PHP. ini to configure various PHP functions. For example:
The following two items are used to adjust the maximum value of the submitted PHP file. For example, the maximum value of data imported in phpMyAdmin is upload_max_filesize = 2mpost_max_size = 8 m; for example, display_errors is used to control whether to display the error display_errors = off of the PHP program.
Run"sudo apachectl restart", Restart Apache, so that PHP can be used.
Run"cp /Library/WebServer/Documents/index.html.en /Library/WebServer/Documents/info.phpCopy the index.html. En file in the apacheroot directory and rename it info. php.
Run"vi /Library/WebServer/Document/info.phpIn this way, you can edit the info. php file in VI. In "It's works !" Add"<?php phpinfo(); ?>And save it. In this way, you can see information about PhP in http: // localhost/info. php, for example, the version number is 5.3.1.

Install MySQL
Because MySQL is not pre-installed in Mac OS X, you need to manually install it. Currently, the most stable mysql version is 5.1. MySQL provides installation instructions for Mac OS X.

Download MySQL 5.1. Select the appropriate version, for example, the mysql-5.1.46-osx10.6-x86_64.dmg here.
Run DMG and you will find four files in it. First click Install mysql-5.1.46-osx10.6-x86_64.pkg, This is the MySQL main installation package. Generally, the installation file automatically installs MySQL to a folder with the same name under/usr/local. For example, clicking run mysql-5.1.46-osx10.6-x86_64.dmg will install mysq to/usr/local/mysql-5.1.46-osx10.6-x86_64. The installation is complete by default.
Click to install the 2nd file mysqlstartupitem. PKG, so that MySQL will automatically start at startup.
Click to install MySQL 3rd files. prefpane. In this way, the icon "MySQL" is displayed in "system setting Preferences", through which you can set whether MySQL starts or stops and whether it runs automatically at startup. MySQL is basically installed.
Runsudo vi /etc/bashrc", Add it to the bash configuration filemysqlAndmysqladminAlias

#mysql
alias mysql='/usr/local/mysql/bin/mysql'
alias mysqladmin='/usr/local/mysql/bin/mysqladmin'
In this way, you can simply perform operations through commands on the terminal, suchrootThe default password is blank. To set a password, run"mysqladmin -u root password "mysqlpassword"Mysqlpassword is the root password. For more information, see B .5.4.1. how to reset the root password.

Note: The upgrade of Mac OS X or other causes may cause MySQL to start or automatically run upon startup. The prompt"Warning:The /usr/local/mysql/data directory is not owned by the 'mysql' or '_mysql' ", Or prompt"Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)", This should be caused by a change in the/usr/local/MySQL/Data host, just run" sudo chown -R mysql /usr/local/mysql/data.

In addition, if you use PHP to connect to MySQL, the error "can't connect to local MySQL server through socket"/var/MySQL may be reported. sock ', or use localhost to connect to MySQL and 127.0.0.1 is required because/var/MySQL is used by default in PHP connection. sock, but MySQL of Mac version changes the file location, put it under/tmp. The solution is to modify PHP. ini as follows:


mysql.default_socket = /tmp/mysql.sock
Use phpMyAdmin
PhpMyAdmin is a MySQL management program developed with PHP. It is very popular and practical. Using phpMyAdmin to manage MySQL is a very effective way to verify the results of the previous steps.

Download phpMyAdmin. Select the desired version, for example, phpmyadmin-3.3.2-all-languages.tar.bz2.
Copy the phpMyAdmin-3.32-all-languages folder in downloads to/Users/[user name]/SiteIn "S", the name is changed to phpMyAdmin.]
Copy"/Users/[user name]/sites/PHPmyAdmin/"Config. sample. Inc. php, and name it config. Inc. php.
Open config. Inc. php and make the following changes:
For cookie encryption, the arbitrary long string $ cfg ['blowfish _ secret'] = ''; when" #2002 cannot log on to MySQL Server "appears in phpMyAdmin, change localhost to 127.0.0.1. This is because the MySQL daemon has bound IP addresses (bind-address = 127.0.0.1) $ cfg ['servers'] [$ I] ['host'] = 'localhost'; change false to true, so that you can access MySQL without a password, even if the MySQL password is set, you can set it like this, and then enter the password $ cfg ['servers'] [$ I] ['allownopassword'] = false when logging on to phpMyAdmin;
In this way, you can useHttp: // localhost /~ [User name]/phpMyAdminAccess phpMyAdmin. At this time, you will see a prompt saying "The mcrypt extension cannot be loaded. Please check your PHP configuration .", This involves installing the mcrypt extension in the next section.
Configure the mcrypt extension of PHP
Mcrypt is a powerful extension library for encryption algorithms. It includes 22 algorithms. phpMyAdmin depends on this PHP extension library. However, it is not so friendly to install on Mac OS X, as follows:

Download and decompress libmcrypt-2.5.8.tar.bz2.
Run the following command on the terminal (note that xcode is required for the following command ):
cd ~/Downloads/libmcrypt-2.5.8/./configure --disable-posix-threads --enable-staticmakesudo make install
cd ~/Downloads/libmcrypt-2.5.8/
./configure --disable-posix-threads --enable-static
make
sudo make install

Download and decompress the PHP source code file php-5.3.1.tar.bz2. In Mac OS X 10.6.3, the pre-installed PHP version is 5.3.1, and the latest PHP version is 5.3.2. You need to select the corresponding version based on your actual situation.
Run the following command on the terminal:
cd ~/Downloads/php-5.3.1/ext/mcrypt
phpize
./configure
make
cd modules
sudo cp mcrypt.so /usr/lib/php/extensions/no-debug-non-zts-20090626/
Open PHP. ini



sudo vi /etc/php.ini

Add the following code to PhP. ini, save the code, exit, and restart Apache.
extension=/usr/lib/php/extensions/no-debug-non-zts-20090626/mcrypt.so
extension=/usr/lib/php/extensions/no-debug-non-zts-20090626/mcrypt.so

When you accessHttp: // localhost /~ [User name]/phpMyAdminYou will find that "the mcrypt extension cannot be loaded. Please check your PHP configuration ." The prompt "no" indicates that the mcrypt extension library has been successfully installed.

Set VM
Run"sudo vi /etc/apache2/httpd.confOpen the Apche configuration file.
In httpd. conf, find"#Include /private/etc/apache2/extra/httpd-vhosts.conf", Remove the previous" # ", save and exit.
Run "sudo apachectl restart" and restart Apache to enable its VM configuration function.
Run sudo VI/etc/apache2/extra/httpd-vhosts.conf to open the file httpd-vhost.conf for configuring the VM and configure the VM you need. Note that two virtual hosts are enabled for this file by default:
<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "/usr/docs/dummy-host.example.com"
    ServerName dummy-host.example.com
    ErrorLog "/private/var/log/apache2/dummy-host.example.com-error_log"
    CustomLog "/private/var/log/apache2/dummy-host.example.com-access_log" common
</VirtualHost>
<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host2.example.com
    DocumentRoot "/usr/docs/dummy-host2.example.com"
    ServerName dummy-host2.example.com
    ErrorLog "/private/var/log/apache2/dummy-host2.example.com-error_log"
    CustomLog "/private/var/log/apache2/dummy-host2.example.com-access_log" common
</VirtualHost> 
In fact, these two virtual hosts do not exist. when no other virtual hosts are configured, the following prompt may appear when accessing localhost:

ForbiddenYou don't have permission to access /index.php on this server
The simplest way is to add # in front of each line and comment it out, so that it can be referenced without causing other problems.

Add the following configuration
<VirtualHost *:80>
    DocumentRoot "/Users/[用户名]/Sites"
    ServerName sites
    ErrorLog "/private/var/log/apache2/sites-error_log"
    CustomLog "/private/var/log/apache2/sites-access_log" common
</VirtualHost> 
Save and exit, and restart Apache.

Run"sudo vi /etc/hosts", Open the hosts configuration file, and add"127.0.0.1 sites", So that you can configure the sites virtual host, so that you can access it with" http: // sites ", its content and" http: // localhost /~ [User name] "is completely consistent.
This is a configuration that is supported by Mac OS x 10.6.3. For more information, see "Mac OS X Leopard: Configure Apache, PHP, SQLite, MySQL, and phpMyAdmin (1) "and" Mac OS X Leopard: Configure Apache, PHP, SQLite, MySQL, and phpMyAdmin (2 )". In fact, you can also use an integrated solution provided by a third party such as XAMPP or macports for simple installation and use.



Author: Qin Ge, time:, summarized in: Apache & MySQL & PHP, apple, subscription: RSS 2.0, reference: trackback

«Advanced guide to high-performance website construction

Enable Mod Rewrite and. htaccess»

There are 56 comments and a new comment»Aoao said:#1
Use the mamp's lazy to pass ~

The lesser said:#2
All of them use Mac,
Hey, we are still using Ubuntu

Fwolf said:#3
Very useful. Thank you!
When installing mcrypt, if the PHP version is updated,
Libmcrypt seems to have to be re-compiled and then make install,
Of course, PHP must be compiled again.

Will said:2010-06-03 23:42 #4
The article is good and detailed, but for many users without MacOS, VI is still unfamiliar. We recommend that you use VI in more details. For example, VI storage and other small places.

In Mac OS X, configure Apache + PHP + MySQL-implicit peaks:2010-06-04 #5
[...] Source [...]

Merge and compress JavaScript and CSS files on the server:2010-06-10 19: 48 #6
[...] Install Apache + PhP (Windows and Mac ). [...]

Youguang said:#7
Can XAMPP be used in Mac OS X?

Qin Ge said:#8
@ Youguang: Yes. For details, refer to the XAMPP link at the end of this article.

[ZT] merge and compress JavaScript and CSS files on the server. «interui:#9
[...] Install Apache + PhP (Windows and Mac ). [...]

Hiro said:#10
I bought the book and learned...

Merge and compress JavaScript and CSS files on the server:#11
[...] Install Apache + PhP (Windows and Mac ). [...]

The team said:#12
There are still some non-mainstream products such as Apple servers. Is it true that money is burning?

For beginners, say:#13
Learned

Xiao said:#14
Run "sudo VI/etc/bashrc" and add the alias of MySQL and mysqladmin to the bash configuration file.
# MySQL
Alias MySQL = '/usr/local/MySQL/bin/mysql'
Alias mysqladmin = '/usr/local/MySQL/bin/mysqladmin'
After this statement is run, I will tell you that the file is readonly and cannot be saved after modification. Do I need to modify the File Permission?

Configure Apache + PHP + MySql in Mac OS X:#15
[...] Start Apache [...]

Qin Ge said:#16
@ Xiao: Is it because you have not added sudo? If you have added sudo, you do not need to modify the File Permission.

Install Apache PHP MySQL phpMyAdmin on Mac:#17
[...] For details, refer to this article to configure Apache + PHP + MySql in Mac OS X. The problem is as follows: [...]

Neville said:#18
Is it necessary to install make first?
Bogon: mcrypt-2.6.8 Neville $./configure-Disable-POSIX-threads-enable-static
Checking build system type... I386-apple-darwin10.4.0
Checking host system type... I386-apple-darwin10.4.0
Checking target system type... I386-apple-darwin10.4.0
Checking for a BSD-compatible install... /Usr/bin/install-C
Checking whether build environment is sane... Yes
Checking for a thread-safe mkdir-P... ./Install-sh-c-d
Checking for gawk... No
Checking for mawk... No
Checking for nawk... No
Checking for awk... Awk
Checking whether make sets $ (make )... No
Checking for style of include used by make... None
Checking for GCC... No
Checking for CC... No
Checking for cl.exe... No
Configure: Error: no acceptable C compiler found in $ path
See 'config. log' for more details.
Bogon: mcrypt-2.6.8 Neville $ make
-Bash: Make: Command not found

Configure Apache + PHP + MySQL-development in Mac OS X:#19
[...] Referenced from: http://dancewithnet.com/2010/05/09/run-apache-php-mysql-in-mac-os-x/ [...]

Charles said:#20
Thanks for the author's article. I wrote it in quite detail. At the same time, I was amazed at Mac's thoughtfulness. I had installed so many software I needed, even Apache, PHP, subversion, and Java, if you are using Windows, you have to wait for half a day before installing it ~~~

Yake said:#21
After reading your tutorial, I wrote it very carefully. I can basically understand it in front-end development. However, if you have any questions, I would like to ask, the PHP version of OS X 10.6 is 5.3.2, however, our current project has an extension that only supports PHP 5.2.8. Is there a way to downgrade the PHP that comes with OS X?

I hope to give you some tips. Thank you very much ~

Configure Apache + PHP + MySql in Mac OS X:#22
[...] Start Apache [...]

[Website creation] configure Apache + PHP + MySql in Mac OS X:#23
[...] Configure the PHP mcrypt extension Library [...]

Stoneros:#24
Written in full detail: D thanks

Merge and compress JavaScript and CSS files on the server | Wang Jun's blog says:#25
[...] Install Apache + PhP (Windows and Mac ). [...]

Simon said:#26
�� "Configure the mcrypt extension for PHP 』
Do you want to install xcode first?
Because I make all messages

Qin Ge said:#27
@ SIMON: Yes. xcode needs to be installed. xcode provides many basic development tools on Mac.

Evan said:#28
I have an error at the end of the compilation process. I don't know where the problem is? I wonder if you have encountered any similar situation.

make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.

Zhu Qi said:#29
That's good. good article.

Heiniu Haha said:#30
I have provided a very detailed tutorial on how to configure the development environment on Mac.

Configure Apache + PHP + MySql in Mac OS X | Note by Web Front-end development engineers-heiniu Haha said:#31
[...] Run php [...]

Kevin said:#32
A very good article, super detailed, abandoned XAMPP, or awesome command ....

Anonymous:#33
Run "VI/library/webserver/document/info. php" on the terminal to edit the info. php file in VI. In "It's works !" Add "" and save it. In this way, you can see information about PhP in http: // localhost/info. php, for example, the version number is 5.3.1.

I am a newbie, but I cannot do this. After "" is added, "" is displayed. Add the error? "" Is displayed after I refresh the page. No version information.

Tutorial

Merge and compress JavaScript and CSS files on the server:#34
[...] Install Apache + PhP (Windows and Mac ). [...]

Mrgaolei said:#35
Why not use PECL to install mcrypt? In addition, there are many problems with the xamp mentioned above, and you cannot compile the extension by yourself.

Tsdeng said:#36
I am very grateful for this article, saving a lot of time.

Anonymous:#37
"# Loadmodule php5_module libexec/apache2/libphp5.so" cannot be found. What should I do?

Qin Ge said:#38
@ #33 floor. Sorry, there is content before the quotation marks.<?php phpinfo(); ?>Because of our transfer, they are filtered out, and I am sorry for this problem.
@ # Which version of Apache are you using on the 37 th floor? I use this version 2.2.14/etc/apache2/httpd.confBy default, this sentence exists. You can search for the keyword to see if it should exist. It should be okay if your version is not added.

Leebin says:#39
I am humbly asking: Can I ask this question?
The problem is as follows:
1. I want to learn how to build a website. What hardware and software knowledge do I need and what hardware equipment do I need?
2. What do I need to apply for when I learn to build a small website )?
3. I have a C language foundation. Does it help me build a website )?
4. If you want to learn how to build a website, can you provide some reference books? What is the general direction for the monks?
(I am a student)
If you can, please take a moment to answer your questions.
No ~

Icy says:#40
LZ. What is the password entered when Apache is started? --

Icy says:#41
Dear LZ, what is the password used when Apache is started ~~ =, =

Leebin says:#42
I still hope the experts can give some advice and point out a direction for the lost passers-.

C:#43
After several hours, I finally got the configuration ready.

Hihww said:#44
Make does not have this command. How can this problem be solved?

Qin Ge said:#45
@ Icy: Sorry, because there are too many spams to reply, it's the root password. I think you have done it.

Qin Ge said:#46
@ Leebin:
1, quickly build a website, you can use some open source programs, first study how others are engaged in, so that you can grow rapidly, such as http://wordpress.org is very good.
2. If you do not need to play anything on the local machine, if you want to make it public, you need to apply for a domain name and space. Before that, of course you can directly go to the domestic blog site or http://wordpress.com to get a first play is also good.
3. Simple small websites rarely use C
4. The best way to be proficient in website building is to build a website with open source. After you build your website, you will understand what you lack and go to school. It is difficult to read a book to master website construction. It is not difficult to build a website. What is difficult is how to build a website that meets specific requirements.
Best of all, I would like to say that there is a lot of similar knowledge on the Internet. We must be able to find out the knowledge we need from the vast amount of information. This is the capability that students who want to engage in information technology must possess, brave practices are the best way for us to grow fast.

Qifei says:#47
Hello, please have a question.
I encountered a problem when installing the mcrypt extension.
According to your instructions, I enter./configure-Disable-POSIX-threads-enable-static in the terminal, and after I press enter, many lines are displayed, with no at the end.
After entering make and press enter, the system prompts that this command is unavailable.

My system is 10.5.8. How can I solve this problem? Thank you.

Qifei says:#48
Hello, try again.
I found some articles on the Internet, because I have not installed xcode, so there is no make command. I found that the system disk installed xcode 3.0 compiled mcrypt. So according to your method, but phpMyAdmin still says there is no mcrypt extension. Another problem is that you cannot connect to the database using localhost. You must use 127.0.0.1.

Kaelzhang said:#49
These three items are available for configuration on Windows, for configuration Reinstallation, and for Mac, so now XAMPP is very lazy, one-click + configure the local test site and domain name in conf and hosts.

XAMPP is used on Mac. Web Sharing and Apache are two conf files in different locations. One is in the installation path and the other is in USR.

I personally prefer to directly configure the conf file in the XAMPP installation path and configure custom domain names for different directories.

Qin Ge said:#50
@ Qifei: I have read your blog. The difference between Mac OS X 10.5 and 10.6 is large. Maybe there is a compatibility problem. Can you upgrade it to 10.6.

Kevin Lee said:#51
Run "sudo VI/etc/apache2/httpd. conf" on the terminal. <I entered, but he asked me to enter password ?? What is passoword ??

Qin Ge said:#52
@ KEVIN: Actually, I replied on the #45 th Floor, that is, the system's root account password.

Eric said:#53
How can I save and exit after I modify "# loadmodule php5_module libexec/apache2/libphp5.so?

Qin Ge said:#54
@ ERIC: Save (enter W in the command line) and exit VI (enter Q in the command line). I have also written it to the original text, which is a VI command.

Eric said:#55
Thank you very much. I have followed the steps for running PHP. But after entering http: // localhost/info. php, the PHP information is not displayed. What is the error?

Joanna said:#56
Appears
Forbidden
You don't have permission to access/index. php on this server
Comment out the following two lines:

Options followsymlinks
AllowOverride none
# Order deny, allow
# Deny from all

Love J2EE follow Java Michael Jackson video station JSON online tools

Http://biancheng.dnbcw.info/php/344026.html pageno: 5.


Related Article

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.