[HOWTO] - Setup PHP & MySQL

Status
Not open for further replies.

yoshi

Registered
Okay before we start I would like to mention that if you screw on any of these commands php will not work. If you wish to get to the document root of apache and use it as real webserver on the net the root of it is located at /library/webserver/documents and the CGI-BIN is located at library/webserver/cgi-executables. I do hope that this HowTo on PHP and MySQL helps you guys learn the terminal and its commands a bit better if you are new to MacOS X. As always please ask any questions you may have. My sources for info will be at the bottom of this HowTo.

PHP PART OF THE HOWTO:
Step 1) Start the Terminal Application.

Step 2) Type "curl -O http://www2.entropy.ch/download/libphp4.so.gz", wait for download to finish

Step 3) Type "gunzip libphp4.so.gz"

Step 4) Type "sudo mv libphp4.so /usr/libexec/httpd/"

Step 5) Type "cd /etc/httpd"

Step 6) Type "sudo apxs -e -a -n php4 libexec/httpd/libphp4.so"

Step 7) Type "sudo perl -p -i.bak -e 's%#(AddType \S+-php[ -])%$1%i' httpd.conf"

Step 8) Type "sudo apachectl graceful" to restart the web server

MYSQL PART OF THE HOWTO:

Step 1) Download and install the package http://www.machowto.com/mysql-3.32.47.pkg.tar

Step 2) Create a new user in the "Users" System Prefs pane:
1. Name: "MySQL User"
2. Short Name: "mysql"
3. Password: whatever you want

Step 3) Open a terminal window and type in the following commands (without the double quotes):

Step 4) type "cd /usr/local/mysql"

Step 5) type "sudo ./scripts/mysql_install_db", enter administrator password when asked

Step 6) type "sudo chown -R mysql /usr/local/mysql/*"

Step 7) type "sudo ./bin/safe_mysqld --user=mysql &"

Step 8) Use it with "mysql test"


Now you should have a perfect web hosting machine that runs PHP and has MySQL on it. It should also run any industry stand scripts such as a forum or a website. Credits are below.

I would like to credit http://www.entropy.ch for most of the infomation used and thanks to jadey for the links.

`Dave
 
I've been down this road before, never could get MySQL to actually start.

Thanks Yoshi for the how-to, I'l be trying it later on today.

I think its critical that we get MySQL and PHP working for every mac os x user who wants it, and I'm glad you wrote a how-to.

I hope Swizcore gets this moved to the Archive, because its quite good!
 
Or you could just uncomment the php lines in the httpd.conf, add index.php to the line with index.htm index.html, and PHP will work.
 
actually no you couldn't, the php module isn't in apache by default... it wouldn't work right if at all.. trust me I tried..


`Yoshi
 
Actually that is how it works. Know how i know? I actaully did it. After a 10.1 Clean install, I opened up httpd.conf uncommentedthe following lines, restarted Apache and BOOM. PHPworked.

Code:
LoadModule php4_module        libexec/httpd/libphp4.so

AddModule mod_php4.c

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

Then added .php to the following line

Code:
DirectoryIndex index.html

Then restart Apache and boom PHP will work.

Make sure you have a 10.1 Clean install.
 
Originally posted by Mac Write
Actually that is how it works. Know how i know? I actaully did it. After a 10.1 Clean install, I opened up httpd.conf uncommentedthe following lines, restarted Apache and BOOM. PHPworked.

Code:
LoadModule php4_module        libexec/httpd/libphp4.so

AddModule mod_php4.c

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

Then added .php to the following line

Code:
DirectoryIndex index.html

Then restart Apache and boom PHP will work.

Make sure you have a 10.1 Clean install.

The built in Apple php module isn't really compiled well which is why I ut the extra 30 seconds of work in the above HowTo: I reccomend it for optimal performance. You are indeed right it will work this way, but it works better with the newer module in apache and honestly I feel its safer.

`Yoshi
 
Thank you for the instruction. The PHP install worked out great. However, I'm having trouble with install of MySQL. I've always been a Mac user, but I'm a newbie at Unix. After I did the instructions to install MySQL and restarting, I typed the "mysql test" in the terminal and go this reply.
ERROR 2002: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
Any suggestions? Could you recommend a good book for using mysql for newcomers to Unix?
thanx
 
<snip>ERROR 2002: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) </snip>

k. I'm really trying to use my brain too - but my hair is falling out... can you provide some insight on how you solved this problem? I'd love to know - really :-D

Thanks in advance -
LisaMac
 
okay that means mysqld isn't running :). This tells me one of two things, one you didn't do the install right and the dameon isn't running right or at all or two you didn't do the below step and mysql isn't running :).

try this:
Step 1) CD to the mysql install directory
Step 2) type "sudo ./bin/safe_mysqld --user=mysql &"

that should start mysql and allow you to do the test :)

Hope this helps

`Yoshi
 
[localhost:/usr/local/mysql] lisamac% sudo ./bin/safe_mysqld --user=mysql &
[1] 428
[localhost:/usr/local/mysql] lisamac% Password:******
******: Command not found.
[localhost:/usr/local/mysql] lisamac%

is what i get when I try to run the above command (password is not all stars , but i tend to reuse my passwords for things like discussion forums, so i put them in instead of my password)- when i type in my password i get the command not found error...... i suck, i know... please help!

btw, thanks for getting back to me so fast :-D You're a lifesaver!

Cheers,
LisaMac
 
I downloaded the nice installation app from Marc Liyanage and installed as requested. did the steps maticulously ( i think ). I know that i've installed wrong though, cause I knew enough to try to start it. I think I understand the process... i got the error message "sorry the host 'blah blah' could not be looked up. Please configure the host command... etc etc." so i realized that my network guys had applied a hostname to me when i plugged in. Thinking i'm going to be working offline most of the time anyway i unplugged the network connection and restarted... this took me out to [localhost] so i tried to run mySQL again... now i'm getting the socket error.

I'm sure this makes no sense... i still suck... thanks for those who might try to decipher this though...

should i uninstall mysql and try again? if so, which files do i get rid of? or is there a simple way to actually re-configure the host command?

Thanks again m8's,
cheers,
LisaMac
 
[localhost:/usr/local/mysql] lisamac% sudo ./bin/safe_mysqld --user=mysql &
[1] 428
[localhost:/usr/local/mysql] lisamac% Password:******
******: Command not found.
[localhost:/usr/local/mysql] lisamac%


Okay thats something with the sudo command, it might give you that error if you enter you password wrong, at this point I would try redoing all the steps from #1 and see if it duplicates the error, get back with me :)

`Yoshi
 
Seems I just needed to sleep on it... thanks so much for your help yoshi - I ran the process from the beginning, just like you said and it worked!

I now have mySql and PHP running! :-D I'm so happy!

Thanks,
LisaMac
 
Man this is frustrating. I did something wrong when installing MySQL. I think I screwed up or skipped resetting the root password. Now I can not create databases. I can play with the "test" database all I want, but that ain't gonna cut it.
This is what it says to do to reset the password:
Code:
./bin/mysqladmin -u root -p password 'new_password'
./bin/mysqladmin -u root -h localhost -p password 'new_password'

But that does nothing. I have re-installed multiple times and still no luck. I am familiar with using PHP and mySQL, but have never done ANYTHING with Unix before, so I am pretty lost.

Side note: It still has 'mysql user deleted' folders in my Users' folder from the users I deleted in my attempt to figure out this mess. It wont let me get rid of them. Any help on this would be greatly appreciated.

If someone, anyone can help me get all this figured out I will be your bestest friend for ever and ever.

Thanks,
Digi
 
hey j00, if resetting your mysql password failed then you have no password for root is should be blank.. if you want to reset your password try this from the terminal its what I used to set my password:

/usr/local/mysql/bin/mysqladmin password new-password

type the directory exactly as I did only change new-password to the password you want!

This should work if you followed the directions above!

~Yoshi
 
ok the php install isnt working. Someone please help me. I am about to copy and past everything it says.
Welcome to Darwin!
[localhost:~] nate% curl -O http://www2.entropy.ch/download/libphp4.so.gz
% Total % Received % Xferd Average Speed Time Curr.
Dload Upload Total Current Left Speed
100 4723k 100 4723k 0 0 20165 0 0:03:59 0:03:59 0:00:00 14145
[localhost:~] nate% gunzip libphp4.so.gz
[localhost:~] nate% sudo mv libphp4.so /usr/libexec/httpd/
Password:
[localhost:~] nate% cd /etc/httpd
[localhost:/etc/httpd] nate% sudo apxs -e -a -n php4 libexec/httpd/libphp4.so
[activating module `php4' in /private/etc/httpd/httpd.conf]
cp /private/etc/httpd/httpd.conf /private/etc/httpd/httpd.conf.bak
cp /private/etc/httpd/httpd.conf.new /private/etc/httpd/httpd.conf
rm /private/etc/httpd/httpd.conf.new
[localhost:/etc/httpd] nate% sudo perl -p -i.bak -e 's%#(AddType \S+-php[ -])%$
Unmatched '.
[localhost:/etc/httpd] nate% sudo perl -p -i.bak -e 's%#(AddType \S+-php[ -])%$1%i' httpd.conf
[localhost:/etc/httpd] nate% sudo apachectl graceful
/usr/sbin/apachectl graceful: httpd not running, trying to start
Syntax error on line 240 of /etc/httpd/httpd.conf:
Cannot load /usr/libexec/httpd/libphp.so into server: (reason unknown)
/usr/sbin/apachectl graceful: httpd could not be started
[localhost:/etc/httpd] nate%


See I did everything right. and also my mysql install aint work either...here is what I got.


Welcome to Darwin!
[localhost:~] nate% cd /usr/local/mysql
/usr/local/mysql: No such file or directory.
[localhost:~] nate% cd /usr/local/mysql
/usr/local/mysql: No such file or directory.
[localhost:~] nate% cd /usr/local/mysql
/usr/local/mysql: No such file or directory.
[localhost:~] nate% cd /usr/local/MySQL
/usr/local/MySQL: No such file or directory.
[localhost:~] nate% cd /usr/local/mysql
/usr/local/mysql: No such file or directory.
[localhost:~] nate%


Whats up? This is starting to get on my nerves. Please help.
 
See I did everything right. and also my mysql install aint work either...here is what I got.


Welcome to Darwin!
[localhost:~] nate% cd /usr/local/mysql
/usr/local/mysql: No such file or directory.
[localhost:~] nate% cd /usr/local/mysql
/usr/local/mysql: No such file or directory.
[localhost:~] nate% cd /usr/local/mysql
/usr/local/mysql: No such file or directory.
[localhost:~] nate% cd /usr/local/MySQL
/usr/local/MySQL: No such file or directory.
[localhost:~] nate% cd /usr/local/mysql
/usr/local/mysql: No such file or directory.
[localhost:~] nate%

Are you sure you did that MySQL Install right? because I don't see the transcript there and you can't just /usr/local/mysql and hope its there, you have to download and follow the directions.

Now as for your PHP problem you DID NOT follow my directions and here is what you did wrong, you did this:
cp /private/etc/httpd/httpd.conf /private/etc/httpd/httpd.conf.bak
cp /private/etc/httpd/httpd.conf.new /private/etc/httpd/httpd.conf
rm /private/etc/httpd/httpd.conf.new

That screwed up your apache config and I did not specify any commands like those. All you needed to do to add the php config lines to the httpd.conf was this:
[localhost:/etc/httpd] nate% sudo perl -p -i.bak -e 's%#(AddType \S+-php[ -])%$1%i' httpd.conf

Now I have no clue what httpd.conf has in it since you replaced it but look at line 240 for your problem.


Sincerely
~Yoshi
 
Status
Not open for further replies.
Back
Top